Updates for mbfile check and rearc

This commit is contained in:
Michiel Broek 2004-03-09 21:42:29 +00:00
parent 126eb3a84f
commit 66fb5827e8
13 changed files with 240 additions and 66 deletions

View File

@ -27,6 +27,7 @@ v0.51.2 06-Mar-2004
mbcico:
Updated file request function to new files database structure.
Fixed a compile problem on FreeBSD 5.1
mbfido:
When removing files during tic import due to replace or maximum
@ -43,6 +44,8 @@ v0.51.2 06-Mar-2004
Fixed an error in check when a mangled 8.3 filename was changed
and the symbolic link was not adjusted.
Added rearc command.
The check command does now also check if the magic alias file
request names are valid and removes the invalid entries.
mbaff:
When scanning for uploads, files which were hatched now have

8
TODO
View File

@ -135,8 +135,6 @@ mbcico:
N: Make workaround for binkp bug in Irex 2.24 upto 2.29
mbfile:
N: Add a check to see if the magic filenames are (still) valid.
L: Update <filespec> <area> <-touch>
L: Possibility to skip file areas from checking and reindexing.
@ -146,12 +144,6 @@ mbfile:
N: The import function doesn't strip the [0] from the files.bbs
when importing the description.
N: With rearc if a LFN results in a new mangled name, update this.
N: With rearc if a file is a magic file, update the magic entry.
N: After rearc force index.
mbmsg:
N: With the post command if a netmail area is used the netmail area
will cause trouble later, should be blocked to be used on netmail

View File

@ -146,6 +146,7 @@ pktname.o: ../config.h mbselib.h
mangle.o: ../config.h mbselib.h
sectest.o: ../config.h mbselib.h
proglock.o: ../config.h mbselib.h
magic.o: ../config.h mbselib.h
dostran.o: ../config.h mbselib.h
ftnmsg.o: ../config.h mbselib.h
mbfile.o: ../config.h mbselib.h

115
lib/magic.c Normal file
View File

@ -0,0 +1,115 @@
/*****************************************************************************
*
* $Id$
* Purpose ...............: Magic filename handling
*
*****************************************************************************
* Copyright (C) 1997-2004
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
* 1971 BV IJmuiden
* the Netherlands
*
* This file is part of MBSE BBS.
*
* This BBS is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* MBSE BBS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MBSE BBS; see the file COPYING. If not, write to the Free
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*****************************************************************************/
#include "../config.h"
#include "mbselib.h"
/*
* Update magic alias with new filename.
*/
void magic_update(char *Alias, char *FileName)
{
char *path;
FILE *fp;
Syslog('f', "magic_update(%s) with %s", Alias, FileName);
if (!strlen(CFG.req_magic)) {
WriteError("No magic filename path configured");
return;
}
path = xstrcpy(CFG.req_magic);
path = xstrcat(path, (char *)"/");
path = xstrcat(path, Alias);
if ((fp = fopen(path, "w")) == NULL) {
WriteError("$Can't create %s", path);
free(path);
return;
}
fprintf(fp, "%s\n", FileName);
fclose(fp);
chmod(path, 0644);
free(path);
}
/*
* Check if magic filename is valid.
*/
int magic_check(char *Alias, char *FileName)
{
char *path;
FILE *fp;
int rc = -1;
Syslog('f', "magic_check(%s, %s)", Alias, FileName);
if (!strlen(CFG.req_magic)) {
WriteError("No magic filename path configured");
return -1;
}
path = xstrcpy(CFG.req_magic);
path = xstrcat(path, (char *)"/");
path = xstrcat(path, Alias);
if ((fp = fopen(path, "r")) == NULL) {
WriteError("$No magic alias %s", path);
free(path);
return -1;
}
free(path);
path = calloc(PATH_MAX, sizeof(char));
fgets(path, PATH_MAX -1, fp);
fclose(fp);
Striplf(path);
if (strcmp(path, FileName) == 0)
rc = 0;
free(path);
return rc;
}
/*
* Get record for a magic alias in area.
*/
long magic_get(char *Name, long AreaNum)
{
return -1;
}

View File

@ -2441,6 +2441,22 @@ char *re_mask(char *, int); /* Bluid file mask */
/*
* rearc.c
*/
int rearc(char *, char *, int); /* Rearc command */
/*
* magic.c
*/
void magic_update(char *, char *); /* Update magic alias */
int magic_check(char *, char *); /* Check if magic alias exists */
long magic_get(char *, long); /* Get fdb record for magic name */
/************************************************************************
*
* Charset mapping
@ -2481,12 +2497,6 @@ char *charset_alias_rfc(char *); /* Search RFC alias */
int charset_set_in_out(char *, char *); /* Setup mapping */
/*
* rearc.c
*/
int rearc(char *, char *, int); /* Rearc command */
/****************************************************************************
*

View File

@ -1,10 +1,10 @@
#ifndef LUTIL_H
#define LUTIL_H
/* $id$ */
/* $Id$ */
void setmyname(char *);
char *date(long);
char *date(time_t);
int IsZMH(void);
unsigned long rnd(void);

View File

@ -304,7 +304,7 @@ void Magic_Keepnum(void)
void Magic_UpDateAlias(void)
{
if (GetMagicRec(MG_UPDALIAS, TRUE)) {
UpDateAlias(TIC.TicIn.Area);
magic_update(TIC.TicIn.Area, TIC.NewFile);
MagicResult((char *)"Update Alias");
}
}

View File

@ -59,16 +59,17 @@ extern int do_pack; /* Pack filebase */
*/
void Check(void)
{
FILE *pAreas, *pFile;
int i, j, iAreas, iAreasNew = 0, Fix, inArea, iTotal = 0, iErrors = 0;
char *sAreas, *fAreas, *newdir, *temp, *mname, *tname;
DIR *dp;
struct dirent *de;
int Found, Update;
char fn[PATH_MAX];
struct stat stb;
struct passwd *pw;
struct group *gr;
FILE *pAreas, *pFile;
int i, j, iAreas, iAreasNew = 0, Fix, inArea, iTotal = 0, iErrors = 0, rc;
char *sAreas, *fAreas, *newdir, *temp, *mname, *tname;
DIR *dp;
struct dirent *de;
int Found, Update;
char fn[PATH_MAX];
struct stat stb;
struct passwd *pw;
struct group *gr;
struct FILEIndex idx;
sAreas = calloc(PATH_MAX, sizeof(char));
fAreas = calloc(PATH_MAX, sizeof(char));
@ -363,6 +364,17 @@ void Check(void)
fwrite(&fdb, fdbhdr.recsize, 1, pFile);
}
}
if (strlen(fdb.Magic)) {
Syslog('f', "Checking magic %s file %s", fdb.Magic, fdb.Name);
rc = magic_check(fdb.Magic, fdb.Name);
if (rc == -1) {
Syslog('+', "Area %d magic alias %s file %s is invalid", i, fdb.Magic, fdb.Name);
memset(&fdb.Magic, 0, sizeof(fdb.Magic));
fseek(pFile, - fdbhdr.recsize, SEEK_CUR);
fwrite(&fdb, fdbhdr.recsize, 1, pFile);
iErrors++;
}
}
}
if (inArea == 0)
Syslog('+', "Warning: area %d (%s) is empty", i, area.Name);
@ -438,6 +450,55 @@ void Check(void)
}
fclose(pAreas);
if (!do_quiet) {
printf("\rChecking magic alias names ... \r");
fflush(stdout);
}
if (!strlen(CFG.req_magic)) {
WriteError("No magic filename path configured");
} else {
if ((dp = opendir(CFG.req_magic)) == NULL) {
WriteError("$Can't open directory %s", CFG.req_magic);
} else {
while ((de = readdir(dp))) {
if (de->d_name[0] != '.') {
sprintf(temp, "%s/%s", CFG.req_magic, de->d_name);
if (file_exist(temp, X_OK) == 0) {
Syslog('f', "%s is executable", temp);
} else if (file_exist(temp, R_OK) == 0) {
Syslog('f', "%s is magic alias", temp);
if ((pFile = fopen(temp, "r"))) {
fgets(mname, PATH_MAX -1, pFile);
fclose(pFile);
Striplf(mname);
sprintf(newdir, "%s/etc/request.index", getenv("MBSE_ROOT"));
Found = FALSE;
if ((pFile = fopen(newdir, "r"))) {
while (fread(&idx, sizeof(idx), 1, pFile)) {
if ((strcmp(idx.Name, mname) == 0) || (strcmp(idx.LName, mname) == 0)) {
Found = TRUE;
break;
}
}
fclose(pFile);
}
if (!Found) {
Syslog('+', "Error: magic alias %s (%s) is invalid, removed", de->d_name, mname);
iErrors++;
unlink(temp);
}
}
} else {
Syslog('f', "%s cannot be", temp);
}
}
}
closedir(dp);
}
}
if (!do_quiet) {
printf("\r \r");
fflush(stdout);

View File

@ -262,6 +262,13 @@ int main(int argc, char **argv)
if (do_check)
Check();
if (do_rearc) {
ReArc(Area, FileName);
if (do_index)
Index();
die(MBERR_OK);
}
if (do_pack)
PackFileBase();
@ -278,11 +285,6 @@ int main(int argc, char **argv)
die(MBERR_OK);
}
if (do_rearc) {
ReArc(Area, FileName);
die(MBERR_OK);
}
if (do_list) {
ListFileAreas(Area);
die(MBERR_OK);

View File

@ -38,6 +38,7 @@
extern int do_quiet; /* Suppress screen output */
extern int do_index; /* Rebuild index */
@ -46,7 +47,7 @@ extern int do_quiet; /* Suppress screen output */
*/
void ReArc(int Area, char *File)
{
char *p, *temp, *linkpath, mask[256];
char *p, *temp, *mname, *linkpath, mask[256];
FILE *fp;
int i, rc = -1, count = 0, errors = 0;
struct utimbuf ut;
@ -168,6 +169,22 @@ void ReArc(int Area, char *File)
ut.actime = mktime(localtime(&fdb.FileDate));
ut.modtime = mktime(localtime(&fdb.FileDate));
utime(temp, &ut);
/*
* Check if mangled name is changed, and if so update to the
* new name and rename the file on disk.
*/
mname = calloc(PATH_MAX, sizeof(char));
strcpy(mname, fdb.LName);
name_mangle(mname);
if (strcmp(fdb.Name, mname)) {
Syslog('+', "Converted 8.3 name to %s", mname);
strcpy(fdb.Name, mname);
sprintf(mname, "%s/%s", area.Path, fdb.Name);
rename(temp, mname);
strcpy(temp, mname);
}
free(mname);
fseek(fp, - fdbhdr.recsize, SEEK_CUR);
fwrite(&fdb, fdbhdr.recsize, 1, fp);
@ -177,6 +194,9 @@ void ReArc(int Area, char *File)
sprintf(linkpath, "%s/%s", area.Path, fdb.LName);
symlink(temp, linkpath);
free(linkpath);
if (strlen(fdb.Magic))
magic_update(fdb.Magic, fdb.Name);
do_index = TRUE;
} else {
errors++;
break; // stop when something goes wrong

View File

@ -666,7 +666,7 @@ int ProcessTic(fa_list *sbl)
*/
if (tic.FileArea) {
if (strlen(TIC.TicIn.Magic))
UpDateAlias(TIC.TicIn.Magic);
magic_update(TIC.TicIn.Magic, TIC.NewFile);
else
Magic_UpDateAlias();

View File

@ -257,33 +257,3 @@ int Get_File_Id()
}
void UpDateAlias(char *Alias)
{
char *path;
FILE *fp;
Syslog('f', "UpDateAlias(%s) with %s", Alias, TIC.NewFile);
if (!strlen(CFG.req_magic)) {
WriteError("No magic filename path configured");
return;
}
path = xstrcpy(CFG.req_magic);
path = xstrcat(path, (char *)"/");
path = xstrcat(path, Alias);
if ((fp = fopen(path, "w")) == NULL) {
WriteError("$Can't create %s", path);
free(path);
return;
}
fprintf(fp, "%s\n", TIC.NewFile);
fclose(fp);
free(path);
}

View File

@ -1,6 +1,7 @@
#ifndef _UTIC_H
#define _UTIC_H
/* $Id$ */
char *MakeTicName(void);
int Day_Of_Year(void);
@ -9,7 +10,6 @@ void DeleteVirusWork(void);
void Bad(char *, ...);
void ReCalcCrc(char *);
int Get_File_Id(void);
void UpDateAlias(char *);
#endif