This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
deb-mbse/mbfido/mbfadopt.c

315 lines
8.0 KiB
C
Raw Normal View History

2001-11-18 23:19:08 +00:00
/*****************************************************************************
*
* $Id$
* Purpose: File Database Maintenance - Adopt file
*
*****************************************************************************
2002-01-07 19:16:03 +00:00
* Copyright (C) 1997-2002
2001-11-18 23:19:08 +00:00
*
* 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
2003-08-15 20:05:34 +00:00
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
2001-11-18 23:19:08 +00:00
*****************************************************************************/
2002-06-30 12:48:44 +00:00
#include "../config.h"
2001-11-18 23:19:08 +00:00
#include "../lib/libs.h"
#include "../lib/structs.h"
2002-01-07 19:16:03 +00:00
#include "../lib/users.h"
2001-11-18 23:19:08 +00:00
#include "../lib/records.h"
#include "../lib/common.h"
#include "../lib/clcomm.h"
#include "../lib/dbcfg.h"
2002-10-20 20:58:55 +00:00
#include "../lib/mberrors.h"
2001-11-25 12:18:18 +00:00
#include "virscan.h"
2001-11-18 23:19:08 +00:00
#include "mbfutil.h"
#include "mbflist.h"
extern int do_quiet; /* Suppress screen output */
extern int do_annon; /* Suppress announce file */
extern int do_novir; /* Suppress virus check */
2001-11-18 23:19:08 +00:00
void AdoptFile(int Area, char *File, char *Description)
{
2001-12-02 20:49:36 +00:00
FILE *fp;
char *temp, *temp2, *tmpdir, *unarc, *pwd, *lname;
2001-11-19 21:34:21 +00:00
char Desc[256], TDesc[256];
int IsArchive = FALSE, MustRearc = FALSE, UnPacked = FALSE;
int IsVirus = FALSE, File_Id = FALSE;
2002-05-10 18:14:27 +00:00
int i, j, k, lines = 0, File_id_cnt = 0, rc;
2001-11-19 21:34:21 +00:00
struct FILERecord fdb;
2001-11-18 23:19:08 +00:00
Syslog('-', "Adopt(%d, %s, %s)", Area, MBSE_SS(File), MBSE_SS(Description));
if (!do_quiet)
colour(CYAN, BLACK);
2001-12-02 20:49:36 +00:00
if (LoadAreaRec(Area) == FALSE)
2002-10-20 20:58:55 +00:00
die(MBERR_INIT_ERROR);
2001-11-18 23:19:08 +00:00
if (area.Available) {
temp = calloc(PATH_MAX, sizeof(char));
2001-11-25 12:18:18 +00:00
temp2 = calloc(PATH_MAX, sizeof(char));
2001-11-18 23:19:08 +00:00
pwd = calloc(PATH_MAX, sizeof(char));
tmpdir = calloc(PATH_MAX, sizeof(char));
2001-11-18 23:19:08 +00:00
2001-11-25 12:18:18 +00:00
if (CheckFDB(Area, area.Path))
2002-10-20 20:58:55 +00:00
die(MBERR_INIT_ERROR);
2001-11-18 23:19:08 +00:00
getcwd(pwd, PATH_MAX);
if (!do_quiet) {
printf("Adopt file: %s ", File);
printf("Unpacking \b\b\b\b\b\b\b\b\b\b");
fflush(stdout);
}
2001-11-25 12:18:18 +00:00
sprintf(temp, "%s/%s", pwd, File);
sprintf(tmpdir, "%s/tmp/arc", getenv("MBSE_ROOT"));
2001-11-25 12:18:18 +00:00
if ((unarc = unpacker(File)) == NULL) {
Syslog('+', "No known archive: %s", File);
sprintf(temp2, "%s/tmp/arc/%s", getenv("MBSE_ROOT"), File);
2002-01-19 13:04:55 +00:00
mkdirs(temp2, 0755);
2002-05-10 18:14:27 +00:00
if ((rc = file_cp(temp, temp2))) {
2002-05-18 12:57:00 +00:00
WriteError("Can't copy file to %s, %s", temp2, strerror(rc));
2001-11-25 12:18:18 +00:00
if (!do_quiet)
2002-05-10 18:14:27 +00:00
printf("Can't copy file to %s, %s\n", temp2, strerror(rc));
2002-10-20 20:58:55 +00:00
die(MBERR_INIT_ERROR);
2001-11-25 12:18:18 +00:00
} else {
2002-06-15 14:00:49 +00:00
if (do_novir == FALSE) {
if (!do_quiet) {
printf("Virscan \b\b\b\b\b\b\b\b\b\b");
fflush(stdout);
}
IsVirus = VirScan(tmpdir);
} else {
IsVirus = FALSE;
2001-11-25 12:18:18 +00:00
}
if (IsVirus) {
DeleteVirusWork();
chdir(pwd);
WriteError("Virus found");
2001-11-18 23:19:08 +00:00
if (!do_quiet)
2001-11-25 12:18:18 +00:00
printf("Virus found\n");
2002-10-20 20:58:55 +00:00
die(MBERR_VIRUS_FOUND);
2001-11-18 23:19:08 +00:00
}
}
2001-11-25 12:18:18 +00:00
} else {
IsArchive = TRUE;
if (strlen(area.Archiver) && (strcmp(unarc, area.Archiver) == 0))
MustRearc = TRUE;
UnPacked = UnpackFile(temp);
if (!UnPacked)
2002-10-20 20:58:55 +00:00
die(MBERR_INIT_ERROR);
2001-11-18 23:19:08 +00:00
2002-06-15 14:00:49 +00:00
if (do_novir == FALSE) {
if (!do_quiet) {
printf("Virscan \b\b\b\b\b\b\b\b\b\b");
fflush(stdout);
}
IsVirus = VirScan(tmpdir);
} else {
IsVirus = FALSE;
}
2001-11-18 23:19:08 +00:00
2001-11-25 12:18:18 +00:00
if (IsVirus) {
DeleteVirusWork();
chdir(pwd);
WriteError("Virus found");
if (!do_quiet)
printf("Virus found\n");
2002-10-20 20:58:55 +00:00
die(MBERR_VIRUS_FOUND);
2001-11-18 23:19:08 +00:00
}
2001-11-25 12:18:18 +00:00
}
if (!do_quiet) {
printf("Checking \b\b\b\b\b\b\b\b\b\b");
fflush(stdout);
}
2001-11-18 23:19:08 +00:00
2001-11-25 12:18:18 +00:00
memset(&fdb, 0, sizeof(fdb));
strcpy(fdb.Uploader, CFG.sysop_name);
fdb.UploadDate = time(NULL);
2001-11-25 16:38:06 +00:00
if (do_annon)
fdb.Announced = TRUE;
2001-11-25 12:18:18 +00:00
if (UnPacked) {
/*
* Try to get a FILE_ID.DIZ
*/
2001-11-18 23:19:08 +00:00
sprintf(temp, "%s/tmp/arc/FILE_ID.DIZ", getenv("MBSE_ROOT"));
sprintf(temp2, "%s/tmp/FILE_ID.DIZ", getenv("MBSE_ROOT"));
if (file_cp(temp, temp2) == 0) {
File_Id = TRUE;
} else {
sprintf(temp, "%s/tmp/arc/file_id.diz", getenv("MBSE_ROOT"));
if (file_cp(temp, temp2) == 0)
File_Id = TRUE;
}
2001-11-25 12:18:18 +00:00
2001-11-19 21:34:21 +00:00
if (File_Id) {
2001-11-18 23:19:08 +00:00
Syslog('-', "FILE_ID.DIZ found");
2001-11-19 21:34:21 +00:00
if ((fp = fopen(temp2, "r"))) {
/*
* Read no more then 25 lines
*/
while (((fgets(Desc, 255, fp)) != NULL) && (File_id_cnt < 25)) {
lines++;
/*
* Check if the FILE_ID.DIZ is in a normal layout.
* This should be max. 10 lines of max. 48 characters.
* We check at 51 characters and if the lines are longer,
* we discard the FILE_ID.DIZ file.
*/
if (strlen(Desc) > 51) {
File_id_cnt = 0;
File_Id = FALSE;
Syslog('!', "Discarding illegal formated FILE_ID.DIZ");
break;
}
if (strlen(Desc)) {
if (strlen(Desc) > 48)
Desc[48] = '\0';
j = 0;
for (i = 0; i < strlen(Desc); i++) {
if ((Desc[i] >= ' ') || (Desc[i] < 0)) {
fdb.Desc[File_id_cnt][j] = Desc[i];
j++;
}
}
File_id_cnt++;
}
}
fclose(fp);
unlink(temp2);
/*
* Strip empty lines at end of FILE_ID.DIZ
*/
while ((strlen(fdb.Desc[File_id_cnt-1]) == 0) && (File_id_cnt))
File_id_cnt--;
Syslog('f', "Got %d FILE_ID.DIZ lines", File_id_cnt);
for (i = 0; i < File_id_cnt; i++)
Syslog('f', "\"%s\"", fdb.Desc[i]);
}
}
2001-11-25 12:18:18 +00:00
}
2001-11-18 23:19:08 +00:00
2001-11-25 12:18:18 +00:00
if (!File_id_cnt) {
if (Description == NULL) {
WriteError("No FILE_ID.DIZ and no description on the commandline");
if (!do_quiet)
printf("No FILE_ID.DIZ and no description on the commandline\n");
DeleteVirusWork();
2002-10-20 20:58:55 +00:00
die(MBERR_COMMANDLINE);
2001-11-19 21:34:21 +00:00
} else {
/*
2001-11-25 12:18:18 +00:00
* Create description from the commandline.
2001-11-19 21:34:21 +00:00
*/
2001-11-25 12:18:18 +00:00
if (strlen(Description) < 48) {
2001-11-19 21:34:21 +00:00
/*
2001-11-25 12:18:18 +00:00
* Less then 48 chars, copy and ready.
2001-11-19 21:34:21 +00:00
*/
2001-11-25 12:18:18 +00:00
strcpy(fdb.Desc[0], Description);
File_id_cnt++;
2001-11-19 21:34:21 +00:00
} else {
/*
2001-11-25 12:18:18 +00:00
* More then 48 characters, break into multiple
* lines not longer then 48 characters.
2001-11-19 21:34:21 +00:00
*/
2001-11-25 12:18:18 +00:00
memset(&TDesc, 0, sizeof(TDesc));
strcpy(TDesc, Description);
while (strlen(TDesc) > 48) {
j = 48;
while (TDesc[j] != ' ')
j--;
strncat(fdb.Desc[File_id_cnt], TDesc, j);
File_id_cnt++;
k = strlen(TDesc);
j++; /* Correct space */
for (i = 0; i <= k; i++, j++)
TDesc[i] = TDesc[j];
}
strcpy(fdb.Desc[File_id_cnt], TDesc);
File_id_cnt++;
2001-11-19 21:34:21 +00:00
}
}
2001-11-25 12:18:18 +00:00
}
2001-11-19 21:34:21 +00:00
2001-11-25 12:18:18 +00:00
/*
* Import the file.
*/
chdir(pwd);
DeleteVirusWork();
2001-11-27 22:55:00 +00:00
/*
* Convert to 8.3 DOS filename
*/
strcpy(temp2, File);
2001-12-01 17:14:49 +00:00
name_mangle(temp2);
2001-11-27 22:55:00 +00:00
strcpy(fdb.Name, temp2);
2001-11-25 12:18:18 +00:00
strcpy(fdb.LName, File);
fdb.Size = file_size(File);
fdb.Crc32 = file_crc(File, TRUE);
fdb.FileDate = file_time(File);
sprintf(temp2, "%s/%s", area.Path, File);
if (!do_quiet) {
printf("Adding \b\b\b\b\b\b\b\b\b\b");
fflush(stdout);
}
if (strcmp(fdb.Name, fdb.LName)) {
lname = calloc(PATH_MAX, sizeof(char));
sprintf(lname, "%s/%s", area.Path, fdb.Name);
if (AddFile(fdb, Area, temp2, File, lname) == FALSE) {
die(MBERR_GENERAL);
}
free(lname);
} else {
if (AddFile(fdb, Area, temp2, File, NULL) == FALSE) {
die(MBERR_GENERAL);
}
2001-11-25 12:18:18 +00:00
}
Syslog('+', "File %s added to area %d", File, Area);
if (MustRearc) {
/* Here we should call the rearc function */
2001-11-18 23:19:08 +00:00
}
free(pwd);
2001-11-25 12:18:18 +00:00
free(temp2);
2001-11-18 23:19:08 +00:00
free(temp);
free(tmpdir);
2001-11-18 23:19:08 +00:00
} else {
WriteError("Area %d is not available", Area);
if (!do_quiet)
printf("Area %d is not available\n", Area);
}
if (!do_quiet) {
printf("\r \r");
fflush(stdout);
}
}