Lines Matching refs:ms

117 file_private int getvalue(struct magic_set *ms, struct magic *, const char **, int);
197 struct magic_set *ms; in main() local
210 if ((ms = magic_open(MAGIC_CHECK)) == NULL) { in main()
214 ret = magic_compile(ms, argv[1]) == -1 ? 1 : 0; in main()
216 (void)fprintf(stderr, "%s: %s\n", progname, magic_error(ms)); in main()
217 magic_close(ms); in main()
467 apprentice_1(struct magic_set *ms, const char *fn, int action) in apprentice_1() argument
475 file_error(ms, 0, "magic element size %lu != %lu", in apprentice_1()
482 map = apprentice_load(ms, fn, action); in apprentice_1()
485 return apprentice_compile(ms, map, fn); in apprentice_1()
489 map = apprentice_map(ms, fn); in apprentice_1()
491 if (ms->flags & MAGIC_CHECK) in apprentice_1()
493 map = apprentice_load(ms, fn, action); in apprentice_1()
499 if (add_mlist(ms->mlist[i], map, i) == -1) { in apprentice_1()
504 mlist_free_all(ms); in apprentice_1()
505 file_oomem(ms, sizeof(*ms->mlist[0])); in apprentice_1()
514 apprentice_list(ms->mlist[i], BINTEST); in apprentice_1()
516 apprentice_list(ms->mlist[i], TEXTTEST); in apprentice_1()
526 file_ms_free(struct magic_set *ms) in file_ms_free() argument
529 if (ms == NULL) in file_ms_free()
532 mlist_free(ms->mlist[i]); in file_ms_free()
533 if (ms->o.pbuf) { in file_ms_free()
534 efree(ms->o.pbuf); in file_ms_free()
536 if (ms->o.buf) { in file_ms_free()
537 efree(ms->o.buf); in file_ms_free()
539 if (ms->c.li) { in file_ms_free()
540 efree(ms->c.li); in file_ms_free()
543 freelocale(ms->c_lc_ctype); in file_ms_free()
545 efree(ms); in file_ms_free()
551 struct magic_set *ms; in file_ms_alloc() local
554 if ((ms = CAST(struct magic_set *, ecalloc(CAST(size_t, 1u), in file_ms_alloc()
555 sizeof(*ms)))) == NULL) in file_ms_alloc()
558 if (magic_setflags(ms, flags) == -1) { in file_ms_alloc()
563 ms->o.buf = ms->o.pbuf = NULL; in file_ms_alloc()
564 ms->o.blen = 0; in file_ms_alloc()
565 len = (ms->c.len = 10) * sizeof(*ms->c.li); in file_ms_alloc()
567 if ((ms->c.li = CAST(struct level_info *, emalloc(len))) == NULL) in file_ms_alloc()
570 ms->event_flags = 0; in file_ms_alloc()
571 ms->error = -1; in file_ms_alloc()
573 ms->mlist[i] = NULL; in file_ms_alloc()
574 ms->file = "unknown"; in file_ms_alloc()
575 ms->line = 0; in file_ms_alloc()
576 ms->indir_max = FILE_INDIR_MAX; in file_ms_alloc()
577 ms->name_max = FILE_NAME_MAX; in file_ms_alloc()
578 ms->elf_shnum_max = FILE_ELF_SHNUM_MAX; in file_ms_alloc()
579 ms->elf_shsize_max = FILE_ELF_SHSIZE_MAX; in file_ms_alloc()
580 ms->elf_phnum_max = FILE_ELF_PHNUM_MAX; in file_ms_alloc()
581 ms->elf_notes_max = FILE_ELF_NOTES_MAX; in file_ms_alloc()
582 ms->regex_max = FILE_REGEX_MAX; in file_ms_alloc()
583 ms->bytes_max = FILE_BYTES_MAX; in file_ms_alloc()
584 ms->encoding_max = FILE_ENCODING_MAX; in file_ms_alloc()
586 ms->c_lc_ctype = newlocale(LC_CTYPE_MASK, "C", 0); in file_ms_alloc()
587 assert(ms->c_lc_ctype != NULL); in file_ms_alloc()
589 return ms; in file_ms_alloc()
591 efree(ms); in file_ms_alloc()
627 mlist_free_all(struct magic_set *ms) in mlist_free_all() argument
632 mlist_free(ms->mlist[i]); in mlist_free_all()
633 ms->mlist[i] = NULL; in mlist_free_all()
663 file_apprentice(struct magic_set *ms, const char *fn, int action) in file_apprentice() argument
669 (void)file_reset(ms, 0); in file_apprentice()
683 mlist_free(ms->mlist[i]); in file_apprentice()
684 if ((ms->mlist[i] = mlist_alloc()) == NULL) { in file_apprentice()
685 file_oomem(ms, sizeof(*ms->mlist[i])); in file_apprentice()
689 return apprentice_1(ms, fn, action); in file_apprentice()
693 file_oomem(ms, strlen(fn)); in file_apprentice()
698 mlist_free(ms->mlist[i]); in file_apprentice()
699 if ((ms->mlist[i] = mlist_alloc()) == NULL) { in file_apprentice()
700 file_oomem(ms, sizeof(*ms->mlist[0])); in file_apprentice()
702 mlist_free(ms->mlist[j]); in file_apprentice()
703 ms->mlist[j] = NULL; in file_apprentice()
717 fileerr = apprentice_1(ms, fn, action); in file_apprentice()
726 mlist_free(ms->mlist[i]); in file_apprentice()
727 ms->mlist[i] = NULL; in file_apprentice()
729 file_error(ms, 0, "could not find any valid magic files!"); in file_apprentice()
741 mlist_free(ms->mlist[i]); in file_apprentice()
742 ms->mlist[i] = NULL; in file_apprentice()
753 file_error(ms, 0, "Invalid action %d", action); in file_apprentice()
1228 addentry(struct magic_set *ms, struct magic_entry *me, in addentry() argument
1239 file_oomem(ms, sizeof(*mp) * incr); in addentry()
1257 load_1(struct magic_set *ms, int action, const char *fn, int *errs, in load_1() argument
1269 ms->file = fn; in load_1()
1274 file_error(ms, errno, "cannot read magic file `%s'", in load_1()
1282 …for (ms->line = 1; (line = php_stream_get_line(stream, buffer , BUFSIZ, &len)) != NULL; ms->line++… in load_1()
1304 file_error(ms, 0, in load_1()
1310 file_error(ms, 0, in load_1()
1316 if ((*bang[i].fun)(ms, &me, in load_1()
1327 switch (parse(ms, &me, line, lineno, action)) { in load_1()
1331 (void)addentry(ms, &me, mset); in load_1()
1340 (void)addentry(ms, &me, mset); in load_1()
1357 set_text_binary(struct magic_set *ms, struct magic_entry *me, uint32_t nme, in set_text_binary() argument
1368 if ((ms->flags & MAGIC_DEBUG) == 0) in set_text_binary()
1390 set_last_default(struct magic_set *ms, struct magic_entry *me, uint32_t nme) in set_last_default() argument
1401 ms->line = me[i].mp->lineno; in set_last_default()
1402 file_magwarn(ms, in set_last_default()
1411 coalesce_entries(struct magic_set *ms, struct magic_entry *me, uint32_t nme, in coalesce_entries() argument
1428 file_oomem(ms, slen); in coalesce_entries()
1454 apprentice_load(struct magic_set *ms, const char *fn, int action) in apprentice_load() argument
1468 ms->flags |= MAGIC_CHECK; /* Enable checks for parsed files */ in apprentice_load()
1473 file_oomem(ms, sizeof(*map)); in apprentice_load()
1496 file_oomem(ms, in apprentice_load()
1511 file_oomem(ms, mlen); in apprentice_load()
1523 load_1(ms, action, filearr[i], &errs, mset); in apprentice_load()
1529 load_1(ms, action, fn, &errs, mset); in apprentice_load()
1540 i = set_text_binary(ms, mset[j].me, mset[j].count, i); in apprentice_load()
1550 set_last_default(ms, mset[j].me, mset[j].count); in apprentice_load()
1556 if (coalesce_entries(ms, mset[j].me, mset[j].count, in apprentice_load()
1578 file_signextend(struct magic_set *ms, struct magic *m, uint64_t v) in file_signextend() argument
1654 if (ms->flags & MAGIC_CHECK) in file_signextend()
1655 file_magwarn(ms, "cannot happen: m->type=%d\n", in file_signextend()
1664 string_modifier_check(struct magic_set *ms, struct magic *m) in string_modifier_check() argument
1666 if ((ms->flags & MAGIC_CHECK) == 0) in string_modifier_check()
1671 file_magwarn(ms, in string_modifier_check()
1679 file_magwarn(ms, in string_modifier_check()
1687 file_magwarn(ms, in string_modifier_check()
1695 file_magwarn(ms, in string_modifier_check()
1704 file_magwarn(ms, "'/%c' not allowed on regex\n", in string_modifier_check()
1709 file_magwarn(ms, "'/%c' not allowed on regex\n", in string_modifier_check()
1715 file_magwarn(ms, "coding error: m->type=%d\n", in string_modifier_check()
1775 check_cond(struct magic_set *ms, int cond, uint32_t cont_level) in check_cond() argument
1778 last_cond = ms->c.li[cont_level].last_cond; in check_cond()
1783 if (ms->flags & MAGIC_CHECK) in check_cond()
1784 file_magwarn(ms, "syntax error: `if'"); in check_cond()
1792 if (ms->flags & MAGIC_CHECK) in check_cond()
1793 file_magwarn(ms, "syntax error: `elif'"); in check_cond()
1801 if (ms->flags & MAGIC_CHECK) in check_cond()
1802 file_magwarn(ms, "syntax error: `else'"); in check_cond()
1813 ms->c.li[cont_level].last_cond = last_cond; in check_cond()
1819 parse_indirect_modifier(struct magic_set *ms, struct magic *m, const char **lp) in parse_indirect_modifier() argument
1829 if (ms->flags & MAGIC_CHECK) in parse_indirect_modifier()
1830 file_magwarn(ms, "indirect modifier `%c' " in parse_indirect_modifier()
1840 parse_op_modifier(struct magic_set *ms, struct magic *m, const char **lp, in parse_op_modifier() argument
1851 m->num_mask = file_signextend(ms, m, val); in parse_op_modifier()
1857 parse_string_modifier(struct magic_set *ms, struct magic *m, const char **lp) in parse_string_modifier() argument
1869 if (have_range && (ms->flags & MAGIC_CHECK)) in parse_string_modifier()
1870 file_magwarn(ms, "multiple ranges"); in parse_string_modifier()
1874 file_magwarn(ms, "zero range"); in parse_string_modifier()
1942 if (ms->flags & MAGIC_CHECK) in parse_string_modifier()
1943 file_magwarn(ms, "string modifier `%c' " in parse_string_modifier()
1951 if (string_modifier_check(ms, m) == -1) in parse_string_modifier()
1964 parse(struct magic_set *ms, struct magic_entry *me, const char *line, in parse() argument
1989 if (file_check_mem(ms, cont_level) == -1) in parse()
1995 file_magerror(ms, "No current entry for continuation"); in parse()
1999 file_magerror(ms, "Continuations present with 0 count"); in parse()
2005 file_magwarn(ms, "New continuation level %u is more " in parse()
2013 file_oomem(ms, sizeof(*nm) * cnt); in parse()
2027 file_oomem(ms, len); in parse()
2056 if (ms->flags & MAGIC_CHECK) in parse()
2057 file_magwarn(ms, "relative offset at level 0"); in parse()
2068 if (ms->flags & MAGIC_CHECK) in parse()
2069 file_magwarn(ms, "offset `%s' invalid", l); in parse()
2136 if (ms->flags & MAGIC_CHECK) in parse()
2137 file_magwarn(ms, in parse()
2160 if (ms->flags & MAGIC_CHECK) in parse()
2161 file_magwarn(ms, in parse()
2169 if (ms->flags & MAGIC_CHECK) in parse()
2170 file_magwarn(ms, in parse()
2179 if (check_cond(ms, m->cond, cont_level) == -1) in parse()
2235 if (ms->flags & MAGIC_CHECK) in parse()
2236 file_magwarn(ms, "type `%s' invalid", l); in parse()
2241 if (ms->flags & MAGIC_CHECK) in parse()
2242 file_magwarn(ms, "`name%s' entries can only be " in parse()
2254 else if (ms->flags & MAGIC_CHECK) in parse()
2255 file_magwarn(ms, "'~' invalid for string types"); in parse()
2265 if (ms->flags & MAGIC_CHECK) in parse()
2266 file_magwarn(ms, in parse()
2273 r = parse_indirect_modifier(ms, m, &l); in parse()
2275 r = parse_string_modifier(ms, m, &l); in parse()
2279 parse_op_modifier(ms, m, &l, op); in parse()
2294 if (ms->flags & MAGIC_CHECK) { in parse()
2295 file_magwarn(ms, "%c= not supported", in parse()
2329 if (m->reln != 'x' && getvalue(ms, m, &l, action)) in parse()
2354 if (ms->flags & MAGIC_CHECK) in parse()
2355 file_magwarn(ms, "description `%s' truncated", m->desc); in parse()
2362 if (ms->flags & MAGIC_CHECK) { in parse()
2363 if (check_format(ms, m) == -1) in parse()
2381 parse_strength(struct magic_set *ms, struct magic_entry *me, const char *line, in parse_strength() argument
2391 file_magwarn(ms, in parse_strength()
2397 file_magwarn(ms, "%s: Strength setting is not supported in " in parse_strength()
2399 file_printable(ms, sbuf, sizeof(sbuf), m->value.s, in parse_strength()
2414 file_magwarn(ms, "Unknown factor op `%c'", *l); in parse_strength()
2420 file_magwarn(ms, "Too large factor `%lu'", factor); in parse_strength()
2424 file_magwarn(ms, "Bad factor `%s'", l); in parse_strength()
2429 file_magwarn(ms, "Cannot have factor op `%c' and factor %u", in parse_strength()
2447 parse_extra(struct magic_set *ms, struct magic_entry *me, const char *line, in parse_extra() argument
2458 file_magwarn(ms, "Current entry already has a %s type " in parse_extra()
2464 file_magwarn(ms, "Current entry does not yet have a " in parse_extra()
2477 if (ms->flags & MAGIC_CHECK) in parse_extra()
2478 file_magwarn(ms, "%s type `%s' truncated %" in parse_extra()
2482 file_magwarn(ms, "%s type `%s' has bad char '%c'", in parse_extra()
2491 file_magerror(ms, "Bad magic entry '%s'", line); in parse_extra()
2500 parse_apple(struct magic_set *ms, struct magic_entry *me, const char *line, in parse_apple() argument
2503 return parse_extra(ms, me, line, len, in parse_apple()
2512 parse_ext(struct magic_set *ms, struct magic_entry *me, const char *line, in parse_ext() argument
2515 return parse_extra(ms, me, line, len, in parse_ext()
2527 parse_mime(struct magic_set *ms, struct magic_entry *me, const char *line, in parse_mime() argument
2530 return parse_extra(ms, me, line, len, in parse_mime()
2730 check_format(struct magic_set *ms, struct magic *m) in check_format() argument
2746 file_magwarn(ms, "Internal error inconsistency between " in check_format()
2751 file_magwarn(ms, "No format string for `%s' with description " in check_format()
2762 file_magwarn(ms, "Printf format is %s for type " in check_format()
2770 file_magwarn(ms, in check_format()
2786 getvalue(struct magic_set *ms, struct magic *m, const char **p, int action) in getvalue() argument
2803 *p = getstr(ms, m, *p, action == FILE_COMPILE); in getvalue()
2805 if (ms->flags & MAGIC_CHECK) in getvalue()
2806 file_magwarn(ms, "cannot get string from `%s'", in getvalue()
2861 m->value.q = file_signextend(ms, m, ull); in getvalue()
2863 file_magwarn(ms, "Unparsable number `%s'", *p); in getvalue()
2871 file_magwarn(ms, in getvalue()
2902 file_magwarn(ms, "Overflow for numeric" in getvalue()
2923 getstr(struct magic_set *ms, struct magic *m, const char *s, int warn) in getstr() argument
2938 file_error(ms, 0, "string too long: `%s'", origs); in getstr()
2955 file_magwarn(ms, "incomplete escape"); in getstr()
2961 file_magwarn(ms, "escaped dot ('.') found, " in getstr()
2968 file_magwarn(ms, in getstr()
2982 file_magwarn(ms, "no " in getstr()
2987 file_magwarn(ms, in getstr()
3090 size_t l = file_pstring_length_size(ms, m); in getstr()
3206 apprentice_map(struct magic_set *ms, const char *fn) in apprentice_map() argument
3220 file_oomem(ms, sizeof(*map)); in apprentice_map()
3239 dbname = mkdbname(ms, fn, 0); in apprentice_map()
3251 file_error(ms, errno, "cannot stat `%s'", dbname); in apprentice_map()
3256 file_error(ms, 0, "file `%s' is too %s", dbname, in apprentice_map()
3266 file_badread(ms); in apprentice_map()
3277 file_error(ms, 0, "bad magic in `%s'", dbname); in apprentice_map()
3288 file_error(ms, 0, "File %d supports only version %d magic " in apprentice_map()
3306 file_error(ms, 0, "Size of `%s' %llu is not a multiple of %zu", in apprentice_map()
3324 file_error(ms, 0, "Inconsistent entries in `%s' %u != %u", in apprentice_map()
3352 apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn) in apprentice_compile() argument
3366 dbname = mkdbname(ms, fn, 1); in apprentice_compile()
3375 file_error(ms, errno, "cannot open `%s'", dbname); in apprentice_compile()
3384 file_error(ms, errno, "error writing `%s'", dbname); in apprentice_compile()
3391 file_error(ms, errno, "error writing `%s'", dbname); in apprentice_compile()
3410 mkdbname(struct magic_set *ms, const char *fn, int strip) argument
3434 if (ms->flags & MAGIC_MIME) {
3441 ms->flags &= MAGIC_MIME_TYPE;
3450 ms->flags &= MAGIC_MIME_TYPE;
3579 file_pstring_length_size(struct magic_set *ms, const struct magic *m) argument
3591 file_error(ms, 0, "corrupt magic file "
3598 file_pstring_get_length(struct magic_set *ms, const struct magic *m, argument
3634 file_error(ms, 0, "corrupt magic file "
3641 size_t l = file_pstring_length_size(ms, m);
3651 file_magicfind(struct magic_set *ms, const char *name, struct mlist *v) argument
3656 mlist = ms->mlist[1];