magic filename testing improved

This commit is contained in:
Michiel Broek 2002-04-18 20:32:57 +00:00
parent ed55db1d62
commit 8876336125
2 changed files with 59 additions and 63 deletions

View File

@ -4717,6 +4717,7 @@ v0.33.20 10-Feb-2002
that has a header line starting with X-MS-, the headerline is that has a header line starting with X-MS-, the headerline is
supressed because there is no key for this header. This looks supressed because there is no key for this header. This looks
like a new kind of M$ standard. mbnews crashed on this one. like a new kind of M$ standard. mbnews crashed on this one.
Fixed a small problem in magic filename testing.
mbfile: mbfile:
The mbfile index command now creates the html pages using the The mbfile index command now creates the html pages using the

View File

@ -100,82 +100,77 @@ char *Magic_Macro(int C)
int GetMagicRec(int Typ, int First) int GetMagicRec(int Typ, int First)
{ {
int Eof = FALSE, DoMagic = TRUE; int Eof = FALSE, DoMagic = TRUE;
int i; int i;
char *temp; char *temp;
FILE *FeM; FILE *FeM;
if (First) if (First)
MagicNr = 0; MagicNr = 0;
temp = calloc(PATH_MAX, sizeof(char)); temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "%s/etc/magic.data", getenv("MBSE_ROOT")); sprintf(temp, "%s/etc/magic.data", getenv("MBSE_ROOT"));
if ((FeM = fopen(temp, "r")) == NULL) { if ((FeM = fopen(temp, "r")) == NULL) {
Syslog('+', "Huh? No magic file? (%s)", temp); Syslog('+', "Huh? No magic file? (%s)", temp);
free(temp); free(temp);
return FALSE; return FALSE;
}
fread(&magichdr, sizeof(magichdr), 1, FeM);
do {
if (fseek(FeM, magichdr.hdrsize + (MagicNr * magichdr.recsize), SEEK_SET) != 0) {
WriteError("$Can't seek record %ld in %s", MagicNr, temp);
free(temp);
fclose(FeM);
return FALSE;
} }
fread(&magichdr, sizeof(magichdr), 1, FeM); MagicNr++;
do { if (fread(&magic, magichdr.recsize, 1, FeM) == 1) {
if (fseek(FeM, magichdr.hdrsize + (MagicNr * magichdr.recsize), SEEK_SET) != 0) {
WriteError("$Can't seek record %ld in %s", MagicNr, temp);
free(temp);
fclose(FeM);
return FALSE;
}
MagicNr++; if ((magic.Active) && (magic.Attrib == Typ) && (strcasecmp(magic.From, TIC.TicIn.Area) == 0)) {
if (fread(&magic, magichdr.recsize, 1, FeM) == 1) { /*
* Comparing of the filename must be done in
* two parts, before and after the dot.
*/
if (strlen(magic.Mask) == strlen(TIC.NewName)) {
for (i = 0; i < strlen(magic.Mask); i++) {
switch (magic.Mask[i]) {
case '?': break;
case '@': if (!isalpha(TIC.NewName[i]))
DoMagic = FALSE;
break;
case '#': if (!isdigit(TIC.NewName[i]))
DoMagic = FALSE;
break;
if ((magic.Active) && (magic.Attrib == Typ) && default: if (toupper(TIC.NewName[i]) != toupper(magic.Mask[i]))
(strcmp(magic.From, TIC.TicIn.Area) == 0)) { DoMagic = FALSE;
/*
* Comparing of the filename must be done in
* two parts, before and after the dot.
*/
if (strlen(magic.Mask) == strlen(TIC.NewName)) {
for (i = 0; i < strlen(magic.Mask); i++) {
switch (magic.Mask[i]) {
case '?':
break;
case '@':
if ((TIC.NewName[i] < 'a') || (TIC.NewName[i] > 'z'))
DoMagic = FALSE;
break;
case '#':
if ((TIC.NewName[i] < '0') || (TIC.NewName[i] > '9'))
DoMagic = FALSE;
break;
default:
if (TIC.NewName[i] != magic.Mask[i])
DoMagic = FALSE;
}
}
}
if (DoMagic) {
fclose(FeM);
free(temp);
return TRUE;
}
} }
}
} else { } else {
Eof = TRUE; DoMagic = FALSE;
} }
} while (!Eof); if (DoMagic) {
fclose(FeM);
free(temp);
return TRUE;
}
}
free(temp); } else {
fclose(FeM); Eof = TRUE;
return FALSE; }
} while (!Eof);
free(temp);
fclose(FeM);
return FALSE;
} }