Code cleanup

This commit is contained in:
Michiel Broek 2005-08-19 19:46:55 +00:00
parent 829514d215
commit ccc8390ad3
6 changed files with 474 additions and 466 deletions

View File

@ -8,6 +8,15 @@ v0.71.5 18-Aug-2005
mbdiff:
Code cleanup.
mball:
Code cleanup.
mbstat:
Code cleanup.
mbuser:
Code cleanup.
v0.71.4 12-Aug-2005 - 18-Aug-2005

View File

@ -438,7 +438,7 @@ void Help(void)
printf(" directory.\n");
mbse_colour(LIGHTBLUE, BLACK);
printf("\n Options are:\n\n");
mbse_colour(CYAN, BLAKC);
mbse_colour(CYAN, BLACK);
printf(" -quiet Quiet mode\n");
mbse_colour(LIGHTGRAY, BLACK);
printf("\n");

View File

@ -41,6 +41,7 @@ static char *months[]={(char *)"Jan",(char *)"Feb",(char *)"Mar",
void count_download(char *, time_t, off_t, char *);
extern int do_quiet;
void dlcount(void)
@ -84,6 +85,8 @@ void dlcount(void)
/*
* Check apache logfile
*/
if (!do_quiet)
printf("Checking WWW downloads\n");
Syslog('+', "Checking WWW downloads");
while (fgets(temp, PATH_MAX-1, fp)) {
@ -163,6 +166,8 @@ void dlcount(void)
/*
* Check apache logfile
*/
if (!do_quiet)
printf("Checking FTP downloads\n");
Syslog('+', "Checking FTP downloads");
while (fgets(temp, PATH_MAX-1, fp)) {

View File

@ -4,7 +4,7 @@
* Purpose ...............: Creates allfiles listings
*
*****************************************************************************
* Copyright (C) 1997-2004
* Copyright (C) 1997-2005
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
@ -49,13 +49,13 @@ struct tm *l_date; /* Structure for Date */
void ProgName()
{
if (do_quiet)
return;
if (do_quiet)
return;
mbse_colour(15, 0);
printf("\nMBALL: MBSE BBS %s Allfiles Listing Creator\n", VERSION);
mbse_colour(14, 0);
printf(" %s\n", COPYRIGHT);
mbse_colour(WHITE, BLACK);
printf("\nMBALL: MBSE BBS %s Allfiles Listing Creator\n", VERSION);
mbse_colour(YELLOW, BLACK);
printf(" %s\n", COPYRIGHT);
}
@ -95,7 +95,7 @@ void die(int onsig)
Syslog(' ', "MBALL finished in %s", t_elapsed(t_start, t_end));
if (!do_quiet) {
mbse_colour(7, 0);
mbse_colour(LIGHTGRAY, BLACK);
printf("\n");
}
ExitClient(onsig);
@ -105,23 +105,23 @@ void die(int onsig)
void Help()
{
do_quiet = FALSE;
ProgName();
do_quiet = FALSE;
ProgName();
mbse_colour(11, 0);
printf("\nUsage: mball [command] <options>\n\n");
mbse_colour(9, 0);
printf(" Commands are:\n\n");
mbse_colour(3, 0);
printf(" l list Create allfiles and newfiles lists\n");
mbse_colour(9, 0);
printf("\n Options are:\n\n");
mbse_colour(3, 0);
printf(" -q -quiet Quiet mode\n");
printf(" -z -zip Create .zip archives\n");
mbse_colour(7, 0);
printf("\n");
die(MBERR_COMMANDLINE);
mbse_colour(LIGHTCYAN, BLACK);
printf("\nUsage: mball [command] <options>\n\n");
mbse_colour(LIGHTBLUE, BLACK);
printf(" Commands are:\n\n");
mbse_colour(CYAN, BLACK);
printf(" l list Create allfiles and newfiles lists\n");
mbse_colour(LIGHTBLUE, BLACK);
printf("\n Options are:\n\n");
mbse_colour(CYAN, BLACK);
printf(" -q -quiet Quiet mode\n");
printf(" -z -zip Create .zip archives\n");
mbse_colour(LIGHTGRAY, BLACK);
printf("\n");
die(MBERR_COMMANDLINE);
}
@ -181,7 +181,7 @@ int main(int argc, char **argv)
free(cmd);
if (!do_quiet) {
mbse_colour(3, 0);
mbse_colour(CYAN, BLACK);
printf("\n");
}
@ -210,60 +210,60 @@ int main(int argc, char **argv)
void MidLine(char *txt, FILE *fp, int doit)
{
char temp[81];
int x, y, z;
char temp[81];
int x, y, z;
if (!doit)
return;
if (!doit)
return;
z = strlen(txt);
x = 77 - z;
x /= 2;
strcpy(temp, "");
z = strlen(txt);
x = 77 - z;
x /= 2;
strcpy(temp, "");
for (y = 0; y < x; y++)
strcat(temp, " ");
for (y = 0; y < x; y++)
strcat(temp, " ");
strcat(temp, txt);
z = strlen(temp);
x = 77 - z;
strcat(temp, txt);
z = strlen(temp);
x = 77 - z;
for (y = 0; y < x; y++)
strcat(temp, " ");
for (y = 0; y < x; y++)
strcat(temp, " ");
fprintf(fp, "%c", 179);
fprintf(fp, "%s", temp);
fprintf(fp, "%c\r\n", 179);
fprintf(fp, "%c", 179);
fprintf(fp, "%s", temp);
fprintf(fp, "%c\r\n", 179);
}
void TopBox(FILE *fp, int doit)
{
int y;
int y;
if (!doit)
return;
if (!doit)
return;
fprintf(fp, "\r\n%c", 213);
for(y = 0; y < 77; y++)
fprintf(fp, "%c", 205);
fprintf(fp, "%c\r\n", 184);
fprintf(fp, "\r\n%c", 213);
for(y = 0; y < 77; y++)
fprintf(fp, "%c", 205);
fprintf(fp, "%c\r\n", 184);
}
void BotBox(FILE *fp, int doit)
{
int y;
int y;
if (!doit)
return;
if (!doit)
return;
fprintf(fp, "%c", 212);
for (y = 0; y < 77; y++)
fprintf(fp, "%c", 205);
fprintf(fp, "%c\r\n\r\n", 190);
fprintf(fp, "%c", 212);
for (y = 0; y < 77; y++)
fprintf(fp, "%c", 205);
fprintf(fp, "%c\r\n\r\n", 190);
}
@ -273,10 +273,8 @@ void Masterlist()
FILE *fp, *np, *pAreas, *pHeader;
int AreaNr = 0, z, x = 0, New;
unsigned long AllFiles = 0, AllKBytes = 0, NewFiles = 0, NewKBytes = 0;
unsigned long AllAreaFiles, AllAreaBytes, popdown, down;
unsigned long NewAreaFiles, NewAreaBytes;
char *sAreas;
char temp[81], pop[81];
unsigned long AllAreaFiles, AllAreaBytes, popdown, down, NewAreaFiles, NewAreaBytes;
char *sAreas, temp[81], pop[81];
struct _fdbarea *fdb_area = NULL;
sAreas = calloc(PATH_MAX, sizeof(char));
@ -287,7 +285,7 @@ void Masterlist()
if(( pAreas = fopen (sAreas, "r")) == NULL) {
WriteError("Can't open File Areas File: %s", sAreas);
mbse_colour(7,0);
mbse_colour(LIGHTGRAY, BLACK);
die(MBERR_GENERAL);
}
fread(&areahdr, sizeof(areahdr), 1, pAreas);
@ -338,7 +336,7 @@ void Masterlist()
Nopper();
if ((fdb_area = mbsedb_OpenFDB(AreaNr, 30)) == 0) {
WriteError("$Can't open Area %d (%s)! Skipping ...", AreaNr, area.Name);
WriteError("Can't open Area %d (%s)! Skipping ...", AreaNr, area.Name);
} else {
popdown = 0;
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
@ -480,35 +478,36 @@ void Masterlist()
void MakeArc()
{
char *cmd;
char *cmd;
if (!getarchiver((char *)"ZIP")) {
WriteError("ZIP Archiver not available");
return;
}
if (!getarchiver((char *)"ZIP")) {
WriteError("ZIP Archiver not available");
return;
}
cmd = xstrcpy(archiver.farc);
cmd = xstrcpy(archiver.farc);
if (cmd == NULL) {
WriteError("ZIP archive command not available");
return;
}
if (cmd == NULL) {
WriteError("ZIP archive command not available");
return;
}
Nopper();
if (!do_quiet)
printf("Creating allfiles.zip\n");
if (!execute_str(cmd, (char *)"allfiles.zip allfiles.txt", (char *)NULL, (char *)"/dev/null",
Nopper();
if (!do_quiet)
printf("Creating allfiles.zip\n");
if (!execute_str(cmd, (char *)"allfiles.zip allfiles.txt", (char *)NULL, (char *)"/dev/null",
(char *)"/dev/null", (char *)"/dev/null") == 0)
WriteError("Create allfiles.zip failed");
WriteError("Create allfiles.zip failed");
Nopper();
if (!do_quiet)
printf("Creating newfiles.zip\n");
if (!execute_str(cmd, (char *)"newfiles.zip newfiles.txt", (char *)NULL, (char *)"/dev/null",
Nopper();
if (!do_quiet)
printf("Creating newfiles.zip\n");
if (!execute_str(cmd, (char *)"newfiles.zip newfiles.txt", (char *)NULL, (char *)"/dev/null",
(char *)"/dev/null", (char *)"/dev/null") == 0)
WriteError("Create newfiles.zip failed");
free(cmd);
cmd = NULL;
WriteError("Create newfiles.zip failed");
free(cmd);
cmd = NULL;
}

View File

@ -4,7 +4,7 @@
* Purpose ...............: Change BBS status
*
*****************************************************************************
* Copyright (C) 1997-2004
* Copyright (C) 1997-2005
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
@ -41,234 +41,234 @@ time_t t_start, t_end;
void Help(void)
{
do_quiet = FALSE;
ProgName();
do_quiet = FALSE;
ProgName();
mbse_colour(11, 0);
printf("\nUsage: mbstat [command] <options>\n\n");
mbse_colour(9, 0);
printf(" Commands are:\n\n");
mbse_colour(3, 0);
printf(" c close Close the BBS for users\n");
printf(" o open Open the BBS for users\n");
printf(" s set semafore Set named semafore\n");
printf(" w wait Wait until the BBS is free\n\n");
mbse_colour(9,0);
printf(" Options are:\n\n");
mbse_colour(3, 0);
printf(" -q -quiet Quiet, no screen output\n");
mbse_colour(7, 0);
die(MBERR_COMMANDLINE);
mbse_colour(LIGHTCYAN, BLACK);
printf("\nUsage: mbstat [command] <options>\n\n");
mbse_colour(LIGHTBLUE, BLACK);
printf(" Commands are:\n\n");
mbse_colour(CYAN, BLACK);
printf(" c close Close the BBS for users\n");
printf(" o open Open the BBS for users\n");
printf(" s set semafore Set named semafore\n");
printf(" w wait Wait until the BBS is free\n\n");
mbse_colour(LIGHTBLUE, BLACK);
printf(" Options are:\n\n");
mbse_colour(CYAN, BLACK);
printf(" -q -quiet Quiet, no screen output\n");
mbse_colour(LIGHTGRAY, BLACK);
die(MBERR_COMMANDLINE);
}
void ProgName(void)
{
if (do_quiet)
return;
if (do_quiet)
return;
mbse_colour(15, 0);
printf("\nMBSTAT: MBSE BBS %s Status Changer\n", VERSION);
mbse_colour(14, 0);
printf(" %s\n", COPYRIGHT);
mbse_colour(3, 0);
mbse_colour(WHITE, BLACK);
printf("\nMBSTAT: MBSE BBS %s Status Changer\n", VERSION);
mbse_colour(YELLOW, BLACK);
printf(" %s\n", COPYRIGHT);
mbse_colour(CYAN, BLACK);
}
void die(int onsig)
{
signal(onsig, SIG_IGN);
signal(onsig, SIG_IGN);
if (onsig)
WriteError("Terminated on signal %d", onsig);
if (onsig)
WriteError("Terminated on signal %d", onsig);
if (!do_quiet) {
mbse_colour(7, 0);
printf("\n");
}
if (!do_quiet) {
mbse_colour(LIGHTGRAY, BLACK);
printf("\n");
}
t_end = time(NULL);
Syslog(' ', "MBSTAT finished in %s", t_elapsed(t_start, t_end));
t_end = time(NULL);
Syslog(' ', "MBSTAT finished in %s", t_elapsed(t_start, t_end));
ExitClient(onsig);
ExitClient(onsig);
}
int main(int argc, char **argv)
{
int i;
char *cmd, *semafore = NULL;
int do_open = FALSE;
int do_close = FALSE;
int do_wait = FALSE;
int do_sema = FALSE;
struct passwd *pw;
int i;
char *cmd, *semafore = NULL;
int do_open = FALSE;
int do_close = FALSE;
int do_wait = FALSE;
int do_sema = FALSE;
struct passwd *pw;
InitConfig();
mbse_TermInit(1, 80, 24);
t_start = time(NULL);
InitConfig();
mbse_TermInit(1, 80, 24);
t_start = time(NULL);
/*
* Catch or ignore signals
*/
for (i = 0; i < NSIG; i++) {
if ((i == SIGHUP) || (i == SIGINT) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM))
signal(i, (void (*))die);
else if ((i != SIGKILL) && (i != SIGSTOP))
signal(i, SIG_IGN);
/*
* Catch or ignore signals
*/
for (i = 0; i < NSIG; i++) {
if ((i == SIGHUP) || (i == SIGINT) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM))
signal(i, (void (*))die);
else if ((i != SIGKILL) && (i != SIGSTOP))
signal(i, SIG_IGN);
}
cmd = xstrcpy((char *)"Command line: mbstat");
for (i = 1; i < argc; i++) {
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, tl(argv[i]));
if (!strncmp(tl(argv[i]), "w", 1))
do_wait = TRUE;
if (!strncmp(tl(argv[i]), "o", 1))
do_open = TRUE;
if (!strncmp(tl(argv[i]), "c", 1))
do_close = TRUE;
if (!strncmp(tl(argv[i]), "s", 1)) {
do_sema = TRUE;
i++;
semafore = xstrcpy(tl(argv[i]));
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, tl(argv[i]));
}
if (!strncmp(tl(argv[i]), "-q", 2))
do_quiet = TRUE;
}
cmd = xstrcpy((char *)"Command line: mbstat");
for (i = 1; i < argc; i++) {
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, tl(argv[i]));
if (!strncmp(tl(argv[i]), "w", 1))
do_wait = TRUE;
if (!strncmp(tl(argv[i]), "o", 1))
do_open = TRUE;
if (!strncmp(tl(argv[i]), "c", 1))
do_close = TRUE;
if (!strncmp(tl(argv[i]), "s", 1)) {
do_sema = TRUE;
i++;
semafore = xstrcpy(tl(argv[i]));
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, tl(argv[i]));
}
if (!strncmp(tl(argv[i]), "-q", 2))
do_quiet = TRUE;
}
ProgName();
pw = getpwuid(getuid());
InitClient(pw->pw_name, (char *)"mbstat", CFG.location, CFG.logfile,
ProgName();
pw = getpwuid(getuid());
InitClient(pw->pw_name, (char *)"mbstat", CFG.location, CFG.logfile,
CFG.util_loglevel, CFG.error_log, CFG.mgrlog, CFG.debuglog);
Syslog(' ', " ");
Syslog(' ', "MBSTAT v%s", VERSION);
Syslog(' ', cmd);
free(cmd);
Syslog(' ', " ");
Syslog(' ', "MBSTAT v%s", VERSION);
Syslog(' ', cmd);
free(cmd);
if (!do_quiet) {
mbse_colour(3, 0);
printf("\n");
}
if (!do_quiet) {
mbse_colour(CYAN, BLACK);
printf("\n");
}
if (do_close)
do_open = FALSE;
if (do_close)
do_open = FALSE;
if (do_open) {
Open();
do_close = FALSE;
do_wait = FALSE;
}
if (do_open) {
Open();
do_close = FALSE;
do_wait = FALSE;
}
if (do_close)
Close();
if (do_close)
Close();
if (do_wait)
Wait();
if (do_wait)
Wait();
if (do_sema)
Semafore(semafore);
if (do_sema)
Semafore(semafore);
if (!(do_open || do_close || do_wait || do_sema))
Help();
if (!(do_open || do_close || do_wait || do_sema))
Help();
die(MBERR_OK);
return 0;
die(MBERR_OK);
return 0;
}
int Semafore(char *semafore)
{
char buf[81];
char buf[81];
strcpy(buf, SockR("SECR:1,%s;", semafore));
if (strncmp(buf, "100:0;", 6) == 0) {
Syslog('+', "Semafore \"%s\" is set", semafore);
if (!do_quiet)
printf("Semafore \"%s\" is set\n", semafore);
return TRUE;
} else {
Syslog('+', "Failed to set \"%s\" semafore", semafore);
printf("Failed to set \"%s\" semafore\n", semafore);
return FALSE;
}
strcpy(buf, SockR("SECR:1,%s;", semafore));
if (strncmp(buf, "100:0;", 6) == 0) {
Syslog('+', "Semafore \"%s\" is set", semafore);
if (!do_quiet)
printf("Semafore \"%s\" is set\n", semafore);
return TRUE;
} else {
Syslog('+', "Failed to set \"%s\" semafore", semafore);
printf("Failed to set \"%s\" semafore\n", semafore);
return FALSE;
}
}
int Close(void)
{
char buf[81];
char buf[81];
strcpy(buf, SockR("SCLO:0;"));
if (strncmp(buf, "100:0;", 6) == 0) {
Syslog('+', "The BBS is closed");
if (!do_quiet)
printf("The BBS is closed\n");
return TRUE;
} else {
printf("Failed to close the BBS\n");
return FALSE;
}
strcpy(buf, SockR("SCLO:0;"));
if (strncmp(buf, "100:0;", 6) == 0) {
Syslog('+', "The BBS is closed");
if (!do_quiet)
printf("The BBS is closed\n");
return TRUE;
} else {
printf("Failed to close the BBS\n");
return FALSE;
}
}
int Open(void)
{
char buf[81];
char buf[81];
strcpy(buf, SockR("SOPE:0;"));
if (strncmp(buf, "100:0;", 6) == 0) {
Syslog('+', "The BBS is open");
if (!do_quiet)
printf("The BBS is open\n");
return TRUE;
} else {
printf("Failed to open the BBS\n");
return FALSE;
}
strcpy(buf, SockR("SOPE:0;"));
if (strncmp(buf, "100:0;", 6) == 0) {
Syslog('+', "The BBS is open");
if (!do_quiet)
printf("The BBS is open\n");
return TRUE;
} else {
printf("Failed to open the BBS\n");
return FALSE;
}
}
int Wait(void)
{
int Waiting = 3600;
char buf[PATH_MAX];
int Waiting = 3600;
char buf[PATH_MAX];
if (IsSema((char *)"upsdown"))
Waiting = 30;
if (IsSema((char *)"upsdown"))
Waiting = 30;
Syslog('+', "Waiting for the BBS to become free, timeout %d seconds", Waiting);
while (Waiting) {
strcpy(buf, SockR("SFRE:0;"));
if (strncmp(buf, "100:0;", 6) == 0) {
Syslog('+', "The BBS is free");
if (!do_quiet)
printf("The BBS is free. \n");
return TRUE;
}
if (!do_quiet) {
buf[strlen(buf) -1] = '\0';
printf("\r%s\r", buf+6);
fflush(stdout);
}
sleep(1);
Waiting--;
Syslog('+', "Waiting for the BBS to become free, timeout %d seconds", Waiting);
while (Waiting) {
strcpy(buf, SockR("SFRE:0;"));
if (strncmp(buf, "100:0;", 6) == 0) {
Syslog('+', "The BBS is free");
if (!do_quiet)
printf("The BBS is free. \n");
return TRUE;
}
if (!do_quiet) {
buf[strlen(buf) -1] = '\0';
printf("\r%s\r", buf+6);
fflush(stdout);
}
sleep(1);
Waiting--;
}
WriteError("Wait for BBS free timeout, aborting");
return FALSE;
WriteError("Wait for BBS free timeout, aborting");
return FALSE;
}

View File

@ -4,7 +4,7 @@
* Purpose ...............: User Pack Util
*
*****************************************************************************
* Copyright (C) 1997-2004
* Copyright (C) 1997-2005
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
@ -111,7 +111,7 @@ int main(int argc, char **argv)
oldmask = umask(027);
if (!do_quiet)
mbse_colour(3, 0);
mbse_colour(CYAN, BLACK);
UserPack(Days, Level, pack);
umask(oldmask);
@ -120,7 +120,7 @@ int main(int argc, char **argv)
Syslog(' ', "MBUSER finished in %s", t_elapsed(t_start, t_end));
if (!do_quiet)
mbse_colour(7, 0);
mbse_colour(LIGHTGRAY, BLACK);
ExitClient(MBERR_OK);
return 0;
}
@ -132,38 +132,38 @@ int main(int argc, char **argv)
*/
void ProgName(void)
{
if (do_quiet)
return;
if (do_quiet)
return;
mbse_colour(15, 0);
printf("\nMBUSER: MBSE BBS %s - User maintenance utility\n", VERSION);
mbse_colour(14, 0);
printf(" %s\n\n", COPYRIGHT);
mbse_colour(7, 0);
mbse_colour(WHITE, BLACK);
printf("\nMBUSER: MBSE BBS %s - User maintenance utility\n", VERSION);
mbse_colour(YELLOW, BLACK);
printf(" %s\n\n", COPYRIGHT);
mbse_colour(LIGHTGRAY, BLACK);
}
void Help(void)
{
do_quiet = FALSE;
ProgName();
do_quiet = FALSE;
ProgName();
mbse_colour(11, 0);
printf("\nUsage: mbuser [commands] <options>\n\n");
mbse_colour(9, 0);
printf(" Commands are:\n\n");
mbse_colour(3, 0);
printf(" kill [n] [l] Kill users not called in \"n\" days below level \"l\"\n");
printf(" pack Pack the userbase\n");
mbse_colour(9, 0);
printf("\n Options are:\n\n");
mbse_colour(3, 0);
printf(" -quiet Quiet mode, (no screen output)\n\n");
mbse_colour(LIGHTCYAN, BLACK);
printf("\nUsage: mbuser [commands] <options>\n\n");
mbse_colour(LIGHTBLUE, BLACK);
printf(" Commands are:\n\n");
mbse_colour(CYAN, BLACK);
printf(" kill [n] [l] Kill users not called in \"n\" days below level \"l\"\n");
printf(" pack Pack the userbase\n");
mbse_colour(LIGHTBLUE, BLACK);
printf("\n Options are:\n\n");
mbse_colour(CYAN, BLACK);
printf(" -quiet Quiet mode, (no screen output)\n\n");
mbse_colour(7, 0);
printf("\n");
ExitClient(MBERR_COMMANDLINE);
mbse_colour(LIGHTGRAY, BLACK);
printf("\n");
ExitClient(MBERR_COMMANDLINE);
}
@ -173,224 +173,219 @@ void Help(void)
*/
void UserPack(int days, int level, int pack)
{
FILE *fin, *fout;
char *fnin, *fnout;
long oldsize, curpos;
int updated, delete = 0, rc, highest = 0, record = 0, sysop = FALSE;
time_t Last;
char *cmd;
FILE *fin, *fout;
char *fnin, *fnout, *cmd;
long oldsize, curpos;
int updated, delete = 0, rc, highest = 0, record = 0, sysop = FALSE;
time_t Last;
fnin = calloc(PATH_MAX, sizeof(char));
fnout = calloc(PATH_MAX, sizeof(char));
sprintf(fnin, "%s/etc/users.data", getenv("MBSE_ROOT"));
sprintf(fnout, "%s/etc/users.temp", getenv("MBSE_ROOT"));
fnin = calloc(PATH_MAX, sizeof(char));
fnout = calloc(PATH_MAX, sizeof(char));
sprintf(fnin, "%s/etc/users.data", getenv("MBSE_ROOT"));
sprintf(fnout, "%s/etc/users.temp", getenv("MBSE_ROOT"));
/*
* First copy the users database, all packing will be done
* on a the copy.
*/
if ((fin = fopen(fnin, "r")) == NULL) {
WriteError("Can't open %s", fnin);
free(fnin);
free(fnout);
return;
}
if ((fout = fopen(fnout, "w+")) == NULL) {
WriteError("Can't create %s", fnout);
fclose(fin);
free(fnin);
free(fnout);
return;
}
fread(&usrhdr, sizeof(usrhdr), 1, fin);
oldsize = usrhdr.recsize;
updated = FALSE;
/*
* First count records and blanks at the end. Check if the sysop name
* in the main configuration exists in the userdatabase.
*/
while (fread(&usr, oldsize, 1,fin) == 1) {
delete++;
if (!usr.Deleted && strlen(usr.sUserName)) {
highest = (ftell(fin) / oldsize);
if (!strcmp(usr.sUserName, CFG.sysop_name) && !strcmp(usr.Name, CFG.sysop))
sysop = TRUE;
}
}
if (highest != delete) {
Syslog('+', "Blank records at the end, truncating userbase");
updated = TRUE;
}
if (!sysop)
WriteError("No valid Sysop Fidoname and/or Unixname found in userbase, check setup!");
fseek(fin, usrhdr.hdrsize, SEEK_SET);
if (oldsize != sizeof(usr)) {
updated = TRUE;
Syslog('+', "Userbase recordsize is changed, making update");
}
usrhdr.hdrsize = sizeof(usrhdr);
usrhdr.recsize = sizeof(usr);
fwrite(&usrhdr, sizeof(usrhdr), 1, fout);
/*
* The datarecord is filled with zero's before each read
* so that if the record format changed, the new fields will
* be empty by default. The blank records at the end of the
* database are dropped.
*/
memset(&usr, 0, sizeof(usr));
while (fread(&usr, oldsize, 1,fin) == 1) {
record++;
fwrite(&usr, sizeof(usr), 1, fout);
memset(&usr, 0, sizeof(usr));
if (CFG.slow_util && do_quiet)
msleep(1);
Nopper();
}
/*
* First copy the users database, all packing will be done
* on a the copy.
*/
if ((fin = fopen(fnin, "r")) == NULL) {
WriteError("$Can't open %s", fnin);
free(fnin);
free(fnout);
return;
}
if ((fout = fopen(fnout, "w+")) == NULL) {
WriteError("$Can't create %s", fnout);
fclose(fin);
delete = 0;
free(fnin);
free(fnout);
return;
}
fread(&usrhdr, sizeof(usrhdr), 1, fin);
oldsize = usrhdr.recsize;
updated = FALSE;
/*
* Handle packing for days below level
*/
if ((days) && (level)) {
fseek(fout, sizeof(usrhdr), SEEK_SET);
curpos = sizeof(usrhdr);
/*
* First count records and blanks at the end. Check if the sysop name
* in the main configuration exists in the userdatabase.
*/
while (fread(&usr, oldsize, 1,fin) == 1) {
delete++;
if (!usr.Deleted && strlen(usr.sUserName)) {
highest = (ftell(fin) / oldsize);
if (!strcmp(usr.sUserName, CFG.sysop_name) && !strcmp(usr.Name, CFG.sysop))
sysop = TRUE;
}
}
if (highest != delete) {
Syslog('+', "Blank records at the end, truncating userbase");
updated = TRUE;
}
if (!sysop)
WriteError("No valid Sysop Fidoname and/or Unixname found in userbase, check setup!");
while (fread(&usr, sizeof(usr), 1, fout) == 1) {
/*
* New users don't have the last login date set yet,
* use the registration date instead.
*/
if (usr.iTotalCalls == 0)
Last = usr.tFirstLoginDate;
else
Last = usr.tLastLoginDate;
fseek(fin, usrhdr.hdrsize, SEEK_SET);
/*
* Wow, killing on the second exact!. Don't kill
* the guest accounts.
*/
if ((((t_start - Last) / 86400) > days) &&
(usr.Security.level < level) && (!usr.Guest) &&
if (oldsize != sizeof(usr)) {
updated = TRUE;
Syslog('+', "Userbase recordsize is changed, making update");
}
usrhdr.hdrsize = sizeof(usrhdr);
usrhdr.recsize = sizeof(usr);
fwrite(&usrhdr, sizeof(usrhdr), 1, fout);
/*
* The datarecord is filled with zero's before each read
* so that if the record format changed, the new fields will
* be empty by default. The blank records at the end of the
* database are dropped.
*/
memset(&usr, 0, sizeof(usr));
while (fread(&usr, oldsize, 1,fin) == 1) {
record++;
fwrite(&usr, sizeof(usr), 1, fout);
memset(&usr, 0, sizeof(usr));
if (CFG.slow_util && do_quiet)
msleep(1);
Nopper();
}
fclose(fin);
delete = 0;
/*
* Handle packing for days below level
*/
if (days && level) {
fseek(fout, sizeof(usrhdr), SEEK_SET);
curpos = sizeof(usrhdr);
while (fread(&usr, sizeof(usr), 1, fout) == 1) {
/*
* New users don't have the last login date set yet,
* use the registration date instead.
*/
if (usr.iTotalCalls == 0)
Last = usr.tFirstLoginDate;
else
Last = usr.tLastLoginDate;
/*
* Wow, killing on the second exact!. Don't kill the guest accounts.
*/
if ((((t_start - Last) / 86400) > days) && (usr.Security.level < level) && (!usr.Guest) &&
(usr.sUserName[0] != '\0') && (!usr.NeverDelete)) {
Syslog('+', "Mark user %s", usr.sUserName);
if (!do_quiet) {
printf("Mark user %s\n", usr.sUserName);
fflush(stdout);
}
delete++;
updated = TRUE;
fseek(fout, - sizeof(usr), SEEK_CUR);
/*
* Just mark for deletion
*/
usr.Deleted = TRUE;
fwrite(&usr, sizeof(usr), 1, fout);
}
if (CFG.slow_util && do_quiet)
msleep(1);
Syslog('+', "Mark user %s", usr.sUserName);
if (!do_quiet) {
printf("Mark user %s\n", usr.sUserName);
fflush(stdout);
}
Syslog('+', "Marked %d users to delete", delete);
}
delete++;
updated = TRUE;
fseek(fout, - sizeof(usr), SEEK_CUR);
/*
* Just mark for deletion
*/
usr.Deleted = TRUE;
fwrite(&usr, sizeof(usr), 1, fout);
}
if (CFG.slow_util && do_quiet)
msleep(1);
}
Syslog('+', "Marked %d users to delete", delete);
}
/*
* Pack the userbase if told so
*/
if (pack) {
Syslog('+', "Packing userbase");
delete = 0;
fseek(fout, sizeof(usrhdr), SEEK_SET);
while (fread(&usr, sizeof(usr), 1, fout) == 1) {
if (CFG.slow_util && do_quiet)
msleep(1);
/*
* Pack the userbase if told so
*/
if (pack) {
Syslog('+', "Packing userbase");
delete = 0;
fseek(fout, sizeof(usrhdr), SEEK_SET);
while (fread(&usr, sizeof(usr), 1, fout) == 1) {
if (CFG.slow_util && do_quiet)
msleep(1);
Nopper();
if (usr.Deleted) {
if (!do_quiet) {
printf("Delete user %s\n", usr.Name);
fflush(stdout);
}
if (usr.Name[0] != '\0') {
if ((setuid(0) == -1) || (setgid(0) == -1)) {
WriteError("Cannot setuid(root) or setgid(root)");
WriteError("Cannot delete unix account %s", usr.Name);
} else {
Nopper();
if (usr.Deleted) {
if (!do_quiet) {
printf("Delete user %s\n", usr.Name);
fflush(stdout);
}
if (usr.Name[0] != '\0') {
if ((setuid(0) == -1) || (setgid(0) == -1)) {
WriteError("Cannot setuid(root) or setgid(root)");
WriteError("Cannot delete unix account %s", usr.Name);
} else {
#ifndef __FreeBSD__
rc = execute_str((char *)"/usr/sbin/userdel ", usr.Name, NULL,
rc = execute_str((char *)"/usr/sbin/userdel ", usr.Name, NULL,
(char *)"/dev/null",(char *)"/dev/null",(char *)"/dev/null");
#else
rc = execute_str((char *)"/usr/sbin/pw userdel ", usr.Name, NULL,
rc = execute_str((char *)"/usr/sbin/pw userdel ", usr.Name, NULL,
(char *)"/dev/null",(char *)"/dev/null",(char *)"/dev/null");
#endif
#ifdef _VPOPMAIL_PATH
cmd = xstrcpy((char *)_VPOPMAIL_PATH);
cmd = xstrcat(cmd, (char *)"/vdeluser ");
rc = execute_str(cmd, usr.Name, NULL,
(char *)"/dev/null",(char *)"/dev/null",(char *)"/dev/null");
free(cmd);
cmd = xstrcpy((char *)_VPOPMAIL_PATH);
cmd = xstrcat(cmd, (char *)"/vdeluser ");
rc = execute_str(cmd, usr.Name, NULL, (char *)"/dev/null",(char *)"/dev/null",(char *)"/dev/null");
free(cmd);
#endif
if (chdir(CFG.bbs_usersdir) == 0) {
cmd = xstrcpy((char *)"-Rf ");
cmd = xstrcat(cmd, usr.Name);
rc = execute_pth((char *)"rm", cmd,
(char *)"/dev/null",(char *)"/dev/null",(char *)"/dev/null");
free(cmd);
}
}
}
fseek(fout, - sizeof(usr), SEEK_CUR);
/*
* Blank the deleted records for reuse.
*/
memset(&usr, 0, sizeof(usr));
fwrite(&usr, sizeof(usr), 1, fout);
delete++;
updated = TRUE;
if (chdir(CFG.bbs_usersdir) == 0) {
cmd = xstrcpy((char *)"-Rf ");
cmd = xstrcat(cmd, usr.Name);
rc = execute_pth((char *)"rm", cmd, (char *)"/dev/null",(char *)"/dev/null",(char *)"/dev/null");
free(cmd);
}
}
}
Syslog('+', "Deleted %d records", delete);
}
if (updated) {
fseek(fout, - sizeof(usr), SEEK_CUR);
/*
* Copy file back to the original file, truncate any
* deleted records at the end.
* Blank the deleted records for reuse.
*/
fseek(fout, 0, SEEK_SET);
if ((fin = fopen(fnin, "w")) == NULL) {
WriteError("Can't open %s", fnin);
free(fnin);
free(fnout);
return;
}
fread(&usrhdr, sizeof(usrhdr), 1, fout);
fwrite(&usrhdr, sizeof(usrhdr), 1, fin);
record = 0;
while (fread(&usr, sizeof(usr), 1,fout) == 1) {
Nopper();
record++;
fwrite(&usr, sizeof(usr), 1, fin);
if (record >= highest)
break;
}
fclose(fin);
fclose(fout);
chmod(fnin, 0660);
Syslog('+', "Userbase is updated, written %d records", record);
} else {
fclose(fout);
memset(&usr, 0, sizeof(usr));
fwrite(&usr, sizeof(usr), 1, fout);
delete++;
updated = TRUE;
}
}
Syslog('+', "Deleted %d records", delete);
}
unlink(fnout);
free(fnin);
free(fnout);
if (updated) {
/*
* Copy file back to the original file, truncate any
* deleted records at the end.
*/
fseek(fout, 0, SEEK_SET);
if ((fin = fopen(fnin, "w")) == NULL) {
WriteError("$Can't open %s", fnin);
free(fnin);
free(fnout);
return;
}
fread(&usrhdr, sizeof(usrhdr), 1, fout);
fwrite(&usrhdr, sizeof(usrhdr), 1, fin);
record = 0;
while (fread(&usr, sizeof(usr), 1,fout) == 1) {
Nopper();
record++;
fwrite(&usr, sizeof(usr), 1, fin);
if (record >= highest)
break;
}
fclose(fin);
fclose(fout);
chmod(fnin, 0660);
Syslog('+', "Userbase is updated, written %d records", record);
} else {
fclose(fout);
}
unlink(fnout);
free(fnin);
free(fnout);
}