diff --git a/ChangeLog b/ChangeLog index 75ee8014..f948b65b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/TODO b/TODO index d69ce059..2aa1517c 100644 --- a/TODO +++ b/TODO @@ -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 <-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 diff --git a/lib/Makefile b/lib/Makefile index d81c4a6d..c35c94d1 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -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 diff --git a/lib/magic.c b/lib/magic.c new file mode 100644 index 00000000..440d0933 --- /dev/null +++ b/lib/magic.c @@ -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; +} + + diff --git a/lib/mbselib.h b/lib/mbselib.h index 7c50e7eb..912f29b5 100644 --- a/lib/mbselib.h +++ b/lib/mbselib.h @@ -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 */ - - /**************************************************************************** * diff --git a/mbcico/lutil.h b/mbcico/lutil.h index 2dc31ba5..49dde3b0 100644 --- a/mbcico/lutil.h +++ b/mbcico/lutil.h @@ -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); diff --git a/mbfido/magic.c b/mbfido/magic.c index 09dde958..b9f2256e 100644 --- a/mbfido/magic.c +++ b/mbfido/magic.c @@ -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"); } } diff --git a/mbfido/mbfcheck.c b/mbfido/mbfcheck.c index 8ad556b9..ad30279d 100644 --- a/mbfido/mbfcheck.c +++ b/mbfido/mbfcheck.c @@ -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); diff --git a/mbfido/mbfile.c b/mbfido/mbfile.c index 218a8869..2adea69f 100644 --- a/mbfido/mbfile.c +++ b/mbfido/mbfile.c @@ -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); diff --git a/mbfido/mbfrearc.c b/mbfido/mbfrearc.c index 2eefe276..51752461 100644 --- a/mbfido/mbfrearc.c +++ b/mbfido/mbfrearc.c @@ -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,15 +169,34 @@ 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); - + /* * Update symbolic link to long filename */ 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 diff --git a/mbfido/ptic.c b/mbfido/ptic.c index e217f460..e8b9a3f2 100644 --- a/mbfido/ptic.c +++ b/mbfido/ptic.c @@ -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(); diff --git a/mbfido/utic.c b/mbfido/utic.c index 80249359..baf307f7 100644 --- a/mbfido/utic.c +++ b/mbfido/utic.c @@ -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); -} - - - diff --git a/mbfido/utic.h b/mbfido/utic.h index f514bae2..98d4b152 100644 --- a/mbfido/utic.h +++ b/mbfido/utic.h @@ -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