Lines Matching refs:ms
115 file_private int getvalue(struct magic_set *ms, struct magic *, const char **, int);
196 struct magic_set *ms; in main() local
209 if ((ms = magic_open(MAGIC_CHECK)) == NULL) { in main()
213 ret = magic_compile(ms, argv[1]) == -1 ? 1 : 0; in main()
215 (void)fprintf(stderr, "%s: %s\n", progname, magic_error(ms)); in main()
216 magic_close(ms); in main()
474 apprentice_1(struct magic_set *ms, const char *fn, int action) in apprentice_1() argument
482 file_error(ms, 0, "magic element size %lu != %lu", in apprentice_1()
489 map = apprentice_load(ms, fn, action); in apprentice_1()
492 return apprentice_compile(ms, map, fn); in apprentice_1()
496 map = apprentice_map(ms, fn); in apprentice_1()
498 if (ms->flags & MAGIC_CHECK) in apprentice_1()
499 file_magwarn(ms, "using regular magic file `%s'", fn); in apprentice_1()
500 map = apprentice_load(ms, fn, action); in apprentice_1()
506 if (add_mlist(ms->mlist[i], map, i) == -1) { in apprentice_1()
511 mlist_free_all(ms); in apprentice_1()
512 file_oomem(ms, sizeof(*ms->mlist[0])); in apprentice_1()
521 apprentice_list(ms->mlist[i], BINTEST); in apprentice_1()
523 apprentice_list(ms->mlist[i], TEXTTEST); in apprentice_1()
533 file_ms_free(struct magic_set *ms) in file_ms_free() argument
536 if (ms == NULL) in file_ms_free()
539 mlist_free(ms->mlist[i]); in file_ms_free()
540 free(ms->o.pbuf); in file_ms_free()
541 free(ms->o.buf); in file_ms_free()
542 free(ms->c.li); in file_ms_free()
543 free(ms->fnamebuf); in file_ms_free()
545 freelocale(ms->c_lc_ctype); in file_ms_free()
547 free(ms); in file_ms_free()
553 struct magic_set *ms; in file_ms_alloc() local
556 if ((ms = CAST(struct magic_set *, calloc(CAST(size_t, 1u), in file_ms_alloc()
557 sizeof(*ms)))) == NULL) in file_ms_alloc()
560 if (magic_setflags(ms, flags) == -1) { in file_ms_alloc()
565 ms->o.buf = ms->o.pbuf = NULL; in file_ms_alloc()
566 ms->o.blen = 0; in file_ms_alloc()
567 len = (ms->c.len = 10) * sizeof(*ms->c.li); in file_ms_alloc()
569 if ((ms->c.li = CAST(struct level_info *, malloc(len))) == NULL) in file_ms_alloc()
572 ms->event_flags = 0; in file_ms_alloc()
573 ms->error = -1; in file_ms_alloc()
575 ms->mlist[i] = NULL; in file_ms_alloc()
576 ms->fnamebuf = NULL; in file_ms_alloc()
577 ms->file = "unknown"; in file_ms_alloc()
578 ms->line = 0; in file_ms_alloc()
579 ms->magwarn = 0; in file_ms_alloc()
580 ms->indir_max = FILE_INDIR_MAX; in file_ms_alloc()
581 ms->name_max = FILE_NAME_MAX; in file_ms_alloc()
582 ms->elf_shnum_max = FILE_ELF_SHNUM_MAX; in file_ms_alloc()
583 ms->elf_shsize_max = FILE_ELF_SHSIZE_MAX; in file_ms_alloc()
584 ms->elf_phnum_max = FILE_ELF_PHNUM_MAX; in file_ms_alloc()
585 ms->elf_notes_max = FILE_ELF_NOTES_MAX; in file_ms_alloc()
586 ms->regex_max = FILE_REGEX_MAX; in file_ms_alloc()
587 ms->bytes_max = FILE_BYTES_MAX; in file_ms_alloc()
588 ms->encoding_max = FILE_ENCODING_MAX; in file_ms_alloc()
589 ms->magwarn_max = FILE_MAGWARN_MAX; in file_ms_alloc()
591 ms->c_lc_ctype = newlocale(LC_CTYPE_MASK, "C", 0); in file_ms_alloc()
592 assert(ms->c_lc_ctype != NULL); in file_ms_alloc()
594 return ms; in file_ms_alloc()
596 free(ms); in file_ms_alloc()
646 mlist_free_all(struct magic_set *ms) in mlist_free_all() argument
651 mlist_free(ms->mlist[i]); in mlist_free_all()
652 ms->mlist[i] = NULL; in mlist_free_all()
695 buffer_apprentice(struct magic_set *ms, struct magic **bufs, in buffer_apprentice() argument
704 (void)file_reset(ms, 0); in buffer_apprentice()
709 mlist_free(ms->mlist[i]); in buffer_apprentice()
710 if ((ms->mlist[i] = mlist_alloc()) == NULL) { in buffer_apprentice()
711 file_oomem(ms, sizeof(*ms->mlist[0])); in buffer_apprentice()
717 map = apprentice_buf(ms, bufs[i], sizes[i]); in buffer_apprentice()
722 if (add_mlist(ms->mlist[j], map, j) == -1) { in buffer_apprentice()
723 file_oomem(ms, sizeof(*ms->mlist[0])); in buffer_apprentice()
731 mlist_free_all(ms); in buffer_apprentice()
738 file_apprentice(struct magic_set *ms, const char *fn, int action) in file_apprentice() argument
744 (void)file_reset(ms, 0); in file_apprentice()
751 free(ms->fnamebuf); in file_apprentice()
752 if ((ms->fnamebuf = strdup(fn)) == NULL) { in file_apprentice()
753 file_oomem(ms, strlen(fn)); in file_apprentice()
758 mlist_free(ms->mlist[i]); in file_apprentice()
759 if ((ms->mlist[i] = mlist_alloc()) == NULL) { in file_apprentice()
760 file_oomem(ms, sizeof(*ms->mlist[0])); in file_apprentice()
762 mlist_free(ms->mlist[j]); in file_apprentice()
763 ms->mlist[j] = NULL; in file_apprentice()
768 fn = ms->fnamebuf; in file_apprentice()
776 fileerr = apprentice_1(ms, fn, action); in file_apprentice()
783 mlist_free(ms->mlist[i]); in file_apprentice()
784 ms->mlist[i] = NULL; in file_apprentice()
786 file_error(ms, 0, "could not find any valid magic files!"); in file_apprentice()
798 mlist_free(ms->mlist[i]); in file_apprentice()
799 ms->mlist[i] = NULL; in file_apprentice()
810 file_error(ms, 0, "Invalid action %d", action); in file_apprentice()
1299 addentry(struct magic_set *ms, struct magic_entry *me, in addentry() argument
1310 file_oomem(ms, sizeof(*mp) * incr); in addentry()
1328 load_1(struct magic_set *ms, int action, const char *fn, int *errs, in load_1() argument
1336 FILE *f = fopen(ms->file = fn, "r"); in load_1()
1339 file_error(ms, errno, "cannot read magic file `%s'", in load_1()
1347 for (ms->line = 1; (len = getline(&line, &llen, f)) != -1; in load_1()
1348 ms->line++) { in load_1()
1349 if (ms->magwarn >= ms->magwarn_max) in load_1()
1372 file_error(ms, 0, in load_1()
1378 file_error(ms, 0, in load_1()
1384 if ((*bang[i].fun)(ms, &me, in load_1()
1395 switch (parse(ms, &me, fn, line, lineno, action)) { in load_1()
1399 (void)addentry(ms, &me, mset); in load_1()
1408 (void)addentry(ms, &me, mset); in load_1()
1425 set_text_binary(struct magic_set *ms, struct magic_entry *me, uint32_t nme, in set_text_binary() argument
1436 if ((ms->flags & MAGIC_DEBUG) == 0) in set_text_binary()
1458 set_last_default(struct magic_set *ms, struct magic_entry *me, uint32_t nme) in set_last_default() argument
1469 ms->line = me[i].mp->lineno; in set_last_default()
1470 file_magwarn(ms, in set_last_default()
1479 coalesce_entries(struct magic_set *ms, struct magic_entry *me, uint32_t nme, in coalesce_entries() argument
1496 file_oomem(ms, slen); in coalesce_entries()
1522 apprentice_load(struct magic_set *ms, const char *fn, int action) in apprentice_load() argument
1535 ms->flags |= MAGIC_CHECK; /* Enable checks for parsed files */ in apprentice_load()
1540 file_oomem(ms, sizeof(*map)); in apprentice_load()
1560 file_oomem(ms, in apprentice_load()
1577 file_oomem(ms, mlen); in apprentice_load()
1591 load_1(ms, action, filearr[i], &errs, mset); in apprentice_load()
1598 load_1(ms, action, fn, &errs, mset); in apprentice_load()
1609 i = set_text_binary(ms, mset[j].me, mset[j].count, i); in apprentice_load()
1619 set_last_default(ms, mset[j].me, mset[j].count); in apprentice_load()
1625 if (coalesce_entries(ms, mset[j].me, mset[j].count, in apprentice_load()
1648 file_signextend(struct magic_set *ms, struct magic *m, uint64_t v) in file_signextend() argument
1724 if (ms->flags & MAGIC_CHECK) in file_signextend()
1725 file_magwarn(ms, "cannot happen: m->type=%d\n", in file_signextend()
1734 string_modifier_check(struct magic_set *ms, struct magic *m) in string_modifier_check() argument
1736 if ((ms->flags & MAGIC_CHECK) == 0) in string_modifier_check()
1741 file_magwarn(ms, in string_modifier_check()
1749 file_magwarn(ms, in string_modifier_check()
1757 file_magwarn(ms, in string_modifier_check()
1765 file_magwarn(ms, in string_modifier_check()
1774 file_magwarn(ms, "'/%c' not allowed on regex\n", in string_modifier_check()
1779 file_magwarn(ms, "'/%c' not allowed on regex\n", in string_modifier_check()
1785 file_magwarn(ms, "coding error: m->type=%d\n", in string_modifier_check()
1845 check_cond(struct magic_set *ms, int cond, uint32_t cont_level) in check_cond() argument
1848 last_cond = ms->c.li[cont_level].last_cond; in check_cond()
1853 if (ms->flags & MAGIC_CHECK) in check_cond()
1854 file_magwarn(ms, "syntax error: `if'"); in check_cond()
1862 if (ms->flags & MAGIC_CHECK) in check_cond()
1863 file_magwarn(ms, "syntax error: `elif'"); in check_cond()
1871 if (ms->flags & MAGIC_CHECK) in check_cond()
1872 file_magwarn(ms, "syntax error: `else'"); in check_cond()
1883 ms->c.li[cont_level].last_cond = last_cond; in check_cond()
1889 parse_indirect_modifier(struct magic_set *ms, struct magic *m, const char **lp) in parse_indirect_modifier() argument
1899 if (ms->flags & MAGIC_CHECK) in parse_indirect_modifier()
1900 file_magwarn(ms, "indirect modifier `%c' " in parse_indirect_modifier()
1910 parse_op_modifier(struct magic_set *ms, struct magic *m, const char **lp, in parse_op_modifier() argument
1921 m->num_mask = file_signextend(ms, m, val); in parse_op_modifier()
1927 parse_string_modifier(struct magic_set *ms, struct magic *m, const char **lp) in parse_string_modifier() argument
1939 if (have_range && (ms->flags & MAGIC_CHECK)) in parse_string_modifier()
1940 file_magwarn(ms, "multiple ranges"); in parse_string_modifier()
1944 file_magwarn(ms, "zero range"); in parse_string_modifier()
2012 if (ms->flags & MAGIC_CHECK) in parse_string_modifier()
2013 file_magwarn(ms, "string modifier `%c' " in parse_string_modifier()
2021 if (string_modifier_check(ms, m) == -1) in parse_string_modifier()
2034 parse(struct magic_set *ms, struct magic_entry *me, const char *file, in parse() argument
2059 if (file_check_mem(ms, cont_level) == -1) in parse()
2065 file_magerror(ms, "No current entry for continuation"); in parse()
2069 file_magerror(ms, "Continuations present with 0 count"); in parse()
2075 file_magwarn(ms, "New continuation level %u is more " in parse()
2083 file_oomem(ms, sizeof(*nm) * cnt); in parse()
2097 file_oomem(ms, len); in parse()
2126 if (ms->flags & MAGIC_CHECK) in parse()
2127 file_magwarn(ms, "relative offset at level 0"); in parse()
2138 if (ms->flags & MAGIC_CHECK) in parse()
2139 file_magwarn(ms, "offset `%s' invalid", l); in parse()
2206 if (ms->flags & MAGIC_CHECK) in parse()
2207 file_magwarn(ms, in parse()
2230 if (ms->flags & MAGIC_CHECK) in parse()
2231 file_magwarn(ms, in parse()
2239 if (ms->flags & MAGIC_CHECK) in parse()
2240 file_magwarn(ms, in parse()
2249 if (check_cond(ms, m->cond, cont_level) == -1) in parse()
2305 if (ms->flags & MAGIC_CHECK) in parse()
2306 file_magwarn(ms, "type `%s' invalid", l); in parse()
2311 if (ms->flags & MAGIC_CHECK) in parse()
2312 file_magwarn(ms, "`name%s' entries can only be " in parse()
2324 else if (ms->flags & MAGIC_CHECK) in parse()
2325 file_magwarn(ms, "'~' invalid for string types"); in parse()
2335 if (ms->flags & MAGIC_CHECK) in parse()
2336 file_magwarn(ms, in parse()
2343 r = parse_indirect_modifier(ms, m, &l); in parse()
2345 r = parse_string_modifier(ms, m, &l); in parse()
2349 parse_op_modifier(ms, m, &l, op); in parse()
2364 if (ms->flags & MAGIC_CHECK) { in parse()
2365 file_magwarn(ms, "%c= not supported", in parse()
2399 if (m->reln != 'x' && getvalue(ms, m, &l, action)) in parse()
2428 if (ms->flags & MAGIC_CHECK) in parse()
2429 file_magwarn(ms, "description `%s' truncated", m->desc); in parse()
2436 if (ms->flags & MAGIC_CHECK) { in parse()
2437 if (check_format(ms, m) == -1) in parse()
2455 parse_strength(struct magic_set *ms, struct magic_entry *me, const char *line, in parse_strength() argument
2465 file_magwarn(ms, in parse_strength()
2471 file_magwarn(ms, "%s: Strength setting is not supported in " in parse_strength()
2473 file_printable(ms, sbuf, sizeof(sbuf), m->value.s, in parse_strength()
2488 file_magwarn(ms, "Unknown factor op `%c'", *l); in parse_strength()
2494 file_magwarn(ms, "Too large factor `%lu'", factor); in parse_strength()
2498 file_magwarn(ms, "Bad factor `%s'", l); in parse_strength()
2503 file_magwarn(ms, "Cannot have factor op `%c' and factor %u", in parse_strength()
2521 parse_extra(struct magic_set *ms, struct magic_entry *me, const char *line, in parse_extra() argument
2532 file_magwarn(ms, "Current entry already has a %s type " in parse_extra()
2538 file_magwarn(ms, "Current entry does not yet have a " in parse_extra()
2551 if (ms->flags & MAGIC_CHECK) in parse_extra()
2552 file_magwarn(ms, "%s type `%s' truncated %" in parse_extra()
2556 file_magwarn(ms, "%s type `%s' has bad char '%c'", in parse_extra()
2565 file_magerror(ms, "Bad magic entry '%s'", line); in parse_extra()
2574 parse_apple(struct magic_set *ms, struct magic_entry *me, const char *line, in parse_apple() argument
2577 return parse_extra(ms, me, line, len, in parse_apple()
2586 parse_ext(struct magic_set *ms, struct magic_entry *me, const char *line, in parse_ext() argument
2589 return parse_extra(ms, me, line, len, in parse_ext()
2602 parse_mime(struct magic_set *ms, struct magic_entry *me, const char *line, in parse_mime() argument
2605 return parse_extra(ms, me, line, len, in parse_mime()
2806 check_format(struct magic_set *ms, struct magic *m) in check_format() argument
2822 file_magwarn(ms, "Internal error inconsistency between " in check_format()
2827 file_magwarn(ms, "No format string for `%s' with description " in check_format()
2838 file_magwarn(ms, "Printf format is %s for type " in check_format()
2846 file_magwarn(ms, in check_format()
2862 getvalue(struct magic_set *ms, struct magic *m, const char **p, int action) in getvalue() argument
2879 *p = getstr(ms, m, *p, action == FILE_COMPILE); in getvalue()
2881 if (ms->flags & MAGIC_CHECK) in getvalue()
2882 file_magwarn(ms, "cannot get string from `%s'", in getvalue()
2889 file_regcomp(ms, &rx, m->value.s, REG_EXTENDED); in getvalue()
2931 m->value.q = file_signextend(ms, m, ull); in getvalue()
2933 file_magwarn(ms, "Unparsable number `%s'", *p); in getvalue()
2941 file_magwarn(ms, in getvalue()
2972 file_magwarn(ms, "Overflow for numeric" in getvalue()
2993 getstr(struct magic_set *ms, struct magic *m, const char *s, int warn) in getstr() argument
3008 file_error(ms, 0, "string too long: `%s'", origs); in getstr()
3025 file_magwarn(ms, "incomplete escape"); in getstr()
3031 file_magwarn(ms, "escaped dot ('.') found, " in getstr()
3038 file_magwarn(ms, in getstr()
3052 file_magwarn(ms, "no " in getstr()
3057 file_magwarn(ms, in getstr()
3160 size_t l = file_pstring_length_size(ms, m); in getstr()
3275 apprentice_buf(struct magic_set *ms, struct magic *buf, size_t len) in apprentice_buf() argument
3280 file_oomem(ms, sizeof(*map)); in apprentice_buf()
3286 if (check_buffer(ms, map, "buffer") != 0) { in apprentice_buf()
3298 apprentice_map(struct magic_set *ms, const char *fn) in apprentice_map() argument
3308 file_oomem(ms, sizeof(*map)); in apprentice_map()
3313 dbname = mkdbname(ms, fn, 0); in apprentice_map()
3321 file_error(ms, errno, "cannot stat `%s'", dbname); in apprentice_map()
3325 file_error(ms, 0, "file `%s' is too %s", dbname, in apprentice_map()
3335 file_error(ms, errno, "cannot map `%s'", dbname); in apprentice_map()
3341 file_oomem(ms, map->len); in apprentice_map()
3345 file_badread(ms); in apprentice_map()
3352 if (check_buffer(ms, map, dbname) != 0) { in apprentice_map()
3357 file_error(ms, errno, "cannot mprotect `%s'", dbname); in apprentice_map()
3374 check_buffer(struct magic_set *ms, struct magic_map *map, const char *dbname) in check_buffer() argument
3383 file_error(ms, 0, "Too few magic entries %u in `%s'", in check_buffer()
3388 file_error(ms, 0, "Size of `%s' %" SIZE_T_FORMAT "u is not " in check_buffer()
3397 file_error(ms, 0, "bad magic in `%s'", dbname); in check_buffer()
3408 file_error(ms, 0, "File %s supports only version %d magic " in check_buffer()
3425 file_error(ms, 0, "Inconsistent entries in `%s' %u != %u", in check_buffer()
3439 apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn) in apprentice_compile() argument
3453 dbname = mkdbname(ms, fn, 1); in apprentice_compile()
3460 file_error(ms, errno, "cannot open `%s'", dbname); in apprentice_compile()
3469 file_error(ms, errno, "error writing `%s'", dbname); in apprentice_compile()
3476 file_error(ms, errno, "error writing `%s'", dbname); in apprentice_compile()
3496 mkdbname(struct magic_set *ms, const char *fn, int strip) in mkdbname() argument
3520 if (ms->flags & MAGIC_MIME) { in mkdbname()
3525 ms->flags &= MAGIC_MIME_TYPE; in mkdbname()
3535 ms->flags &= MAGIC_MIME_TYPE; in mkdbname()
3664 file_pstring_length_size(struct magic_set *ms, const struct magic *m) in file_pstring_length_size() argument
3676 file_error(ms, 0, "corrupt magic file " in file_pstring_length_size()
3683 file_pstring_get_length(struct magic_set *ms, const struct magic *m, in file_pstring_get_length() argument
3719 file_error(ms, 0, "corrupt magic file " in file_pstring_get_length()
3726 size_t l = file_pstring_length_size(ms, m); in file_pstring_get_length()
3736 file_magicfind(struct magic_set *ms, const char *name, struct mlist *v) in file_magicfind() argument
3741 mlist = ms->mlist[1]; in file_magicfind()