Lines Matching refs:ms
118 private int getvalue(struct magic_set *ms, struct magic *, const char **, int);
181 struct magic_set *ms; in main() local
194 if ((ms = magic_open(MAGIC_CHECK)) == NULL) { in main()
198 ret = magic_compile(ms, argv[1]) == -1 ? 1 : 0; in main()
200 (void)fprintf(stderr, "%s: %s\n", progname, magic_error(ms)); in main()
201 magic_close(ms); in main()
430 apprentice_1(struct magic_set *ms, const char *fn, int action) in apprentice_1() argument
439 file_error(ms, 0, "magic element size %lu != %lu", in apprentice_1()
446 map = apprentice_load(ms, fn, action); in apprentice_1()
449 return apprentice_compile(ms, map, fn); in apprentice_1()
453 map = apprentice_map(ms, fn); in apprentice_1()
457 if (ms->flags & MAGIC_CHECK) in apprentice_1()
458 file_magwarn(ms, "using regular magic file `%s'", fn); in apprentice_1()
459 map = apprentice_load(ms, fn, action); in apprentice_1()
465 if (add_mlist(ms->mlist[i], map, i) == -1) { in apprentice_1()
466 file_oomem(ms, sizeof(*ml)); in apprentice_1()
475 apprentice_list(ms->mlist[i], BINTEST); in apprentice_1()
477 apprentice_list(ms->mlist[i], TEXTTEST); in apprentice_1()
487 file_ms_free(struct magic_set *ms) in file_ms_free() argument
490 if (ms == NULL) in file_ms_free()
493 mlist_free(ms->mlist[i]); in file_ms_free()
494 free(ms->o.pbuf); in file_ms_free()
495 free(ms->o.buf); in file_ms_free()
496 free(ms->c.li); in file_ms_free()
497 free(ms); in file_ms_free()
503 struct magic_set *ms; in file_ms_alloc() local
506 if ((ms = CAST(struct magic_set *, calloc((size_t)1, in file_ms_alloc()
510 if (magic_setflags(ms, flags) == -1) { in file_ms_alloc()
515 ms->o.buf = ms->o.pbuf = NULL; in file_ms_alloc()
516 len = (ms->c.len = 10) * sizeof(*ms->c.li); in file_ms_alloc()
518 if ((ms->c.li = CAST(struct level_info *, malloc(len))) == NULL) in file_ms_alloc()
521 ms->event_flags = 0; in file_ms_alloc()
522 ms->error = -1; in file_ms_alloc()
524 ms->mlist[i] = NULL; in file_ms_alloc()
525 ms->file = "unknown"; in file_ms_alloc()
526 ms->line = 0; in file_ms_alloc()
527 ms->indir_max = FILE_INDIR_MAX; in file_ms_alloc()
528 ms->name_max = FILE_NAME_MAX; in file_ms_alloc()
529 ms->elf_shnum_max = FILE_ELF_SHNUM_MAX; in file_ms_alloc()
530 ms->elf_phnum_max = FILE_ELF_PHNUM_MAX; in file_ms_alloc()
531 ms->elf_notes_max = FILE_ELF_NOTES_MAX; in file_ms_alloc()
532 ms->regex_max = FILE_REGEX_MAX; in file_ms_alloc()
533 ms->bytes_max = FILE_BYTES_MAX; in file_ms_alloc()
534 return ms; in file_ms_alloc()
536 free(ms); in file_ms_alloc()
605 buffer_apprentice(struct magic_set *ms, struct magic **bufs, in buffer_apprentice() argument
615 (void)file_reset(ms, 0); in buffer_apprentice()
620 mlist_free(ms->mlist[i]); in buffer_apprentice()
621 if ((ms->mlist[i] = mlist_alloc()) == NULL) { in buffer_apprentice()
622 file_oomem(ms, sizeof(*ms->mlist[i])); in buffer_apprentice()
628 map = apprentice_buf(ms, bufs[i], sizes[i]); in buffer_apprentice()
633 if (add_mlist(ms->mlist[j], map, j) == -1) { in buffer_apprentice()
634 file_oomem(ms, sizeof(*ml)); in buffer_apprentice()
643 mlist_free(ms->mlist[i]); in buffer_apprentice()
644 ms->mlist[i] = NULL; in buffer_apprentice()
652 file_apprentice(struct magic_set *ms, const char *fn, int action) in file_apprentice() argument
658 (void)file_reset(ms, 0); in file_apprentice()
666 file_oomem(ms, strlen(fn)); in file_apprentice()
671 mlist_free(ms->mlist[i]); in file_apprentice()
672 if ((ms->mlist[i] = mlist_alloc()) == NULL) { in file_apprentice()
673 file_oomem(ms, sizeof(*ms->mlist[i])); in file_apprentice()
675 mlist_free(ms->mlist[i]); in file_apprentice()
676 ms->mlist[i] = NULL; in file_apprentice()
690 fileerr = apprentice_1(ms, fn, action); in file_apprentice()
699 mlist_free(ms->mlist[i]); in file_apprentice()
700 ms->mlist[i] = NULL; in file_apprentice()
702 file_error(ms, 0, "could not find any valid magic files!"); in file_apprentice()
714 mlist_free(ms->mlist[i]); in file_apprentice()
715 ms->mlist[i] = NULL; in file_apprentice()
726 file_error(ms, 0, "Invalid action %d", action); in file_apprentice()
1114 addentry(struct magic_set *ms, struct magic_entry *me, in addentry() argument
1125 file_oomem(ms, sizeof(*mp) * mset[i].max); in addentry()
1141 load_1(struct magic_set *ms, int action, const char *fn, int *errs, in load_1() argument
1149 FILE *f = fopen(ms->file = fn, "r"); in load_1()
1152 file_error(ms, errno, "cannot read magic file `%s'", in load_1()
1160 for (ms->line = 1; (len = getline(&line, &llen, f)) != -1; in load_1()
1161 ms->line++) { in load_1()
1183 file_error(ms, 0, in load_1()
1189 file_error(ms, 0, in load_1()
1195 if ((*bang[i].fun)(ms, &me, in load_1()
1205 switch (parse(ms, &me, line, lineno, action)) { in load_1()
1209 (void)addentry(ms, &me, mset); in load_1()
1218 (void)addentry(ms, &me, mset); in load_1()
1235 set_text_binary(struct magic_set *ms, struct magic_entry *me, uint32_t nme, in set_text_binary() argument
1246 if ((ms->flags & MAGIC_DEBUG) == 0) in set_text_binary()
1268 set_last_default(struct magic_set *ms, struct magic_entry *me, uint32_t nme) in set_last_default() argument
1279 ms->line = me[i].mp->lineno; in set_last_default()
1280 file_magwarn(ms, in set_last_default()
1289 coalesce_entries(struct magic_set *ms, struct magic_entry *me, uint32_t nme, in coalesce_entries() argument
1300 file_oomem(ms, slen); in coalesce_entries()
1326 apprentice_load(struct magic_set *ms, const char *fn, int action) in apprentice_load() argument
1339 ms->flags |= MAGIC_CHECK; /* Enable checks for parsed files */ in apprentice_load()
1344 file_oomem(ms, sizeof(*map)); in apprentice_load()
1364 file_oomem(ms, in apprentice_load()
1380 file_oomem(ms, mlen); in apprentice_load()
1392 load_1(ms, action, filearr[i], &errs, mset); in apprentice_load()
1397 load_1(ms, action, fn, &errs, mset); in apprentice_load()
1408 i = set_text_binary(ms, mset[j].me, mset[j].count, i); in apprentice_load()
1418 set_last_default(ms, mset[j].me, mset[j].count); in apprentice_load()
1421 if (coalesce_entries(ms, mset[j].me, mset[j].count, in apprentice_load()
1443 file_signextend(struct magic_set *ms, struct magic *m, uint64_t v) in file_signextend() argument
1508 if (ms->flags & MAGIC_CHECK) in file_signextend()
1509 file_magwarn(ms, "cannot happen: m->type=%d\n", in file_signextend()
1518 string_modifier_check(struct magic_set *ms, struct magic *m) in string_modifier_check() argument
1520 if ((ms->flags & MAGIC_CHECK) == 0) in string_modifier_check()
1525 file_magwarn(ms, in string_modifier_check()
1533 file_magwarn(ms, in string_modifier_check()
1541 file_magwarn(ms, in string_modifier_check()
1549 file_magwarn(ms, in string_modifier_check()
1558 file_magwarn(ms, "'/%c' not allowed on regex\n", in string_modifier_check()
1563 file_magwarn(ms, "'/%c' not allowed on regex\n", in string_modifier_check()
1569 file_magwarn(ms, "coding error: m->type=%d\n", in string_modifier_check()
1629 check_cond(struct magic_set *ms, int cond, uint32_t cont_level) in check_cond() argument
1632 last_cond = ms->c.li[cont_level].last_cond; in check_cond()
1637 if (ms->flags & MAGIC_CHECK) in check_cond()
1638 file_magwarn(ms, "syntax error: `if'"); in check_cond()
1646 if (ms->flags & MAGIC_CHECK) in check_cond()
1647 file_magwarn(ms, "syntax error: `elif'"); in check_cond()
1655 if (ms->flags & MAGIC_CHECK) in check_cond()
1656 file_magwarn(ms, "syntax error: `else'"); in check_cond()
1667 ms->c.li[cont_level].last_cond = last_cond; in check_cond()
1673 parse_indirect_modifier(struct magic_set *ms, struct magic *m, const char **lp) in parse_indirect_modifier() argument
1683 if (ms->flags & MAGIC_CHECK) in parse_indirect_modifier()
1684 file_magwarn(ms, "indirect modifier `%c' " in parse_indirect_modifier()
1694 parse_op_modifier(struct magic_set *ms, struct magic *m, const char **lp, in parse_op_modifier() argument
1705 m->num_mask = file_signextend(ms, m, val); in parse_op_modifier()
1711 parse_string_modifier(struct magic_set *ms, struct magic *m, const char **lp) in parse_string_modifier() argument
1723 if (have_range && (ms->flags & MAGIC_CHECK)) in parse_string_modifier()
1724 file_magwarn(ms, "multiple ranges"); in parse_string_modifier()
1728 file_magwarn(ms, "zero range"); in parse_string_modifier()
1793 if (ms->flags & MAGIC_CHECK) in parse_string_modifier()
1794 file_magwarn(ms, "string modifier `%c' " in parse_string_modifier()
1802 if (string_modifier_check(ms, m) == -1) in parse_string_modifier()
1815 parse(struct magic_set *ms, struct magic_entry *me, const char *line, in parse() argument
1840 if (file_check_mem(ms, cont_level) == -1) in parse()
1846 file_magerror(ms, "No current entry for continuation"); in parse()
1850 file_magerror(ms, "Continuations present with 0 count"); in parse()
1856 file_magwarn(ms, "New continuation level %u is more " in parse()
1864 file_oomem(ms, sizeof(*nm) * cnt); in parse()
1878 file_oomem(ms, len); in parse()
1907 if (ms->flags & MAGIC_CHECK) in parse()
1908 file_magwarn(ms, "relative offset at level 0"); in parse()
1915 if (ms->flags & MAGIC_CHECK) in parse()
1916 file_magwarn(ms, "offset `%s' invalid", l); in parse()
1922 if (ms->flags & MAGIC_CHECK) { in parse()
1923 file_magwarn(ms, in parse()
1990 if (ms->flags & MAGIC_CHECK) in parse()
1991 file_magwarn(ms, in parse()
2014 if (ms->flags & MAGIC_CHECK) in parse()
2015 file_magwarn(ms, in parse()
2023 if (ms->flags & MAGIC_CHECK) in parse()
2024 file_magwarn(ms, in parse()
2033 if (check_cond(ms, m->cond, cont_level) == -1) in parse()
2088 if (ms->flags & MAGIC_CHECK) in parse()
2089 file_magwarn(ms, "type `%s' invalid", l); in parse()
2100 else if (ms->flags & MAGIC_CHECK) in parse()
2101 file_magwarn(ms, "'~' invalid for string types"); in parse()
2111 if (ms->flags & MAGIC_CHECK) in parse()
2112 file_magwarn(ms, in parse()
2119 r = parse_indirect_modifier(ms, m, &l); in parse()
2121 r = parse_string_modifier(ms, m, &l); in parse()
2125 parse_op_modifier(ms, m, &l, op); in parse()
2140 if (ms->flags & MAGIC_CHECK) { in parse()
2141 file_magwarn(ms, "%c= not supported", in parse()
2175 if (m->reln != 'x' && getvalue(ms, m, &l, action)) in parse()
2200 if (ms->flags & MAGIC_CHECK) in parse()
2201 file_magwarn(ms, "description `%s' truncated", m->desc); in parse()
2208 if (ms->flags & MAGIC_CHECK) { in parse()
2209 if (check_format(ms, m) == -1) in parse()
2226 parse_strength(struct magic_set *ms, struct magic_entry *me, const char *line) in parse_strength() argument
2234 file_magwarn(ms, in parse_strength()
2240 file_magwarn(ms, "%s: Strength setting is not supported in " in parse_strength()
2254 file_magwarn(ms, "Unknown factor op `%c'", *l); in parse_strength()
2260 file_magwarn(ms, "Too large factor `%lu'", factor); in parse_strength()
2264 file_magwarn(ms, "Bad factor `%s'", l); in parse_strength()
2269 file_magwarn(ms, "Cannot have factor op `%c' and factor %u", in parse_strength()
2287 parse_extra(struct magic_set *ms, struct magic_entry *me, const char *line, in parse_extra() argument
2297 file_magwarn(ms, "Current entry already has a %s type " in parse_extra()
2303 file_magwarn(ms, "Current entry does not yet have a " in parse_extra()
2315 if (ms->flags & MAGIC_CHECK) in parse_extra()
2316 file_magwarn(ms, "%s type `%s' truncated %" in parse_extra()
2320 file_magwarn(ms, "%s type `%s' has bad char '%c'", in parse_extra()
2329 file_magerror(ms, "Bad magic entry '%s'", line); in parse_extra()
2338 parse_apple(struct magic_set *ms, struct magic_entry *me, const char *line) in parse_apple() argument
2342 return parse_extra(ms, me, line, in parse_apple()
2351 parse_ext(struct magic_set *ms, struct magic_entry *me, const char *line) in parse_ext() argument
2355 return parse_extra(ms, me, line, in parse_ext()
2365 parse_mime(struct magic_set *ms, struct magic_entry *me, const char *line) in parse_mime() argument
2369 return parse_extra(ms, me, line, in parse_mime()
2570 check_format(struct magic_set *ms, struct magic *m) in check_format() argument
2586 file_magwarn(ms, "Internal error inconsistency between " in check_format()
2591 file_magwarn(ms, "No format string for `%s' with description " in check_format()
2602 file_magwarn(ms, "Printf format is %s for type " in check_format()
2610 file_magwarn(ms, in check_format()
2626 getvalue(struct magic_set *ms, struct magic *m, const char **p, int action) in getvalue() argument
2641 *p = getstr(ms, m, *p, action == FILE_COMPILE); in getvalue()
2643 if (ms->flags & MAGIC_CHECK) in getvalue()
2644 file_magwarn(ms, "cannot get string from `%s'", in getvalue()
2652 if (ms->flags & MAGIC_CHECK) in getvalue()
2653 file_regerror(&rx, rc, ms); in getvalue()
2689 m->value.q = file_signextend(ms, m, ull); in getvalue()
2691 file_magwarn(ms, "Unparseable number `%s'", *p); in getvalue()
2698 file_magwarn(ms, in getvalue()
2723 file_magwarn(ms, "Overflow for numeric" in getvalue()
2743 getstr(struct magic_set *ms, struct magic *m, const char *s, int warn) in getstr() argument
2757 file_error(ms, 0, "string too long: `%s'", origs); in getstr()
2765 file_magwarn(ms, "incomplete escape"); in getstr()
2771 file_magwarn(ms, in getstr()
2785 file_magwarn(ms, "no " in getstr()
2790 file_magwarn(ms, in getstr()
3006 apprentice_buf(struct magic_set *ms, struct magic *buf, size_t len) in apprentice_buf() argument
3011 file_oomem(ms, sizeof(*map)); in apprentice_buf()
3017 if (check_buffer(ms, map, "buffer") != 0) { in apprentice_buf()
3029 apprentice_map(struct magic_set *ms, const char *fn) in apprentice_map() argument
3039 file_oomem(ms, sizeof(*map)); in apprentice_map()
3044 dbname = mkdbname(ms, fn, 0); in apprentice_map()
3052 file_error(ms, errno, "cannot stat `%s'", dbname); in apprentice_map()
3056 file_error(ms, 0, "file `%s' is too %s", dbname, in apprentice_map()
3066 file_error(ms, errno, "cannot map `%s'", dbname); in apprentice_map()
3072 file_oomem(ms, map->len); in apprentice_map()
3076 file_badread(ms); in apprentice_map()
3084 if (check_buffer(ms, map, dbname) != 0) { in apprentice_map()
3090 file_error(ms, errno, "cannot mprotect `%s'", dbname); in apprentice_map()
3107 check_buffer(struct magic_set *ms, struct magic_map *map, const char *dbname) in check_buffer() argument
3117 file_error(ms, 0, "bad magic in `%s'", dbname); in check_buffer()
3128 file_error(ms, 0, "File %s supports only version %d magic " in check_buffer()
3135 file_error(ms, 0, "Size of `%s' %" SIZE_T_FORMAT "u is not " in check_buffer()
3152 file_error(ms, 0, "Inconsistent entries in `%s' %u != %u", in check_buffer()
3166 apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn) in apprentice_compile() argument
3180 dbname = mkdbname(ms, fn, 1); in apprentice_compile()
3187 file_error(ms, errno, "cannot open `%s'", dbname); in apprentice_compile()
3196 file_error(ms, errno, "error writing `%s'", dbname); in apprentice_compile()
3203 file_error(ms, errno, "error writing `%s'", dbname); in apprentice_compile()
3223 mkdbname(struct magic_set *ms, const char *fn, int strip) in mkdbname() argument
3247 if (ms->flags & MAGIC_MIME) { in mkdbname()
3251 ms->flags &= MAGIC_MIME_TYPE; in mkdbname()
3261 ms->flags &= MAGIC_MIME_TYPE; in mkdbname()
3420 file_magicfind(struct magic_set *ms, const char *name, struct mlist *v) in file_magicfind() argument
3425 mlist = ms->mlist[1]; in file_magicfind()