diff --git a/ChangeLog b/ChangeLog index 4f35a66a..9394914e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4743,6 +4743,9 @@ v0.33.20 10-Feb-2002 removed if they are empty. Good for bulk areas create. When missing areas are created, uplink requests are sent to connect the areas. + Added more checks to processing of file_id.diz files. Also + when it is illegal formatted the already processed lines are + cleared to prevent later malformatted descriptions. mbmsg: When creating non-existend message bases, the path is created @@ -4755,6 +4758,8 @@ v0.33.20 10-Feb-2002 The check function now checks download directory permissions and tries to correct errors. Missing download directories are created mode 0775. + Moved check for empty areas to mbfile check function. + The mbfile move command now also moves the thumbnails. mball: Will not crash anymore when it needs more then 10 minutes to diff --git a/TODO b/TODO index 8afe2d41..fa82d6c5 100644 --- a/TODO +++ b/TODO @@ -71,10 +71,6 @@ mbfile: N: Rearc - L: When files are moved from one area to another, the thumbnails - are not moved. They are recreated later but this can be very - time consuming. - mbaff: L: Add setup parameters for minimum length of keywords. diff --git a/mbfido/mbfcheck.c b/mbfido/mbfcheck.c index a8f25500..55bcd98e 100644 --- a/mbfido/mbfcheck.c +++ b/mbfido/mbfcheck.c @@ -63,7 +63,7 @@ extern int do_pack; /* Pack filebase */ void Check(void) { FILE *pAreas, *pFile; - int i, iAreas, iAreasNew = 0, Fix; + int i, iAreas, iAreasNew = 0, Fix, inArea; int iTotal = 0, iErrors = 0; char *sAreas, *fAreas, *newdir, *temp; DIR *dp; @@ -193,9 +193,11 @@ void Check(void) * Now start checking the files in the filedatabase * against the contents of the directory. */ + inArea = 0; while (fread(&file, sizeof(file), 1, pFile) == 1) { iTotal++; + inArea++; sprintf(newdir, "%s/%s", area.Path, file.LName); if (file_exist(newdir, R_OK)) { @@ -248,6 +250,8 @@ void Check(void) } } } + if (inArea == 0) + Syslog('+', "Warning: area %d (%s) is empty", i, area.Name); /* * Check files in the directory against the database. diff --git a/mbfido/mbfkill.c b/mbfido/mbfkill.c index dd28726c..f0ab186e 100644 --- a/mbfido/mbfkill.c +++ b/mbfido/mbfkill.c @@ -225,9 +225,6 @@ void Kill(void) unlink(sTemp); chmod(fAreas, 006600); } - if (!FilesLeft) { - Syslog('+', "Warning: area %d (%s) is empty", i, area.Name); - } } else fclose(pFile); diff --git a/mbfido/mbfmove.c b/mbfido/mbfmove.c index 0745af07..12efec6e 100644 --- a/mbfido/mbfmove.c +++ b/mbfido/mbfmove.c @@ -132,8 +132,26 @@ void Move(int From, int To, char *File) while (fread(&fdb, sizeof(fdb), 1, fp1) == 1) { if (strcmp(fdb.LName, File)) fwrite(&fdb, sizeof(fdb), 1, fp2); - else + else { rc = AddFile(fdb, To, topath, frompath); + if (rc) { + /* + * Try to move thumbnail if it exists + */ + unlink(frompath); + free(frompath); + free(topath); + frompath = xstrcpy(area.Path); + frompath = xstrcat(frompath, (char *)"/."); + frompath = xstrcat(frompath, File); + topath = xstrcpy(area.Path); + topath = xstrcat(topath, (char *)"/."); + topath = xstrcat(topath, File); + if (file_exist(frompath, R_OK) == 0) { + file_mv(frompath, topath); + } + } + } } fclose(fp1); fclose(fp2); @@ -149,7 +167,6 @@ void Move(int From, int To, char *File) WriteError("$Can't unlink %s", temp1); unlink(temp2); } - unlink(frompath); colour(CYAN, BLACK); } else { /* diff --git a/mbfido/ptic.c b/mbfido/ptic.c index 8eaea7dc..19a0224a 100644 --- a/mbfido/ptic.c +++ b/mbfido/ptic.c @@ -579,9 +579,7 @@ int ProcessTic(fa_list *sbl) if (!Get_File_Id()) { if (TIC.TicIn.TotLDesc > 2) { for (i = 0; i < TIC.TicIn.TotLDesc; i++) { - strcpy(temp1, TIC.TicIn.LDesc[i]); - temp1[48] = '\0'; - strcpy(TIC.File_Id[i], temp1); + strncpy(TIC.File_Id[i], TIC.TicIn.LDesc[i], 48); } TIC.File_Id_Ct = TIC.TicIn.TotLDesc; } else { @@ -599,14 +597,18 @@ int ProcessTic(fa_list *sbl) j = 48; while (TDesc[j] != ' ') j--; - strncat(TIC.File_Id[TIC.File_Id_Ct], TDesc, j); + strncpy(TIC.File_Id[TIC.File_Id_Ct], TDesc, j); + Syslog('f', "%2d/%2d: \"%s\"", TIC.File_Id_Ct, j, TIC.File_Id[TIC.File_Id_Ct]); TIC.File_Id_Ct++; k = strlen(TDesc); j++; /* Correct space */ for (i = 0; i <= k; i++, j++) TDesc[i] = TDesc[j]; + if (TIC.File_Id_Ct == 23) + break; } - strcpy(TIC.File_Id[TIC.File_Id_Ct], TDesc); + strncpy(TIC.File_Id[TIC.File_Id_Ct], TDesc, 48); + Syslog('f', "%2d/%2d: \"%s\"", TIC.File_Id_Ct, strlen(TIC.File_Id[TIC.File_Id_Ct]), TIC.File_Id[TIC.File_Id_Ct]); TIC.File_Id_Ct++; } } diff --git a/mbfido/tic.c b/mbfido/tic.c index c1324f92..93a13832 100644 --- a/mbfido/tic.c +++ b/mbfido/tic.c @@ -165,7 +165,7 @@ int LoadTic(char *inb, char *tfn) { FILE *tfp; char *Temp, *Temp2, *Buf, *Log = NULL; - int i, j, rc; + int i, j, rc, bufsize; fa_list *sbl = NULL; int DescCnt = FALSE; @@ -184,10 +184,15 @@ int LoadTic(char *inb, char *tfn) return 1; } - Temp = calloc(PATH_MAX, sizeof(char)); - Buf = calloc(PATH_MAX, sizeof(char)); + if (PATH_MAX > 1024) + bufsize = PATH_MAX; + else + bufsize = 1024; + Temp = calloc(bufsize+1, sizeof(char)); + Buf = calloc(bufsize+1, sizeof(char)); + Syslog('f', "Tic buffersize %d", bufsize); - while ((fgets(Buf, PATH_MAX -1, tfp)) != NULL) { + while ((fgets(Buf, bufsize, tfp)) != NULL) { /* * Remove all garbage from the .TIC file. */ @@ -200,10 +205,10 @@ int LoadTic(char *inb, char *tfn) } Temp[j] = '\0'; - if (strlen(Temp) > 255) { - Syslog('+', "Truncating TIC line of %d characters", strlen(Temp)); - Temp[255] = '\0'; - } +// if (strlen(Temp) > 255) { +// Syslog('+', "Truncating TIC line of %d characters", strlen(Temp)); +// Temp[255] = '\0'; +// } Syslog('f', "TIC: %s", Temp); if (strncasecmp(Temp, "hatch", 5) == 0) { @@ -251,7 +256,7 @@ int LoadTic(char *inb, char *tfn) } else if (strncasecmp(Temp, "desc ", 5) == 0) { if (!DescCnt) { - strncpy(TIC.TicIn.Desc, Temp+5, 255); + strncpy(TIC.TicIn.Desc, Temp+5, 1023); strncpy(T_File.Desc, TIC.TicIn.Desc, 255); DescCnt = TRUE; } else { diff --git a/mbfido/tic.h b/mbfido/tic.h index 824744fa..803be3a0 100644 --- a/mbfido/tic.h +++ b/mbfido/tic.h @@ -17,7 +17,7 @@ typedef struct _tic_in { char Created[81]; /* Created text */ char Path[25][81]; /* Travelled path */ int TotPath; /* Nr of pathlines */ - char Desc[256]; /* Short description */ + char Desc[1024]; /* Short description */ char Magic[21]; /* Magic alias */ char Crc[9]; /* CRC of file */ char Pw[21]; /* Password */ diff --git a/mbfido/utic.c b/mbfido/utic.c index 563c6c0c..dd336f58 100644 --- a/mbfido/utic.c +++ b/mbfido/utic.c @@ -172,74 +172,80 @@ void ReCalcCrc(char *fn) int Get_File_Id() { - char *temp; - char Desc[256]; - FILE *fp; - int i, j, lines = 0; + char *temp; + char Desc[1024]; + FILE *fp; + int i, j, lines = 0; - temp = calloc(PATH_MAX, sizeof(char)); - sprintf(temp, "%s/tmp/FILE_ID.DIZ", getenv("MBSE_ROOT")); + temp = calloc(PATH_MAX, sizeof(char)); + sprintf(temp, "%s/tmp/FILE_ID.DIZ", getenv("MBSE_ROOT")); + if ((fp = fopen(temp, "r")) == NULL) { + sprintf(temp, "%s/tmp/file_id.diz", getenv("MBSE_ROOT")); if ((fp = fopen(temp, "r")) == NULL) { - sprintf(temp, "%s/tmp/file_id.diz", getenv("MBSE_ROOT")); - if ((fp = fopen(temp, "r")) == NULL) { - free(temp); - return FALSE; + free(temp); + return FALSE; + } + } + + /* + * Read no more then 25 lines. + */ + while (((fgets(Desc, 1023, fp)) != NULL) && (TIC.File_Id_Ct < 25)) { + lines++; + /* + * Check if the FILE_ID.DIZ is in a normal layout. + * The layout should be max. 10 lines of max. 48 characters. + * We check at 51 characters and if the lines are longer, + * we trash the FILE_ID.DIZ file. + */ + if (strlen(Desc) > 51) { + fclose(fp); + unlink(temp); + for (i = 0; i < 25; i++) + TIC.File_Id[i][0] = '\0'; + TIC.File_Id_Ct = 0; + Syslog('f', "FILE_ID.DIZ line %d is %d chars", lines, strlen(Desc)); + Syslog('!', "Trashing illegal formatted FILE_ID.DIZ"); + free(temp); + return FALSE; + } + + if (strlen(Desc) > 0) { + j = 0; + for (i = 0; i < strlen(Desc); i++) { + if (isprint(Desc[i])) { + TIC.File_Id[TIC.File_Id_Ct][j] = Desc[i]; + j++; + if (j > 47) + break; + } } + + /* + * Remove trailing spaces + */ + while (j && isspace(TIC.File_Id[TIC.File_Id_Ct][j-1])) + j--; + TIC.File_Id[TIC.File_Id_Ct][j] = '\0'; + Syslog('f', "%2d/%2d: \"%s\"", TIC.File_Id_Ct, j, TIC.File_Id[TIC.File_Id_Ct]); + TIC.File_Id_Ct++; } + } + fclose(fp); + unlink(temp); + free(temp); - /* - * Read no more then 25 lines. - */ - while (((fgets(Desc, 255, fp)) != NULL) && (TIC.File_Id_Ct < 25)) { - lines++; - /* - * Check if the FILE_ID.DIZ is in a normal layout. - * The layout should be max. 10 lines of max. 48 characters. - * We check at 51 characters and if the lines are longer, - * we trash the FILE_ID.DIZ file. - */ - if (strlen(Desc) > 51) { - fclose(fp); - unlink(temp); - TIC.File_Id_Ct = 0; - Syslog('f', "FILE_ID.DIZ line %d is %d chars", lines, strlen(Desc)); - Syslog('!', "Trashing illegal formatted FILE_ID.DIZ"); - free(temp); - return FALSE; - } + /* + * Strip empty lines at end of FILE_ID.DIZ + */ + while ((strlen(TIC.File_Id[TIC.File_Id_Ct-1]) == 0) && (TIC.File_Id_Ct)) + TIC.File_Id_Ct--; - if (strlen(Desc) > 0) { - j = 0; - for (i = 0; i < strlen(Desc); i++) { - if ((Desc[i] >= ' ') || (Desc[i] < 0)) { - TIC.File_Id[TIC.File_Id_Ct][j] = Desc[i]; - j++; - } - } - - if (j >= 48) - TIC.File_Id[TIC.File_Id_Ct][48] = '\0'; - else - TIC.File_Id[TIC.File_Id_Ct][j] = '\0'; - - TIC.File_Id_Ct++; - } - } - fclose(fp); - unlink(temp); - free(temp); - - /* - * Strip empty lines at end of FILE_ID.DIZ - */ - while ((strlen(TIC.File_Id[TIC.File_Id_Ct-1]) == 0) && (TIC.File_Id_Ct)) - TIC.File_Id_Ct--; - - Syslog('f', "Got %d FILE_ID.DIZ lines", TIC.File_Id_Ct); - if (TIC.File_Id_Ct) - return TRUE; - else - return FALSE; + Syslog('f', "Got %d FILE_ID.DIZ lines", TIC.File_Id_Ct); + if (TIC.File_Id_Ct) + return TRUE; + else + return FALSE; }