file 4.04

fixes, patches and more magic
This commit is contained in:
pooka 2003-09-25 17:58:02 +00:00
parent 2365b48b5e
commit 61a359ca7d
30 changed files with 408 additions and 145 deletions

25
dist/file/ChangeLog vendored
View File

@ -1,3 +1,28 @@
2003-09-12 15:09 Christos Zoulas <christos@zoulas.com>
* update magic files.
* remove largefile support from file.h; it breaks things on most OS's
2003-08-10 10:25 Christos Zoulas <christos@zoulas.com>
* fix unmapping'ing of mmaped files.
2003-07-10 12:03 Christos Zoulas <christos@zoulas.com>
* don't exit with -1 on error; always exit 1 (Marty Leisner)
* restore utimes code.
2003-06-10 17:03 Christos Zoulas <christos@zoulas.com>
* make sure we don't access uninitialized memory.
* pass lint
* #ifdef __cplusplus in magic.h
2003-05-25 19:23 Christos Zoulas <christos@zoulas.com>
* rename cvs magic file to revision to deal with
case insensitive filesystems.
2003-05-23 17:03 Christos Zoulas <christos@zoulas.com>
* documentation fixes from Michael Piefel <piefel@debian.org>

View File

@ -1,4 +1,4 @@
.\" $NetBSD: libmagic.3,v 1.1.1.2 2003/05/25 21:27:29 pooka Exp $
.\" $NetBSD: libmagic.3,v 1.1.1.3 2003/09/25 17:58:56 pooka Exp $
.\"
.\"
.\" Copyright (c) Christos Zoulas 2003.
@ -56,7 +56,7 @@
.Fn magic_file "magic_t cookie, const char *filename"
.Ft const char *
.Fn magic_buffer "magic_t cookie, const void *buffer, size_t length"
.Ft void
.Ft int
.Fn magic_setflags "magic_t cookie, int flags"
.Ft int
.Fn magic_check "magic_t cookie, const char *filename"
@ -95,6 +95,12 @@ Return a mime string, instead of a textual description.
Return all matches, not just the first.
.It Dv MAGIC_CHECK
Check the magic database for consistency and print warnings to stderr.
.It Dv MAGIC_PRESERVE_ATIME
On systems that support
.Xr utime 2
or
.Xr utimes 2 ,
attempt to preserve the access time of files analyzed.
.El
.Pp
The
@ -160,7 +166,8 @@ before any magic queries can performed.
The function
.Fn magic_open
returns a magic cookie on success and NULL on failure setting errno to
an appropriate value.
an appropriate value. It will set errno to EINVAL if an unsupported
value for flags was given.
The
.Fn magic_load ,
.Fn magic_compile ,
@ -175,6 +182,15 @@ functions return a string on success and NULL on failure. The
.Fn magic_error
function returns a textual description of the errors of the above
functions, or NULL if there was no error.
Finally,
.Fn magic_setflags
returns -1 on systems that don't support
.Xr utime 2 ,
or
.Xr utimes 2
when
.Dv MAGIC_PRESERVE_ATIME
is set.
.Sh FILES
.Bl -tag -width /usr/share/misc/magic.mime.mgc -compact
.It Pa /usr/share/misc/magic.mime

View File

@ -38,12 +38,14 @@ Magdir/archive \
Magdir/asterix \
Magdir/att3b \
Magdir/audio \
Magdir/audio.orig \
Magdir/bFLT \
Magdir/blender \
Magdir/blit \
Magdir/bout \
Magdir/bsdi \
Magdir/c-lang \
Magdir/c64 \
Magdir/cddb \
Magdir/chi \
Magdir/chord \
@ -57,7 +59,6 @@ Magdir/compress \
Magdir/console \
Magdir/convex \
Magdir/ctags \
Magdir/cvs \
Magdir/database \
Magdir/diamond \
Magdir/diff \
@ -77,6 +78,7 @@ Magdir/frame \
Magdir/freebsd \
Magdir/fsav \
Magdir/games \
Magdir/gcc \
Magdir/gimp \
Magdir/gnu \
Magdir/grace \
@ -103,6 +105,7 @@ Magdir/linux \
Magdir/lisp \
Magdir/mach \
Magdir/macintosh \
Magdir/macintosh.orig \
Magdir/magic \
Magdir/mail.news \
Magdir/maple \
@ -146,6 +149,7 @@ Magdir/psdbms \
Magdir/pulsar \
Magdir/pyramid \
Magdir/python \
Magdir/revision \
Magdir/riff \
Magdir/rpm \
Magdir/rtf \
@ -153,6 +157,7 @@ Magdir/sc \
Magdir/sccs \
Magdir/sendmail \
Magdir/sequent \
Magdir/sgi \
Magdir/sgml \
Magdir/sharc \
Magdir/sinclair \
@ -176,15 +181,18 @@ Magdir/typeset \
Magdir/unknown \
Magdir/uuencode \
Magdir/varied.out \
Magdir/varied.script \
Magdir/vax \
Magdir/vicar \
Magdir/visx \
Magdir/vms \
Magdir/vmware \
Magdir/vorbis \
Magdir/vorbis.orig \
Magdir/vxl \
Magdir/wordprocessors \
Magdir/xdelta \
Magdir/xenix \
Magdir/xwindows \
Magdir/zilog \
Magdir/zyxel

View File

@ -262,16 +262,44 @@
# Felix von Leitner <felix-file@fefe.de>
0 string d8:announce BitTorrent file
# ACE archive (Nikolay Petrov, nik@techlab.office1.bg)
7 string **ACE** Winace archive data
# Atari MSA archive - Teemu Hukkanen <tjhukkan@iki.fi>
0 beshort 0x0e0f Atari MSA archive data
>2 beshort x \b, %d sectors per track
>4 beshort 0 \b, 1 sided
>4 beshort 1 \b, 2 sided
>6 beshort x \b, starting track: %d
>8 beshort x \b, ending track: %d
>2 beshort x \b, %d sectors per track
>4 beshort 0 \b, 1 sided
>4 beshort 1 \b, 2 sided
>6 beshort x \b, starting track: %d
>8 beshort x \b, ending track: %d
# Alternate ZIP string (amc@arwen.cs.berkeley.edu)
0 string PK00PK\003\004 Zip archive data
0 string PK00PK\003\004 Zip archive data
# ACE archive (from http://www.wotsit.org/download.asp?f=ace)
# by Stefan `Sec` Zehl <sec@42.org>
7 string **ACE** ACE compressed archive
>15 byte >0 version %d
>16 byte =0x00 \b, from MS-DOS
>16 byte =0x01 \b, from OS/2
>16 byte =0x02 \b, from Win/32
>16 byte =0x03 \b, from Unix
>16 byte =0x04 \b, from MacOS
>16 byte =0x05 \b, from WinNT
>16 byte =0x06 \b, from Primos
>16 byte =0x07 \b, from AppleGS
>16 byte =0x08 \b, from Atari
>16 byte =0x09 \b, from Vax/VMS
>16 byte =0x0A \b, from Amiga
>16 byte =0x0B \b, from Next
>14 byte x \b, version %d to extract
>5 leshort &0x0080 \b, multiple volumes,
>>17 byte x \b (part %d),
>5 leshort &0x0002 \b, contains comment
>5 leshort &0x0200 \b, sfx
>5 leshort &0x0400 \b, small dictionary
>5 leshort &0x0800 \b, multi-volume
>5 leshort &0x1000 \b, contains AV-String
>>30 string\x16*UNREGISTERED\x20VERSION* (unregistered)
>5 leshort &0x2000 \b, with recovery record
>5 leshort &0x4000 \b, locked
>5 leshort &0x8000 \b, solid
# Date in MS-DOS format (whatever that is)
#>18 lelong x Created on

27
dist/file/magic/magdir/c64 vendored Normal file
View File

@ -0,0 +1,27 @@
#------------------------------------------------------------------------------
# c64: file(1) magic for various commodore 64 related files
#
# From <doj@cubic.org>
0x16500 belong 0x12014100 D64 Image
0x16500 belong 0x12014180 D71 Image
0x61800 belong 0x28034400 D81 Image
0 string C64\40CARTRIDGE CCS C64 Emultar Cartridge Image
0 belong 0x43154164 X64 Image
0 string GCR-1541 GCR Image
>8 byte x version: $i
>9 byte x tracks: %i
9 string PSUR ARC archive (c64)
2 string -LH1- LHA archive (c64)
0 string C64File PC64 Emulator file
>8 string >\0 "%s"
0 string C64Image PC64 Freezer Image
0 beshort 0x38CD C64 PCLink Image
0 string CBM\144\0\0 Power 64 C64 Emulator Snapshot
0 belong 0xFF424CFF WRAptor packer (c64)

View File

@ -42,17 +42,6 @@
0 string #!\ /usr/bin/env a
>16 string >\0 %s script text executable
# generic shell magic
0 string #!\ / a
>3 string >\0 %s script text executable
0 string #!\ / a
>3 string >\0 %s script text executable
0 string #!/ a
>2 string >\0 %s script text executable
0 string #!\ script text executable
>3 string >\0 for %s
# PHP scripts
# Ulf Harnhammar <ulfh@update.uu.se>
0 string/c =<?php PHP script text

View File

@ -46,10 +46,8 @@
>2 belong >1 \b, %d characters originally
>2 belong =1 \b, %d character originally
#
# This magic number is byte-order-independent. XXX - Does that mean this
# is big-endian, little-endian, either, or that you can't tell?
# this short is valid for SunOS
0 short 017437 old packed data
# This magic number is byte-order-independent.
0 short 0x1f1f old packed data
# XXX - why *two* entries for "compacted data", one of which is
# byte-order independent, and one of which is byte-order dependent?

View File

@ -55,3 +55,7 @@
0 string \007\001\001\000Copyright\ (c)\ 199 Adobe Multiple Master font
0 string \012\001\001\000Copyright\ (c)\ 199 Adobe Multiple Master font
# Opentype font data from Avi Bercovich
0 string OTTO OpenType font data

16
dist/file/magic/magdir/gcc vendored Normal file
View File

@ -0,0 +1,16 @@
#------------------------------------------------------------------------------
# gcc: file(1) magic for GCC special files
#
0 string gpch GCC precompiled header
# The version field is annoying. It's 3 characters, not zero-terminated.
>5 byte x (version %c
>6 byte x \b%c
>7 byte x \b%c)
# 67 = 'C', 111 = 'o', 43 = '+', 79 = 'O'
>4 byte 67 for C
>4 byte 111 for Objective C
>4 byte 43 for C++
>4 byte 79 for Objective C++

View File

@ -12,7 +12,10 @@
>12 belong 3 shared library
>12 belong 4 core
>12 belong 5 preload executable
>12 belong >5
>12 belong 6 dynamically linked shared library
>12 belong 7 dynamic linker
>12 belong 8 bundle
>12 belong >8
>>12 belong x filetype=%ld
>4 belong <0
>>4 belong x architecture=%ld
@ -38,6 +41,6 @@
>4 belong 15 i860-big
>4 belong 16 i860
>4 belong 17 rs6000
>4 belong 18 powerPC
>4 belong 18 ppc
>4 belong >18
>>4 belong x architecture=%ld

View File

@ -247,6 +247,7 @@
# Macintosh filesystem data
# From "Tom N Harris" <telliamed@mac.com>
# Fixed HFS+ and Partition map magic: Ethan Benson <erbenson@alaska.net>
# The MacOS epoch begins on 1 Jan 1904 instead of 1 Jan 1970, so these
# entries depend on the data arithmetic added after v.35
# There's also some Pascal strings in here, ditto...
@ -270,35 +271,34 @@
>0 beshort 0x4C4B (bootable)
>0x40a beshort &0x8000 (locked)
>0x40a beshort ^0x0100 (mounted)
>0x40a beshort &0x0200 (spared blocks)
>0x40a beshort &0x0800 (unclean)
>0x47C beshort 0x482B (Embedded HFS+ Volume)
>0x402 beldate-0x7C25B080 x created: %s,
>0x406 beldate-0x7C25B080 x last modified: %s,
>0x440 beldate-0x7C25B080 >0 last backup: %s,
>0x414 belong x block size: %d,
>0x412 beshort x number of blocks: %d,
>0x424 pstring x volume name: %s
#>0x480 beshort =0x482B Embedded HFS+ Volume:
#>>((0x482*(0x414))+(0x41c*512)) x \b
# Well, this is (theoretically) how we could do this. But it occurs to
# me that we likely don't read in a large enough chunk. I don't have any
# HFS+ volumes to see what a typical offset would be.
0x400 beshort 0x482B Macintosh HFS Extended
>&2 beshort x version %d data
>&0 beshort x version %d data
>0 beshort 0x4C4B (bootable)
>&4 belong ^0x00000100 (mounted)
>&4 belong &0x00000800 (unclean)
>&4 belong &0x00008000 (locked)
>&8 string x last mounted by: '%.4s',
>0x404 belong ^0x00000100 (mounted)
>&2 belong &0x00000200 (spared blocks)
>&2 belong &0x00000800 (unclean)
>&2 belong &0x00008000 (locked)
>&6 string x last mounted by: '%.4s',
# really, that should be treated as a belong and we print a string
# based on the value. TN1150 only mentions '8.10' for "MacOS 8.1"
>&16 beldate-0x7C25B080 x created: %s,
>&20 beldate-0x7C25B080 x last modified: %s,
>&24 beldate-0x7C25B080 >0 last backup: %s,
>&28 beldate-0x7C25B080 >0 last checked: %s,
>&40 belong x block size: %d,
>&44 belong x number of blocks: %d,
>&48 belong x free blocks: %d
>&14 beldate-0x7C25B080 x created: %s,
# only the creation date is local time, all other timestamps in HFS+ are UTC.
>&18 bedate-0x7C25B080 x last modified: %s,
>&22 bedate-0x7C25B080 >0 last backup: %s,
>&26 bedate-0x7C25B080 >0 last checked: %s,
>&38 belong x block size: %d,
>&42 belong x number of blocks: %d,
>&46 belong x free blocks: %d
# I don't think this is really necessary since it doesn't do much and
# anything with a valid driver descriptor will also have a valid
@ -311,29 +311,37 @@
# cstring. Of course, partitions can contain more than four entries, but
# what're you gonna do?
0x200 beshort 0x504D Apple Partition data
>&2 beshort x block size: %d
>&48 string x first type: %s,
>&12 belong x number of blocks: %d,
>(&0x2.S) beshort 0x504D
>>&48 string x second type: %s
>>&12 belong x number of blocks: %d,
>>(&0x2.S) beshort 0x504D
>>>&48 string x third type: %s
>>>&12 belong x number of blocks: %d,
>>>(&0x2.S) beshort 0x504D
>>>>&48 string x fourth type: %s
>>>>&12 belong x number of blocks: %d,
>0x2 beshort x block size: %d,
>0x230 string x first type: %s,
>0x210 string x name: %s,
>0x254 belong x number of blocks: %d,
>0x400 beshort 0x504D
>>0x430 string x second type: %s,
>>0x410 string x name: %s,
>>0x454 belong x number of blocks: %d,
>>0x800 beshort 0x504D
>>>0x830 string x third type: %s,
>>>0x810 string x name: %s,
>>>0x854 belong x number of blocks: %d,
>>>0xa00 beshort 0x504D
>>>>0xa30 string x fourth type: %s,
>>>>0xa10 string x name: %s,
>>>>0xa54 belong x number of blocks: %d
# AFAIK, only the signature is different
0x200 beshort 0x5453 Apple Old Partition data
>&2 beshort x block size: %d
>&48 string x first type: %s,
>&12 belong x number of blocks: %d,
>(&0x2.S) beshort 0x504D
>>&48 string x second type: %s
>>&12 belong x number of blocks: %d,
>>(&0x2.S) beshort 0x504D
>>>&48 string x third type: %s
>>>&12 belong x number of blocks: %d,
>>>(&0x2.S) beshort 0x504D
>>>>&48 string x fourth type: %s
>>>>&12 belong x number of blocks: %d,
>0x2 beshort x block size: %d,
>0x230 string x first type: %s,
>0x210 string x name: %s,
>0x254 belong x number of blocks: %d,
>0x400 beshort 0x504D
>>0x430 string x second type: %s,
>>0x410 string x name: %s,
>>0x454 belong x number of blocks: %d,
>>0x800 beshort 0x504D
>>>0x830 string x third type: %s,
>>>0x810 string x name: %s,
>>>0x854 belong x number of blocks: %d,
>>>0xa00 beshort 0x504D
>>>>0xa30 string x fourth type: %s,
>>>>0xa10 string x name: %s,
>>>>0xa54 belong x number of blocks: %d

View File

@ -56,7 +56,7 @@
0 string (*********************** Mathematica 3.0 notebook
# other (* matches it is a comment start in these langs
0 string (* Mathematica, or Pascal, Modula-2 or 3 code
0 string (* Mathematica, or Pascal, Modula-2 or 3 code text
#########################
# MatLab v5

View File

@ -264,9 +264,9 @@
# Acroread or something files wrongly identified as G3 .pfm
# these have the form \000 \001 any? \002 \000 \000
# or \000 \001 any? \022 \000 \000
0 string \000\001 pfm?
>3 string \022\000\000Copyright\ yes
>3 string \002\000\000Copyright\ yes
#0 string \000\001 pfm?
#>3 string \022\000\000Copyright\ yes
#>3 string \002\000\000Copyright\ yes
#>3 string >\0 oops, not a font file. Cancel that.
#it clashes with ttf files so put it lower down.

View File

@ -110,3 +110,7 @@
# This would otherwise be recognized as PostScript - nick@debian.org
0 string %!VMF SunClock's Vector Map Format data
#------------------------------------------------------------------------------
# HP LaserJet 1000 series downloadable firmware file
0 string \xbe\xefABCDEFGH HP LaserJet 1000 series downloadable firmware

5
dist/file/magic/magdir/revision vendored Normal file
View File

@ -0,0 +1,5 @@
#------------------------------------------------------------------------------
# file(1) magic for revision control files
# From Hendrik Scholz <hendrik@scholz.net>
0 string /1\ :pserver: cvs password text file

59
dist/file/magic/magdir/sgi vendored Normal file
View File

@ -0,0 +1,59 @@
#------------------------------------------------------------------------------
# sgi: file(1) magic for Silicon Graphics applications
#
#
# Performance Co-Pilot file types
0 string PmNs PCP compiled namespace (V.0)
0 string PmN PCP compiled namespace
>3 addr x (V.%1.1s)
3 long 0x84500526 PCP archive
>7 byte x (V.%d)
>20 long -2 temporal index
>20 long -1 metadata
>20 long 0 log volume #0
>20 long >0 log volume #%ld
>24 addr x host: %s
0 string PCPFolio PCP
>9 string Version: Archive Folio
>18 addr x (V.%s)
0 string #pmchart PCP pmchart view
>9 string Version
>17 addr x (V%-3.3s)
0 string pmview PCP pmview config
>7 string Version
>15 addr x (V%-3.3s)
0 string #pmlogger PCP pmlogger config
>10 string Version
>18 addr x (V%1.1s)
0 string PcPh PCP Help
>4 string 1 Index
>4 string 2 Text
>5 addr x (V.%1.1s)
0 string #pmieconf-rules PCP pmieconf rules
>16 addr x (V.%1.1s)
3 string pmieconf-pmie PCP pmie config
>17 addr x (V.%1.1s)
# SpeedShop data files
0 long 0x13130303 SpeedShop data file
# mdbm files
0 long 0x01023962 mdbm file, version 0 (obsolete)
0 string mdbm mdbm file,
>5 byte x version %d,
>6 byte x 2^%d pages,
>7 byte x pagesize 2^%d,
>17 byte x hash %d,
>11 byte x dataformat %d
# Alias|Wavefront Maya files
0 string //Maya ASCII Alias|Wavefront Maya Ascii File,
>13 addr x version %s
8 string MAYAFOR4 Alias|Wavefront Maya Binary File,
>32 addr x version %s scene
8 string MayaFOR4 Alias|Wavefront Maya Binary File,
>32 addr x version %s scene
8 string CIMG Alias|Wavefront Maya Image File
8 string DEEP Alias|Wavefront Maya Image File

View File

@ -101,7 +101,8 @@
>12 belong 7 (IBM channel-to-channel adapter)
>12 belong 8 (FDDI)
>12 belong 9 (Unknown)
# Microsoft ICM color profile
36 string acspMSFT Microsoft ICM Color Profile
# Sun KCMS
36 string acsp Kodak Color Management System, ICC Profile

View File

@ -28,5 +28,8 @@
>4 long x - version %ld
# From: Dave Pearson <davep@davep.org>
# Harbour <URL:http://www.harbour-project.org/> HRB files.
0 string \xc0HRB Harbour HRB file
>4 short x version %d
0 string \xc0HRB Harbour HRB file
>4 short x version %d
# From: "Stefan A. Haubenthal" <polluks@web.de>
0 belong 0x000001EB Plan 9 executable

12
dist/file/magic/magdir/varied.script vendored Normal file
View File

@ -0,0 +1,12 @@
#------------------------------------------------------------------------------
# varied.script: file(1) magic for various interpreter scripts
0 string #!\ / a
>3 string >\0 %s script text executable
0 string #!\ / a
>3 string >\0 %s script text executable
0 string #!/ a
>2 string >\0 %s script text executable
0 string #!\ script text executable
>3 string >\0 for %s

View File

@ -19,6 +19,9 @@
##>>14 lelong x (Serial %lX)
# --- First vorbis packet - general header ---
>>28 string \x01vorbis \b, Vorbis audio,
# non-Vorbis content: FLAC (Free Loss-lessy Audio Codec,
# http://flac.sourceforge.net)
>>28 string fLaC \b, FLAC audio
>>>35 lelong !0 UNKNOWN VERSION %lu,
##>>>35 lelong 0 version 0,
>>>35 lelong 0
@ -29,19 +32,19 @@
# Minimal, nominal and maximal bitrates specified when encoding
>>>>48 string <\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \b,
# The above tests if at least one of these is specified:
>>>>>44 lelong !-1
>>>>>52 lelong !-1
# Vorbis RC2 has a bug which puts -1000 in the min/max bitrate fields
# instead of -1.
# Vorbis 1.0 uses 0 instead of -1.
>>>>>>44 lelong !-1000
>>>>>>>44 lelong !0
>>>>>>>>44 lelong x >%lu
>>>>>48 lelong !-1
>>>>>>48 lelong x ~%lu
>>>>>52 lelong !-1
>>>>>>52 lelong !0
>>>>>>>52 lelong !-1000
>>>>>>>>52 lelong x <%lu
>>>>>48 lelong !-1
>>>>>>48 lelong x ~%lu
>>>>>44 lelong !-1
>>>>>>44 lelong !-1000
>>>>>>>44 lelong !0
>>>>>>>>44 lelong x >%lu
>>>>>48 string <\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff bps
# -- Second vorbis header packet - the comments
# A kludge to read the vendor string. It's a counted string, not a

25
dist/file/magic/magdir/xwindows vendored Normal file
View File

@ -0,0 +1,25 @@
#------------------------------------------------------------------------------
# xwindows: file(1) magic for various X/Window system file formats.
# Compiled X Keymap
# XKM (compiled X keymap) files (including version and byte ordering)
1 string mkx Compiled XKB Keymap: lsb,
>0 byte >0 version %d
>0 byte =0 obsolete
0 string xkm Compiled XKB Keymap: msb,
>3 byte >0 version %d
>0 byte =0 obsolete
# xfsdump archive
0 string xFSdump0 xfsdump archive
>8 long x (version %d)
# Jaleo XFS files
0 long 395726 Jaleo XFS file
>4 long x - version %ld
>8 long x - [%ld -
>20 long x %ldx
>24 long x %ldx
>28 long 1008 YUV422]
>28 long 1000 RGB24]

View File

@ -100,7 +100,7 @@
#MP3 with ID3 tag
0 string ID3 audio/mpeg
# Ogg/Vorbis
0 string OggS audio/x-ogg
0 string OggS application/ogg
#------------------------------------------------------------------------------
# c-lang: file(1) magic for C programs or various scripts

View File

@ -1,4 +1,4 @@
/* $NetBSD: apprentice.c,v 1.1.1.2 2003/05/25 21:27:34 pooka Exp $ */
/* $NetBSD: apprentice.c,v 1.1.1.3 2003/09/25 17:59:00 pooka Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -53,9 +53,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)Id: apprentice.c,v 1.58 2003/05/23 21:31:58 christos Exp")
FILE_RCSID("@(#)Id: apprentice.c,v 1.64 2003/09/12 19:39:44 christos Exp")
#else
__RCSID("$NetBSD: apprentice.c,v 1.1.1.2 2003/05/25 21:27:34 pooka Exp $");
__RCSID("$NetBSD: apprentice.c,v 1.1.1.3 2003/09/25 17:59:00 pooka Exp $");
#endif
#endif /* lint */
@ -107,6 +107,7 @@ private int apprentice_compile(struct magic_set *, struct magic **, uint32_t *,
const char *);
private size_t maxmagic = 0;
private size_t magicsize = sizeof(struct magic);
#ifdef COMPILE_ONLY
const char *magicfile;
@ -131,7 +132,7 @@ main(int argc, char *argv[])
}
magicfile = argv[1];
exit(apprentice(magicfile, COMPILE, MAGIC_CHECK));
exit(file_apprentice(magicfile, COMPILE, MAGIC_CHECK) == -1 ? 1 : 0);
}
#endif /* COMPILE_ONLY */
@ -149,7 +150,7 @@ apprentice_1(struct magic_set *ms, const char *fn, int action,
int rv = -1;
int mapped;
if (sizeof(*magic) != FILE_MAGICSIZE) {
if (magicsize != FILE_MAGICSIZE) {
file_error(ms, "Magic element size %lu != %lu",
(unsigned long)sizeof(*magic),
(unsigned long)FILE_MAGICSIZE);
@ -268,10 +269,11 @@ apprentice_file(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
return -1;
}
/* parse it */
if (action == FILE_CHECK) /* print silly verbose header for USG compat. */
(void) printf("%s\n", hdr);
/* print silly verbose header for USG compat. */
if (action == FILE_CHECK)
(void)fprintf(stderr, "%s\n", hdr);
/* parse it */
for (lineno = 1; fgets(line, BUFSIZ, f) != NULL; lineno++) {
if (line[0]=='#') /* comment, do not parse */
continue;
@ -687,8 +689,12 @@ getvalue(struct magic_set *ms, struct magic *m, char **p)
case FILE_PSTRING:
case FILE_REGEX:
*p = getstr(ms, *p, m->value.s, sizeof(m->value.s), &slen);
if (*p == NULL)
if (*p == NULL) {
if (ms->flags & MAGIC_CHECK)
file_magwarn("Cannot get string from `%s'",
m->value.s);
return -1;
}
m->vallen = slen;
return 0;
default:
@ -938,6 +944,7 @@ apprentice_map(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
file_error(ms, "Cannot map `%s' (%s)", dbname, strerror(errno));
goto error;
}
#define RET 2
#else
if ((mm = malloc((size_t)st.st_size)) == NULL) {
file_oomem(ms);
@ -947,6 +954,7 @@ apprentice_map(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
file_error(ms, "Read failed (%s)", strerror(errno));
goto error;
}
#define RET 1
#endif
*magicp = mm;
(void)close(fd);
@ -973,7 +981,7 @@ apprentice_map(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
(*magicp)++;
if (needsbyteswap)
byteswap(*magicp, *nmagicp);
return 0;
return RET;
error:
if (fd != -1)

View File

@ -1,4 +1,4 @@
/* $NetBSD: apptype.c,v 1.1.1.1 2003/03/25 22:30:16 pooka Exp $ */
/* $NetBSD: apptype.c,v 1.1.1.2 2003/09/25 17:59:00 pooka Exp $ */
/*
* Adapted from: apptype.c, Written by Eberhard Mattes and put into the
@ -26,10 +26,21 @@
*
*/
#ifdef __EMX__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "file.h"
#ifndef lint
#if 0
FILE_RCSID("@(#)Id: apptype.c,v 1.3 2003/06/10 18:28:37 christos Exp")
#else
__RCSID("$NetBSD: apptype.c,v 1.1.1.2 2003/09/25 17:59:00 pooka Exp $");
#endif
#endif /* lint */
#ifdef __EMX__
#include <io.h>
#define INCL_DOSSESMGR
#define INCL_DOSERRORS
@ -37,16 +48,6 @@
#include <os2.h>
typedef ULONG APPTYPE;
#include "file.h"
#ifndef lint
#if 0
FILE_RCSID("@(#)Id: apptype.c,v 1.2 2003/03/24 14:53:31 christos Exp")
#else
__RCSID("$NetBSD: apptype.c,v 1.1.1.1 2003/03/25 22:30:16 pooka Exp $");
#endif
#endif /* lint */
protected int
file_os2_apptype(struct magic_set *ms, const char *fn, const void *buf,
size_t nb)

25
dist/file/src/file.c vendored
View File

@ -1,4 +1,4 @@
/* $NetBSD: file.c,v 1.1.1.2 2003/05/25 21:27:42 pooka Exp $ */
/* $NetBSD: file.c,v 1.1.1.3 2003/09/25 17:59:03 pooka Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -75,9 +75,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)Id: file.c,v 1.77 2003/03/27 22:46:51 christos Exp")
FILE_RCSID("@(#)Id: file.c,v 1.81 2003/09/12 19:39:44 christos Exp")
#else
__RCSID("$NetBSD: file.c,v 1.1.1.2 2003/05/25 21:27:42 pooka Exp $");
__RCSID("$NetBSD: file.c,v 1.1.1.3 2003/09/25 17:59:03 pooka Exp $");
#endif
#endif /* lint */
@ -102,7 +102,8 @@ private int /* Global command-line options */
bflag = 0, /* brief output format */
nopad = 0, /* Don't pad output */
nobuffer = 0, /* Do not buffer stdout */
kflag = 0; /* Keep going after the first match */
kflag = 0, /* Keep going after the first match */
rflag = 0; /* Restore access times of files */
private const char *magicfile = 0; /* where the magic is */
private const char *default_magicfile = MAGIC;
@ -138,7 +139,7 @@ main(int argc, char *argv[])
int flags = 0;
char *mime, *home, *usermagic;
struct stat sb;
#define OPTSTRING "bcdf:F:ikm:nNsvzCL"
#define OPTSTRING "bcCdf:F:ikLm:nNpsvz"
#ifdef HAVE_GETOPT_LONG
int longindex;
private struct option long_options[] =
@ -156,6 +157,9 @@ main(int argc, char *argv[])
{"dereference", 0, 0, 'L'},
#endif
{"magic-file", 1, 0, 'm'},
#if defined(HAVE_UTIME) || defined(HAVE_UTIMES)
{"preserve-date", 0, 0, 'p'},
#endif
{"uncompress", 0, 0, 'z'},
{"no-buffer", 0, 0, 'n'},
{"no-pad", 0, 0, 'N'},
@ -217,7 +221,7 @@ main(int argc, char *argv[])
action = FILE_COMPILE;
break;
case 'd':
flags |= MAGIC_DEBUG;
flags |= MAGIC_DEBUG|MAGIC_CHECK;
break;
case 'f':
if(action)
@ -249,6 +253,11 @@ main(int argc, char *argv[])
case 'N':
++nopad;
break;
#if defined(HAVE_UTIME) || defined(HAVE_UTIMES)
case 'p':
flags |= MAGIC_PRESERVE_ATIME;
break;
#endif
case 's':
flags |= MAGIC_DEVICES;
break;
@ -285,8 +294,9 @@ main(int argc, char *argv[])
strerror(errno));
return 1;
}
return action == FILE_CHECK ? magic_check(magic, magicfile) :
c = action == FILE_CHECK ? magic_check(magic, magicfile) :
magic_compile(magic, magicfile);
return c == -1 ? 1 : 0;
default:
load(magicfile, flags);
break;
@ -475,6 +485,7 @@ help(void)
" -L, --dereference causes symlinks to be followed\n"
" -n, --no-buffer do not buffer output\n"
" -N, --no-pad do not pad output\n"
" -p, --preserve-date preserve access times on files\n"
" -s, --special-files treat special (block/char devices) files as\n"
" ordinary ones\n"
" --help display this help and exit\n"

View File

@ -1,4 +1,4 @@
/* $NetBSD: funcs.c,v 1.1.1.2 2003/05/25 21:27:43 pooka Exp $ */
/* $NetBSD: funcs.c,v 1.1.1.3 2003/09/25 17:59:04 pooka Exp $ */
/*
* Copyright (c) Christos Zoulas 2003.
@ -78,10 +78,6 @@ file_error(struct magic_set *ms, const char *f, ...)
if (ms->haderr)
return;
va_start(va, f);
/* cuz we use stdout for most, stderr here */
(void) fflush(stdout);
(void) vsnprintf(ms->o.buf, ms->o.size, f, va);
ms->haderr++;
va_end(va);

31
dist/file/src/magic.h vendored
View File

@ -1,4 +1,4 @@
/* $NetBSD: magic.h,v 1.1.1.2 2003/05/25 21:27:43 pooka Exp $ */
/* $NetBSD: magic.h,v 1.1.1.3 2003/09/25 17:59:05 pooka Exp $ */
/*
* Copyright (c) Christos Zoulas 2003.
@ -33,17 +33,22 @@
#include <sys/types.h>
#define MAGIC_NONE 0x00 /* No flags */
#define MAGIC_DEBUG 0x01 /* Turn on debugging */
#define MAGIC_SYMLINK 0x02 /* Follow symlinks */
#define MAGIC_COMPRESS 0x04 /* Check inside compressed files */
#define MAGIC_DEVICES 0x08 /* Look at the contents of devices */
#define MAGIC_MIME 0x10 /* Return a mime string */
#define MAGIC_CONTINUE 0x20 /* Return all matches, not just the first */
#define MAGIC_CHECK 0x40 /* Print warnings to stderr */
#define MAGIC_NONE 0x00 /* No flags */
#define MAGIC_DEBUG 0x01 /* Turn on debugging */
#define MAGIC_SYMLINK 0x02 /* Follow symlinks */
#define MAGIC_COMPRESS 0x04 /* Check inside compressed files */
#define MAGIC_DEVICES 0x08 /* Look at the contents of devices */
#define MAGIC_MIME 0x10 /* Return a mime string */
#define MAGIC_CONTINUE 0x20 /* Return all matches */
#define MAGIC_CHECK 0x40 /* Print warnings to stderr */
#define MAGIC_PRESERVE_ATIME 0x80 /* Restore access time on exit */
#ifdef __cplusplus
extern "C" {
#endif
typedef struct magic_set *magic_t;
magic_t magic_open(int);
void magic_close(magic_t);
@ -51,10 +56,14 @@ const char *magic_file(magic_t, const char *);
const char *magic_buffer(magic_t, const void *, size_t);
const char *magic_error(magic_t);
void magic_setflags(magic_t, int);
int magic_setflags(magic_t, int);
int magic_load(magic_t, const char *);
int magic_compile(magic_t, const char *);
int magic_check(magic_t, const char *);
#ifdef __cplusplus
};
#endif
#endif /* _MAGIC_H */

View File

@ -1,13 +1,16 @@
/* $NetBSD: patchlevel.h,v 1.1.1.2 2003/05/25 21:28:08 pooka Exp $ */
/* $NetBSD: patchlevel.h,v 1.1.1.3 2003/09/25 17:59:06 pooka Exp $ */
#define FILE_VERSION_MAJOR 4
#define patchlevel 3
#define patchlevel 4
/*
* Patchlevel file for Ian Darwin's MAGIC command.
* Id: patchlevel.h,v 1.47 2003/05/23 21:38:21 christos Exp
* Id: patchlevel.h,v 1.48 2003/09/12 19:41:14 christos Exp
*
* Log: patchlevel.h,v
* Revision 1.48 2003/09/12 19:41:14 christos
* this is 4.04
*
* Revision 1.47 2003/05/23 21:38:21 christos
* welcome to 4.03
*

View File

@ -1,4 +1,4 @@
/* $NetBSD: print.c,v 1.1.1.2 2003/05/25 21:28:10 pooka Exp $ */
/* $NetBSD: print.c,v 1.1.1.3 2003/09/25 17:59:06 pooka Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -49,9 +49,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)Id: print.c,v 1.43 2003/03/26 15:35:30 christos Exp")
FILE_RCSID("@(#)Id: print.c,v 1.44 2003/09/12 19:39:44 christos Exp")
#else
__RCSID("$NetBSD: print.c,v 1.1.1.2 2003/05/25 21:28:10 pooka Exp $");
__RCSID("$NetBSD: print.c,v 1.1.1.3 2003/09/25 17:59:06 pooka Exp $");
#endif
#endif /* lint */
@ -156,6 +156,7 @@ file_magwarn(const char *f, ...)
/* cuz we use stdout for most, stderr here */
(void) fflush(stdout);
(void) fprintf(stderr, "WARNING: ");
(void) vfprintf(stderr, f, va);
va_end(va);
fputc('\n', stderr);

View File

@ -1,4 +1,4 @@
/* $NetBSD: softmagic.c,v 1.1.1.2 2003/05/25 21:28:12 pooka Exp $ */
/* $NetBSD: softmagic.c,v 1.1.1.3 2003/09/25 17:59:10 pooka Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
@ -47,9 +47,9 @@
#ifndef lint
#if 0
FILE_RCSID("@(#)Id: softmagic.c,v 1.59 2003/05/23 21:31:59 christos Exp")
FILE_RCSID("@(#)Id: softmagic.c,v 1.60 2003/06/10 18:28:37 christos Exp")
#else
__RCSID("$NetBSD: softmagic.c,v 1.1.1.2 2003/05/25 21:28:12 pooka Exp $");
__RCSID("$NetBSD: softmagic.c,v 1.1.1.3 2003/09/25 17:59:10 pooka Exp $");
#endif
#endif /* lint */
@ -59,9 +59,9 @@ private int mget(struct magic_set *, union VALUETYPE *, const unsigned char *,
struct magic *, size_t);
private int mcheck(struct magic_set *, union VALUETYPE *, struct magic *);
private int32_t mprint(struct magic_set *, union VALUETYPE *, struct magic *);
private void mdebug(int32_t, const char *, size_t);
private void mdebug(uint32_t, const char *, size_t);
private int mconvert(struct magic_set *, union VALUETYPE *, struct magic *);
private int check_mem(struct magic_set *, int);
private int check_mem(struct magic_set *, unsigned int);
/*
* softmagic - lookup one file in database
@ -232,7 +232,7 @@ done:
}
private int
check_mem(struct magic_set *ms, int level)
check_mem(struct magic_set *ms, unsigned int level)
{
size_t len;
@ -600,7 +600,7 @@ mconvert(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
private void
mdebug(int32_t offset, const char *str, size_t len)
mdebug(uint32_t offset, const char *str, size_t len)
{
(void) fprintf(stderr, "mget @%d: ", offset);
file_showstr(stderr, str, len);