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/mbfile.c

315 lines
7.7 KiB
C
Raw Normal View History

2001-08-17 05:46:24 +00:00
/*****************************************************************************
*
* $Id$
* Purpose: File Database Maintenance
2001-08-17 05:46:24 +00:00
*
*****************************************************************************
2004-02-21 17:22:00 +00:00
* Copyright (C) 1997-2004
2001-08-17 05:46:24 +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-08-17 05:46:24 +00:00
*****************************************************************************/
2002-06-30 12:48:44 +00:00
#include "../config.h"
2004-02-21 17:22:00 +00:00
#include "../lib/mbselib.h"
2002-01-07 19:16:03 +00:00
#include "../lib/users.h"
2004-02-21 17:22:00 +00:00
#include "../lib/mbsedb.h"
2001-11-18 23:19:08 +00:00
#include "mbfkill.h"
#include "mbfadopt.h"
#include "mbfindex.h"
#include "mbfcheck.h"
#include "mbfpack.h"
#include "mbflist.h"
2001-11-25 12:18:18 +00:00
#include "mbfimport.h"
2001-11-25 16:38:06 +00:00
#include "mbftoberep.h"
2001-12-02 19:17:14 +00:00
#include "mbfmove.h"
#include "mbfdel.h"
2001-11-18 23:19:08 +00:00
#include "mbfutil.h"
2003-11-08 15:30:04 +00:00
#include "mbfsort.h"
2001-08-17 05:46:24 +00:00
#include "mbfile.h"
2004-03-08 20:51:04 +00:00
#include "mbfrearc.h"
2001-08-17 05:46:24 +00:00
extern int do_quiet; /* Suppress screen output */
2001-11-25 16:38:06 +00:00
int do_annon = FALSE; /* Suppress announce on new files */
2002-06-15 14:00:49 +00:00
int do_novir = FALSE; /* Suppress virus check */
2001-11-18 23:19:08 +00:00
int do_adopt = FALSE; /* Adopt a file */
2001-08-17 05:46:24 +00:00
int do_pack = FALSE; /* Pack filebase */
int do_check = FALSE; /* Check filebase */
int do_kill = FALSE; /* Kill/move old files */
int do_index = FALSE; /* Create request index */
2001-11-25 12:18:18 +00:00
int do_import= FALSE; /* Import files in area */
2001-10-19 13:04:37 +00:00
int do_list = FALSE; /* List fileareas */
2001-11-25 16:38:06 +00:00
int do_tobe = FALSE; /* List toberep database */
2001-12-02 19:17:14 +00:00
int do_move = FALSE; /* Move a file */
int do_del = FALSE; /* Delete/undelete a file */
2003-11-08 15:30:04 +00:00
int do_sort = FALSE; /* Sort a filebase */
2004-03-08 20:51:04 +00:00
int do_rearc = FALSE; /* ReArc a file */
2001-08-17 05:46:24 +00:00
extern int e_pid; /* Pid of external process */
extern int show_log; /* Show logging */
time_t t_start; /* Start time */
time_t t_end; /* End time */
int main(int argc, char **argv)
{
2002-10-20 20:58:55 +00:00
int i, Area = 0, ToArea = 0, UnDel = FALSE;
char *cmd, *FileName = NULL, *Description = NULL;
struct passwd *pw;
2001-08-17 05:46:24 +00:00
2002-10-20 20:58:55 +00:00
InitConfig();
2004-02-21 17:22:00 +00:00
TermInit(1, 80, 25);
2002-10-20 20:58:55 +00:00
t_start = time(NULL);
umask(002);
/*
* Catch all signals we can, and ignore the rest.
*/
for (i = 0; i < NSIG; i++) {
2003-12-04 22:07:33 +00:00
if ((i == SIGHUP) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM))
2002-10-20 20:58:55 +00:00
signal(i, (void (*))die);
2004-04-09 18:31:22 +00:00
else if (i == SIGCHLD)
signal(i, SIG_DFL);
2003-12-04 22:07:33 +00:00
else if ((i != SIGKILL) && (i != SIGSTOP))
2002-10-20 20:58:55 +00:00
signal(i, SIG_IGN);
}
if(argc < 2)
Help();
cmd = xstrcpy((char *)"Command line: mbfile");
for (i = 1; i < argc; i++) {
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
if (!strncasecmp(argv[i], "a", 1)) {
i++;
Area = atoi(argv[i]);
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
2003-11-02 11:51:10 +00:00
if (Area) {
do_adopt = TRUE;
2002-10-20 20:58:55 +00:00
i++;
2003-11-02 11:51:10 +00:00
FileName = xstrcpy(argv[i]);
2001-08-17 05:46:24 +00:00
cmd = xstrcat(cmd, (char *)" ");
2001-11-25 16:38:06 +00:00
cmd = xstrcat(cmd, argv[i]);
2003-11-02 11:51:10 +00:00
if (argc > (i + 1)) {
i++;
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
if (!strncasecmp(argv[i], "-a", 2)) {
do_annon = TRUE;
} else {
Description = xstrcpy(argv[i]);
}
2002-10-20 20:58:55 +00:00
}
}
} else if ((!strncasecmp(argv[i], "d", 1)) || (!strncasecmp(argv[i], "u", 1))) {
if (!strncasecmp(argv[i], "u", 1))
UnDel = TRUE;
if (argc > (i + 1)) {
i++;
Area = atoi(argv[i]);
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
if (argc > (i + 1)) {
i++;
FileName = xstrcpy(argv[i]);
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
do_del = TRUE;
}
}
2004-03-08 20:51:04 +00:00
} else if (!strncasecmp(argv[i], "r", 1)) {
if (argc > (i + 1)) {
i++;
Area = atoi(argv[i]);
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
if (argc > (i + 1)) {
i++;
FileName = xstrcpy(argv[i]);
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
do_rearc = TRUE;
}
}
2002-10-20 20:58:55 +00:00
} else if (!strncasecmp(argv[i], "in", 2)) {
do_index = TRUE;
} else if (!strncasecmp(argv[i], "im", 2)) {
if (argc > (i + 1)) {
do_import = TRUE;
i++;
Area = atoi(argv[i]);
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
}
2004-08-07 11:57:20 +00:00
} else if (!strcasecmp(argv[i], "i")) {
Help();
2002-10-20 20:58:55 +00:00
} else if (!strncasecmp(argv[i], "l", 1)) {
do_list = TRUE;
if (argc > (i + 1)) {
i++;
Area = atoi(argv[i]);
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
}
} else if (!strncasecmp(argv[i], "m", 1)) {
if (argc > (i + 1)) {
i++;
Area = atoi(argv[i]);
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
if (argc > (i + 1)) {
i++;
ToArea = atoi(argv[i]);
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
2001-12-02 19:17:14 +00:00
if (argc > (i + 1)) {
i++;
2002-10-20 20:58:55 +00:00
FileName = xstrcpy(argv[i]);
2001-12-02 19:17:14 +00:00
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
2002-10-20 20:58:55 +00:00
do_move = TRUE;
2001-12-02 19:17:14 +00:00
}
2001-12-02 20:49:36 +00:00
}
2002-10-20 20:58:55 +00:00
}
2003-11-08 15:30:04 +00:00
} else if (!strncasecmp(argv[i], "s", 1)) {
if (argc > (i + 1)) {
i++;
Area = atoi(argv[i]);
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
do_sort = TRUE;
}
2002-10-20 20:58:55 +00:00
} else if (!strncasecmp(argv[i], "p", 1)) {
do_pack = TRUE;
} else if (!strncasecmp(argv[i], "c", 1)) {
do_check = TRUE;
2004-05-04 14:31:25 +00:00
if (argc > (i + 1)) {
Area = atoi(argv[i+1]);
if (Area) {
i++;
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
}
}
2002-10-20 20:58:55 +00:00
} else if (!strncasecmp(argv[i], "k", 1)) {
do_kill = TRUE;
} else if (!strncasecmp(argv[i], "t", 1)) {
do_tobe = TRUE;
} else if (!strncasecmp(argv[i], "-q", 2)) {
do_quiet = TRUE;
} else if (!strncasecmp(argv[i], "-a", 2)) {
do_annon = TRUE;
} else if (!strncasecmp(argv[i], "-v", 2)) {
do_novir = TRUE;
2001-08-17 05:46:24 +00:00
}
2002-10-20 20:58:55 +00:00
}
2001-08-17 05:46:24 +00:00
2003-11-08 15:30:04 +00:00
if (!(do_pack || do_sort || do_check || do_kill || do_index || do_import ||
2004-03-08 20:51:04 +00:00
do_list || do_adopt || do_del || do_move || do_tobe || do_rearc))
2002-10-20 20:58:55 +00:00
Help();
2001-08-17 05:46:24 +00:00
2002-10-20 20:58:55 +00:00
ProgName();
pw = getpwuid(getuid());
2003-09-09 19:39:51 +00:00
InitClient(pw->pw_name, (char *)"mbfile", CFG.location, CFG.logfile,
CFG.util_loglevel, CFG.error_log, CFG.mgrlog, CFG.debuglog);
2001-08-17 05:46:24 +00:00
2002-10-20 20:58:55 +00:00
Syslog(' ', " ");
Syslog(' ', "MBFILE v%s", VERSION);
Syslog(' ', cmd);
if (do_novir)
Syslog('!', "WARNING: running without virus checking");
free(cmd);
2001-08-17 05:46:24 +00:00
2002-10-20 20:58:55 +00:00
if (!do_quiet)
printf("\n");
2001-08-17 05:46:24 +00:00
2004-03-21 12:55:45 +00:00
if (enoughspace(CFG.freespace) == 0)
2002-10-20 20:58:55 +00:00
die(MBERR_DISK_FULL);
2001-08-17 05:46:24 +00:00
2003-08-03 14:42:12 +00:00
if (lockprogram((char *)"mbfile")) {
if (!do_quiet)
printf("Can't lock mbfile, abort.\n");
die(MBERR_NO_PROGLOCK);
}
2002-10-20 20:58:55 +00:00
if (do_adopt) {
AdoptFile(Area, FileName, Description);
die(MBERR_OK);
}
2001-11-18 23:19:08 +00:00
2002-10-20 20:58:55 +00:00
if (do_import) {
ImportFiles(Area);
die(MBERR_OK);
}
2001-11-25 12:18:18 +00:00
2002-10-20 20:58:55 +00:00
if (do_kill)
Kill();
2001-08-17 05:46:24 +00:00
2003-11-08 15:30:04 +00:00
if (do_sort)
SortFileBase(Area);
2004-05-04 14:31:25 +00:00
if (do_check) {
Check(Area);
}
2001-08-17 05:46:24 +00:00
2004-03-09 21:42:29 +00:00
if (do_rearc) {
ReArc(Area, FileName);
if (do_index)
Index();
die(MBERR_OK);
}
2002-10-20 20:58:55 +00:00
if (do_pack)
PackFileBase();
2001-08-17 05:46:24 +00:00
2002-10-20 20:58:55 +00:00
if (do_index)
Index();
2001-08-17 05:46:24 +00:00
2002-10-20 20:58:55 +00:00
if (do_move) {
Move(Area, ToArea, FileName);
die(MBERR_OK);
}
2001-12-02 19:17:14 +00:00
2002-10-20 20:58:55 +00:00
if (do_del) {
Delete(UnDel, Area, FileName);
die(MBERR_OK);
}
2002-10-20 20:58:55 +00:00
if (do_list) {
ListFileAreas(Area);
die(MBERR_OK);
}
2001-10-19 13:04:37 +00:00
2002-10-20 20:58:55 +00:00
if (do_tobe)
ToBeRep();
die(MBERR_OK);
return 0;
2001-08-17 05:46:24 +00:00
}
2001-10-19 13:04:37 +00:00