sbbsecho.c 147 KB
Newer Older
1
/* sbbsecho.c */
2

3
/* Synchronet FidoNet EchoMail Scanning/Tossing and NetMail Tossing Utility */
4

5
6
7
8
9
10
/* $Id$ */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
rswindell's avatar
rswindell committed
11
 * Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html		*
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 *																			*
 * This program 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			*
 * of the License, or (at your option) any later version.					*
 * See the GNU General Public License for more details: gpl.txt or			*
 * http://www.fsf.org/copyleft/gpl.html										*
 *																			*
 * Anonymous FTP access to the most recent released source is available at	*
 * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net	*
 *																			*
 * Anonymous CVS access to the development source and modification history	*
 * is available at cvs.synchro.net:/cvsroot/sbbs, example:					*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login			*
 *     (just hit return, no password is necessary)							*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src		*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * You are encouraged to submit any modifications (preferably in Unix diff	*
 * format) via e-mail to mods@synchro.net									*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/
37

38
/* Portions written by Allen Christiansen 1994-1996 						*/
39
40
41
42
43
44
45
46
47
48
49
50
51

#ifdef _WIN32
	#include <windows.h>
#endif

#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <ctype.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
52
#include <sys/stat.h>
53
54
55
56
57

#ifdef __WATCOMC__
	#include <mem.h>
#endif

58
#ifndef __unix__
59
60
61
	#include <malloc.h>
#endif

rswindell's avatar
rswindell committed
62
#include "conwrap.h"		/* getch() */
63
64
65
66
67
68
#include "sbbs.h"			/* load_cfg() */
#include "sbbsdefs.h"
#include "smblib.h"
#include "scfglib.h"
#include "lzh.h"
#include "sbbsecho.h"
deuce's avatar
deuce committed
69
#include "genwrap.h"		/* PLATFORM_DESC */
70
71
72
73
74
75
76
77
78
79

smb_t *smb,*email;
long misc=(IMPORT_PACKETS|IMPORT_NETMAIL|IMPORT_ECHOMAIL|EXPORT_ECHOMAIL
			|DELETE_NETMAIL|DELETE_PACKETS);
ulong netmail=0;
char tmp[256],pkt_type=0;
int secure,cur_smb=0;
FILE *fidologfile=NULL;
two_two_t two_two;
two_plus_t two_plus;
80
BOOL twit_list;
81

82
faddr_t		sys_faddr = {1,1,1,0};		/* Default system address: 1:1/1.0 */
83
84
config_t	cfg;
scfg_t		scfg;
85
char		revision[16];
86
char		compiler[32];
87

88
BOOL pause_on_exit=FALSE;
89
90
91
92
93
94
95
96

#ifndef __NT__
#define delfile(x) remove(x)
#else
int delfile(char *filename)
{
	int i=0;

97
98
99
	while(remove(filename) && i++<120)	/* Wait up to 60 seconds to delete file */
		delay(500); 					/* for Win95 bug fix */
	return(i);
100
101
102
}
#endif

103
#if defined(__unix__)	/* borrowed from MSVC */
rswindell's avatar
rswindell committed
104
unsigned _rotr (
105
106
107
108
        unsigned val,
        int shift
        )
{
109
110
111
112
113
114
115
116
117
118
119
    register unsigned lobit;        /* non-zero means lo bit set */
    register unsigned num = val;    /* number to rotate */

    shift &= 0x1f;                  /* modulo 32 -- this will also make
                                       negative shifts work */
    while (shift--) {
	    lobit = num & 1;        /* get high bit */
        num >>= 1;              /* shift right one bit */
        if (lobit)
			num |= 0x80000000;  /* set hi bit if lo bit was set */
	}
120

121
    return num;
122
123
124
}
#endif

rswindell's avatar
rswindell committed
125
/****************************************************************************/
126
/* This is needed by load_cfg.c												*/
rswindell's avatar
rswindell committed
127
/****************************************************************************/
128
int lprintf(int level, char *fmat, ...)
rswindell's avatar
rswindell committed
129
130
131
132
133
134
{
	va_list argptr;
	char sbuf[256];
	int chcount;

	va_start(argptr,fmat);
135
	chcount=vsnprintf(sbuf,sizeof(sbuf),fmat,argptr);
136
	sbuf[sizeof(sbuf)-1]=0;
rswindell's avatar
rswindell committed
137
	va_end(argptr);
138
139
	truncsp(sbuf);
	printf("%s\n",sbuf);
rswindell's avatar
rswindell committed
140
141
142
	return(chcount);
}

143
144
145
146
147
148
149
150
151
152
/**********************/
/* Log print function */
/**********************/
void logprintf(char *str, ...)
{
    va_list argptr;
    char buf[256];
    time_t now;
    struct tm *gm;

153
154
155
156
157
158
159
160
	if(!(misc&LOGFILE) || fidologfile==NULL)
		return;
	va_start(argptr,str);
	vsnprintf(buf,sizeof(buf),str,argptr);
	buf[sizeof(buf)-1]=0;
	va_end(argptr);
	now=time(NULL);
	gm=localtime(&now);
161
	fprintf(fidologfile,"%02u/%02u/%02u %02u:%02u:%02u %s\n"
162
163
		,gm->tm_mon+1,gm->tm_mday,TM_YEAR(gm->tm_year),gm->tm_hour,gm->tm_min,gm->tm_sec
		,buf);
164
165
166
167
168
}

/*****************************************************************************/
/* Returns command line generated from instr with %c replacments             */
/*****************************************************************************/
169
char *mycmdstr(scfg_t* cfg, char *instr, char *fpath, char *fspec)
170
{
171
    static char cmd[MAX_PATH+1];
172
173
174
    char str[256],str2[128];
    int i,j,len;

175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
	len=strlen(instr);
	for(i=j=0;i<len && j<128;i++) {
		if(instr[i]=='%') {
			i++;
			cmd[j]=0;
			switch(toupper(instr[i])) {
				case 'F':   /* File path */
					strcat(cmd,fpath);
					break;
				case 'G':   /* Temp directory */
					if(cfg->temp_dir[0]!='\\' 
						&& cfg->temp_dir[0]!='/' 
						&& cfg->temp_dir[1]!=':') {
						strcpy(str,cfg->node_dir);
						strcat(str,cfg->temp_dir);
						if(FULLPATH(str2,str,40))
							strcpy(str,str2);
						backslash(str);
						strcat(cmd,str);}
					else
						strcat(cmd,cfg->temp_dir);
					break;
				case 'J':
					if(cfg->data_dir[0]!='\\' 
						&& cfg->data_dir[0]!='/' 
						&& cfg->data_dir[1]!=':') {
						strcpy(str,cfg->node_dir);
						strcat(str,cfg->data_dir);
						if(FULLPATH(str2,str,40))
							strcpy(str,str2);
						backslash(str);
						strcat(cmd,str); }
					else
						strcat(cmd,cfg->data_dir);
					break;
				case 'K':
					if(cfg->ctrl_dir[0]!='\\' 
						&& cfg->ctrl_dir[0]!='/' 
						&& cfg->ctrl_dir[1]!=':') {
						strcpy(str,cfg->node_dir);
						strcat(str,cfg->ctrl_dir);
						if(FULLPATH(str2,str,40))
							strcpy(str,str2);
						backslash(str);
						strcat(cmd,str); }
					else
						strcat(cmd,cfg->ctrl_dir);
					break;
				case 'N':   /* Node Directory (same as SBBSNODE environment var) */
					strcat(cmd,cfg->node_dir);
					break;
				case 'O':   /* SysOp */
					strcat(cmd,cfg->sys_op);
					break;
				case 'Q':   /* QWK ID */
					strcat(cmd,cfg->sys_id);
					break;
				case 'S':   /* File Spec */
					strcat(cmd,fspec);
					break;
				case '!':   /* EXEC Directory */
236
					strcat(cmd,cfg->exec_dir);
237
					break;
238
239
240
241
242
                case '@':   /* EXEC Directory for DOS/OS2/Win32, blank for Unix */
#ifndef __unix__
                    strcat(cmd,cfg->exec_dir);
#endif
                    break;
243
244
245
246
247
248
249
250
251
252
253
				case '#':   /* Node number (same as SBBSNNUM environment var) */
					sprintf(str,"%d",cfg->node_num);
					strcat(cmd,str);
					break;
				case '*':
					sprintf(str,"%03d",cfg->node_num);
					strcat(cmd,str);
					break;
				case '%':   /* %% for percent sign */
					strcat(cmd,"%");
					break;
254
255
256
257
258
259
260
261
262
263
264
265
266
267
				case '.':	/* .exe for DOS/OS2/Win32, blank for Unix */
#ifndef __unix__
					strcat(cmd,".exe");
#endif
					break;
				case '?':	/* Platform */
#ifdef __OS2__
					strcpy(str,"OS2");
#else
					strcpy(str,PLATFORM_DESC);
#endif
					strlwr(str);
					strcat(cmd,str);
					break;
268
269
270
271
272
273
274
275
276
277
				default:    /* unknown specification */
					printf("ERROR Checking Command Line '%s'\n",instr);
					logprintf("ERROR line %d Checking Command Line '%s'",__LINE__
						,instr);
					bail(1);
					break; }
			j=strlen(cmd); }
		else
			cmd[j++]=instr[i]; }
	cmd[j]=0;
278

279
	return(cmd);
280
281
282
283
284
285
286
}

/****************************************************************************/
/* Runs an external program directly using spawnvp							*/
/****************************************************************************/
int execute(char *cmdline)
{
rswindell's avatar
rswindell committed
287
#if 1
288
	return system(cmdline);
rswindell's avatar
rswindell committed
289
#else
290
291
292
293
294
295
296
	char c,d,e,cmdlen,*arg[30],str[256];
	int i;

	strcpy(str,cmdline);
	arg[0]=str;	/* point to the beginning of the string */
	cmdlen=strlen(str);
	for(c=0,d=1,e=0;c<cmdlen;c++,e++)	/* Break up command line */
297
		if(str[c]==' ') {
298
299
300
301
302
303
			str[c]=0;			/* insert nulls */
			arg[d++]=str+c+1;	/* point to the beginning of the next arg */
			e=0; }
	arg[d]=0;
	i=spawnvp(P_WAIT,arg[0],arg);
	return(i);
rswindell's avatar
rswindell committed
304
#endif
305
}
306

307
308
309
310
311
312
/******************************************************************************
 Returns the system address with the same zone as the address passed
******************************************************************************/
faddr_t getsysfaddr(short zone)
{
	int i;
313

314
315
316
	for(i=0;i<scfg.total_faddrs;i++)
		if(scfg.faddr[i].zone==zone)
			return(scfg.faddr[i]);
317
	return(sys_faddr);
318
}
319

320
321
322
323
324
/******************************************************************************
 This function creates or appends on existing Binkley compatible .?LO file
 attach file.
 Returns 0 on success.
******************************************************************************/
325
int write_flofile(char *attachment, faddr_t dest, BOOL bundle)
326
{
327
328
329
330
331
	char fname[MAX_PATH+1];
	char outbound[MAX_PATH+1];
	char str[MAX_PATH+1];
	char ch;
	char searchstr[MAX_PATH+1];
332
333
334
335
336
337
338
339
	ushort attr=0;
	int i,file;
	FILE *stream;

	i=matchnode(dest,0);
	if(i<(int)cfg.nodecfgs)
		attr=cfg.nodecfg[i].attr;

rswindell's avatar
rswindell committed
340
341
342
343
	if(attr&ATTR_CRASH) ch='c';
	else if(attr&ATTR_HOLD) ch='h';
	else if(attr&ATTR_DIRECT) ch='d';
	else ch='f';
344
	if(dest.zone==sys_faddr.zone)		/* Default zone, use default outbound */
345
		strcpy(outbound,cfg.outbound);
346
347
	else {								/* Inter-zone outbound is OUTBOUND.XXX */
		sprintf(outbound,"%.*s.%03x"
rswindell's avatar
rswindell committed
348
			,(int)strlen(cfg.outbound)-1,cfg.outbound,dest.zone);
349
350
351
		MKDIR(outbound);
		backslash(outbound);
	}
352
	if(dest.point) {					/* Point destination is OUTBOUND\*.PNT */
rswindell's avatar
rswindell committed
353
		sprintf(str,"%04x%04x.pnt"
354
355
			,dest.net,dest.node);
		strcat(outbound,str); }
rswindell's avatar
rswindell committed
356
357
	if(outbound[strlen(outbound)-1]=='\\'
		|| outbound[strlen(outbound)-1]=='/')
358
		outbound[strlen(outbound)-1]=0;
rswindell's avatar
rswindell committed
359
	MKDIR(outbound);
360
	backslash(outbound);
361
	if(dest.point)
rswindell's avatar
rswindell committed
362
		sprintf(fname,"%s%08x.%clo",outbound,dest.point,ch);
363
	else
rswindell's avatar
rswindell committed
364
		sprintf(fname,"%s%04x%04x.%clo",outbound,dest.net,dest.node,ch);
365
366
367
368
	if(bundle && misc&TRUNC_BUNDLES)
		ch='#';
	else
		ch='^';
369
370
371
	if(*attachment == '^')	/* work-around for BRE/FE inter-BBS attachment bug */
		attachment++;
	fexistcase(attachment);	/* just in-case it's the wrong case for a Unix file system */
372
	sprintf(searchstr,"%c%s",ch,attachment);
373
374
	if(findstr(searchstr,fname))	/* file already in FLO file */
		return(0);
375
	if((stream=fopen(fname,"a"))==NULL) {
376
377
		printf("\7ERROR line %d opening %s %s\n",__LINE__,fname,strerror(errno));
		logprintf("ERROR line %d opening %s %s",__LINE__,fname,strerror(errno));
378
379
		return(-1); 
	}
380
	fprintf(stream,"%s\n",searchstr);
381
382
383
384
	fclose(stream);
	return(0);
}

385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
/* Writes text buffer to file, expanding sole LFs to CRLFs */
size_t fwrite_crlf(char* buf, size_t len, FILE* fp)
{
	char	ch,last_ch=0;
	size_t	i;
	size_t	wr=0;	/* total chars written (may be > len) */

	for(i=0;i<len;i++) {
		ch=*buf++;
		if(ch=='\n' && last_ch!='\r') {
			if(fputc('\r',fp)==EOF)
				return(wr);
			wr++;
		}
		if(fputc(ch,fp)==EOF)
			return(wr);
		wr++;
		last_ch=ch;
	}

	return(wr);
}

408
409
410
411
412
/******************************************************************************
 This function will create a netmail message (.MSG format).
 If file is non-zero, will set file attachment bit (for bundles).
 Returns 0 on success.
******************************************************************************/
413
int create_netmail(char *to, char *subject, char *body, faddr_t dest, BOOL file_attached)
414
415
{
	FILE *fstream;
416
	char str[256],fname[MAX_PATH+1];
417
418
419
420
421
422
423
424
425
	ushort attr=0;
	int fmsg;
	uint i;
	static uint startmsg;
	time_t t;
	faddr_t	faddr;
	fmsghdr_t hdr;
	struct tm *tm;

426
427
428
429
430
431
432
433
434
435
436
	if(!startmsg) startmsg=1;
	i=matchnode(dest,0);
	if(i<cfg.nodecfgs) {
		attr=cfg.nodecfg[i].attr;
		if(!attr) {
			i=matchnode(dest,2);
			if(i<cfg.nodecfgs)
				attr=cfg.nodecfg[i].attr; } }

	do {
		for(i=startmsg;i;i++) {
437
			sprintf(fname,"%s%u.msg",scfg.netmail_dir,i);
438
439
440
			if(!fexistcase(fname))
				break; 
		}
441
442
443
444
445
446
		if(!i) {
			printf("\7%s directory full!\n",scfg.netmail_dir);
			logprintf("Directory full: %s",scfg.netmail_dir);
			return(-1); }
		startmsg=i+1;
		if((fstream=fnopen(&fmsg,fname,O_RDWR|O_CREAT))==NULL) {
447
448
			printf("\7ERROR line %d opening %s %s\n",__LINE__,fname,strerror(errno));
			logprintf("ERROR line %d opening %s %s",__LINE__,fname,strerror(errno));
449
			return(-1); }
450

451
452
453
454
455
456
457
458
459
460
461
462
		faddr=getsysfaddr(dest.zone);
		memset(&hdr,0,sizeof(fmsghdr_t));
		hdr.origzone=faddr.zone;
		hdr.orignet=faddr.net;
		hdr.orignode=faddr.node;
		hdr.origpoint=faddr.point;
		hdr.destzone=dest.zone;
		hdr.destnet=dest.net;
		hdr.destnode=dest.node;
		hdr.destpoint=dest.point;

		hdr.attr=(FIDO_PRIVATE|FIDO_KILLSENT|FIDO_LOCAL);
463
		if(file_attached)
464
			hdr.attr|=FIDO_FILE;
465

466
467
468
469
		if(attr&ATTR_HOLD)
			hdr.attr|=FIDO_HOLD;
		if(attr&ATTR_CRASH)
			hdr.attr|=FIDO_CRASH;
470

471
472
473
474
475
476
477
478
479
		sprintf(hdr.from,"SBBSecho");

		t=time(NULL);
		tm=localtime(&t);
		sprintf(hdr.time,"%02u %3.3s %02u  %02u:%02u:%02u"
			,tm->tm_mday,mon[tm->tm_mon],TM_YEAR(tm->tm_year)
			,tm->tm_hour,tm->tm_min,tm->tm_sec);

		if(to)
480
			SAFECOPY(hdr.to,to);
481
		else
482
			SAFECOPY(hdr.to,"SYSOP");
483

484
		SAFECOPY(hdr.subj,subject);
485
486
487
488
489
490

		fwrite(&hdr,sizeof(fmsghdr_t),1,fstream);
		sprintf(str,"\1INTL %hu:%hu/%hu %hu:%hu/%hu\r"
			,hdr.destzone,hdr.destnet,hdr.destnode
			,hdr.origzone,hdr.orignet,hdr.orignode);
		fwrite(str,strlen(str),1,fstream);
491
492
493
494
495
496
497
498

		/* Add FSC-53 FLAGS kludge */
		fprintf(fstream,"\1FLAGS");
		if(attr&ATTR_DIRECT)
			fprintf(fstream," DIR");
		if(file_attached) {
			if(misc&TRUNC_BUNDLES)
				fprintf(fstream," TFS");
499
			else
500
501
502
503
				fprintf(fstream," KFS");
		}
		fprintf(fstream,"\r");

504
505
506
507
508
509
		if(hdr.destpoint) {
			sprintf(str,"\1TOPT %hu\r",hdr.destpoint);
			fwrite(str,strlen(str),1,fstream); }
		if(hdr.origpoint) {
			sprintf(str,"\1FMPT %hu\r",hdr.origpoint);
			fwrite(str,strlen(str),1,fstream); }
510
		if(!file_attached || (!(attr&ATTR_DIRECT) && file_attached))
511
			fwrite_crlf(body,strlen(body)+1,fstream);	/* Write additional NULL */
512
513
514
		else
			fwrite("\0",1,1,fstream);               /* Write NULL */
		fclose(fstream);
515
	} while(!fexistcase(fname));
516
	return(0);
517
518
519
520
521
522
523
524
525
526
527
}

/******************************************************************************
 This function takes the contents of 'infile' and puts it into a netmail
 message bound for addr.
******************************************************************************/
void file_to_netmail(FILE *infile,char *title,faddr_t addr,char *to)
{
	char *buf,*p;
	long l,m,len;

528
529
530
531
	l=len=ftell(infile);
	if(len>8192L)
		len=8192L;
	rewind(infile);
deuce's avatar
deuce committed
532
	if((buf=(char *)malloc(len+1))==NULL) {
533
534
535
536
537
538
539
		printf("ERROR allocating %lu bytes for file to netmail buffer.\n",len);
		logprintf("ERROR line %d allocating %lu for file to netmail buf",__LINE__
			,len);
		return; }
	while((m=fread(buf,1,(len>8064L) ? 8064L:len,infile))>0) {
		buf[m]=0;
		if(l>8064L && (p=strrchr(buf,'\n'))!=NULL) {
540
			p++;
541
542
			if(*p) {
				*p=0;
543
				p++;
544
545
546
547
548
549
				fseek(infile,-1L,SEEK_CUR);
				while(*p) { 			/* Seek back to end of last line */
					p++;
					fseek(infile,-1L,SEEK_CUR); } } }
		if(ftell(infile)<l)
			strcat(buf,"\r\nContinued in next message...\r\n");
550
551
		create_netmail(to,title,buf,addr,FALSE); 
	}
deuce's avatar
deuce committed
552
	free(buf);
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
}
/******************************************************************************
 This function sends a notify list to applicable nodes, this list includes the
 settings configured for the node, as well as a list of areas the node is
 connected to.
******************************************************************************/
void notify_list(void)
{
	FILE *	tmpf;
	char	str[256];
	uint	i,j,k;

	for(k=0;k<cfg.nodecfgs;k++) {

		if(!(cfg.nodecfg[k].attr&SEND_NOTIFY))
			continue;

		if((tmpf=tmpfile())==NULL) {
			printf("\7ERROR couldn't open tmpfile.\n");
			logprintf("ERROR line %d couldn't open tmpfile",__LINE__);
			return; }

		fprintf(tmpf,"Following are the options set for your system and a list "
			"of areas\r\nyou are connected to.  Please make sure everything "
			"is correct.\r\n\r\n");
		fprintf(tmpf,"Packet Type       %s\r\n"
			,cfg.nodecfg[k].pkt_type==PKT_TWO ? "2"
			:cfg.nodecfg[k].pkt_type==PKT_TWO_TWO ? "2.2":"2+");
		fprintf(tmpf,"Archive Type      %s\r\n"
			,(cfg.nodecfg[k].arctype>cfg.arcdefs) ?
			 "None":cfg.arcdef[cfg.nodecfg[k].arctype].name);
		fprintf(tmpf,"Mail Status       %s\r\n"
			,cfg.nodecfg[k].attr&ATTR_CRASH ? "Crash"
			:cfg.nodecfg[k].attr&ATTR_HOLD ? "Hold" : "None");
		fprintf(tmpf,"Direct            %s\r\n"
			,cfg.nodecfg[k].attr&ATTR_DIRECT ? "Yes":"No");
		fprintf(tmpf,"Passive           %s\r\n"
			,cfg.nodecfg[k].attr&ATTR_PASSIVE ? "Yes":"No");
		fprintf(tmpf,"Remote AreaMgr    %s\r\n\r\n"
			,cfg.nodecfg[k].password[0] ? "Yes" : "No");

		fprintf(tmpf,"Connected Areas\r\n---------------\r\n");
		for(i=0;i<cfg.areas;i++) {
			sprintf(str,"%s\r\n",cfg.area[i].name);
			if(str[0]=='*')
				continue;
			for(j=0;j<cfg.area[i].uplinks;j++)
				if(!memcmp(&cfg.nodecfg[k].faddr,&cfg.area[i].uplink[j]
					,sizeof(faddr_t)))
					break;
			if(j<cfg.area[i].uplinks)
				fprintf(tmpf,"%s",str); }

		if(ftell(tmpf))
			file_to_netmail(tmpf,"SBBSecho Notify List",cfg.nodecfg[k].faddr,0);
		fclose(tmpf); }
}
/******************************************************************************
 This function creates a netmail to addr showing a list of available areas (0),
 a list of connected areas (1), or a list of removed areas (2).
******************************************************************************/
614
void netmail_arealist(int type, faddr_t addr)
615
616
{
	FILE *stream,*tmpf;
617
	char str[256],temp[256],title[128],match,*p,*tp;
618
619
620
621
622
623
624
625
626
627
628
629
630
631
	int file,i,j,k,x,y;

	if(!type)
		strcpy(title,"List of Available Areas");
	else if(type==1)
		strcpy(title,"List of Connected Areas");
	else
		strcpy(title,"List of Unlinked Areas");

	if((tmpf=tmpfile())==NULL) {
		printf("\7ERROR couldn't open tmpfile.\n");
		logprintf("ERROR line %d couldn't open tmpfile",__LINE__);
		return; }

632
	if(type==1 || !(misc&ELIST_ONLY)) {
633
634
635
636
637
638
639
		for(i=0;i<cfg.areas;i++) {
			if(type) {
				for(j=0;j<cfg.area[i].uplinks;j++)
					if(!memcmp(&addr,&cfg.area[i].uplink[j],sizeof(faddr_t)))
						break;
				if((type==1 && j<cfg.area[i].uplinks) ||
					(type==2 && j==cfg.area[i].uplinks))
640
						fprintf(tmpf,"%s\r\n",cfg.area[i].name); }
641
			else
642
				fprintf(tmpf,"%s\r\n",cfg.area[i].name); } }
643
644
645
646
647
648
649
650
651
652
653

	if(!type) {
		i=matchnode(addr,0);
		if(i<cfg.nodecfgs) {
			for(j=0;j<cfg.listcfgs;j++) {
				match=0;
				for(k=0;k<cfg.listcfg[j].numflags;k++) {
					if(match) break;
					for(x=0;x<cfg.nodecfg[i].numflags;x++)
						if(!stricmp(cfg.listcfg[j].flag[k].flag
							,cfg.nodecfg[i].flag[x].flag)) {
654
							if((stream=fopen(cfg.listcfg[j].listpath,"r"))==NULL) {
655
656
657
658
								printf("\7ERROR couldn't open %s.\n"
									,cfg.listcfg[j].listpath);
								logprintf("ERROR line %d couldn't open %s %s"
									,__LINE__,cfg.listcfg[j].listpath
659
									,strerror(errno));
660
661
662
								match=1;
								break; }
							while(!feof(stream)) {
663
								if(!fgets(str,sizeof(str),stream))
664
665
									break;
								p=str;
666
								SKIP_WHITESPACE(p);
667
668
								if(*p==';')     /* Ignore Comment Lines */
									continue;
669
670
671
								tp=p;
								FIND_WHITESPACE(tp);
								*tp=0;
672
673
								if(!(misc&ELIST_ONLY)) {
									for(y=0;y<cfg.areas;y++)
674
										if(!stricmp(cfg.area[y].name,p))
675
676
											break;
									if(y==cfg.areas)
677
										fprintf(tmpf,"%s\r\n",p); }
678
								else
679
									fprintf(tmpf,"%s\r\n",p); }
680
681
682
683
684
							fclose(stream);
							match=1;
							break; } } } } }

	if(!ftell(tmpf))
685
		create_netmail(NULL,title,"None.",addr,FALSE);
686
687
688
689
690
691
692
693
694
	else
		file_to_netmail(tmpf,title,addr,0);
	fclose(tmpf);
}
/******************************************************************************
 Imitation of Borland's tempnam function because Watcom doesn't have it
******************************************************************************/
char *tempname(char *dir, char *prefix)
{
695
	char str[MAX_PATH+1],*p;
696
697
	int i;

698
699
700
701
702
703
704
705
706
707
708
709
710
	for(i=0;i<1000;i++) {
		sprintf(str,"%s%s%03u.$$$",dir,prefix,i);
		if(!fexist(str))
			break; }
	if(i>=1000) {
		logprintf("tempnam: too many files");
		return(NULL); }
	p=malloc(strlen(str)+1);
	if(!p) {
		logprintf("tempnam: couldn't malloc %u",strlen(str)+1);
		return(NULL); }
	strcpy(p,str);
	return(p);
711
712
}

rswindell's avatar
rswindell committed
713
int check_elists(char *areatag,faddr_t addr)
714
715
{
	FILE *stream;
716
	char str[1025],quit=0,*p,*tp;
rswindell's avatar
rswindell committed
717
	int i,j,k,x,file,match=0;
718

rswindell's avatar
rswindell committed
719
720
721
722
723
724
725
726
727
	i=matchnode(addr,0);
	if(i<cfg.nodecfgs) {
		for(j=0;j<cfg.listcfgs;j++) {
			quit=0;
			for(k=0;k<cfg.listcfg[j].numflags;k++) {
				if(quit) break;
				for(x=0;x<cfg.nodecfg[i].numflags;x++)
					if(!stricmp(cfg.listcfg[j].flag[k].flag
						,cfg.nodecfg[i].flag[x].flag)) {
728
						if((stream=fopen(cfg.listcfg[j].listpath,"r"))==NULL) {
rswindell's avatar
rswindell committed
729
730
731
732
733
734
735
							printf("\7ERROR couldn't open %s.\n"
								,cfg.listcfg[j].listpath);
							logprintf("ERROR line %d opening %s"
								,__LINE__,cfg.listcfg[j].listpath);
							quit=1;
							break; }
						while(!feof(stream)) {
736
							if(!fgets(str,sizeof(str),stream))
rswindell's avatar
rswindell committed
737
738
								break;
							p=str;
739
							SKIP_WHITESPACE(p);
rswindell's avatar
rswindell committed
740
741
							if(*p==';')     /* Ignore Comment Lines */
								continue;
742
743
744
745
							tp=p;
							FIND_WHITESPACE(tp);
							*tp=0;
							if(!stricmp(areatag,p)) {
rswindell's avatar
rswindell committed
746
747
748
								match=1;
								break; } }
						fclose(stream);
749
						quit=1;
rswindell's avatar
rswindell committed
750
751
752
753
						if(match)
							return(match);
						break; } } } }
	return(match);
754
755
756
757
}
/******************************************************************************
 Used by AREAFIX to add/remove/change areas in the areas file
******************************************************************************/
758
void alter_areas(area_t* add_area,area_t* del_area,faddr_t addr)
759
760
{
	FILE *nmfile,*afilein,*afileout,*fwdfile;
761
762
	char str[1024],fields[1024],field1[256],field2[256],field3[256]
		,outpath[MAX_PATH+1]
763
		,*outname,*p,*tp,nomatch=0,match=0;
764
	int i,j,k,x,y;
765
766
	ulong tagcrc;

767
768
	SAFECOPY(outpath,cfg.areafile);
	*getfname(outpath)=0;
769
770
771
772
773
774
775
776
777
	if((outname=tempname(outpath,"AREAS"))==NULL) {
		printf("\7ERROR creating temp file name for %s.\n",outpath);
		logprintf("ERROR tempnam(%s,AREAS)",outpath);
		return; }
	if((nmfile=tmpfile())==NULL) {
		printf("\7ERROR couldn't open NetMail temp file.\n");
		logprintf("ERROR in tmpfile()");
		free(outname);
		return; }
778
	if((afileout=fopen(outname,"w+"))==NULL) {
779
780
		printf("\7ERROR couldn't open %s.\n",outname);
		logprintf("ERROR line %d opening %s %s",__LINE__,outname
781
			,strerror(errno));
782
783
784
		fclose(nmfile);
		free(outname);
		return; }
785
	if((afilein=fopen(cfg.areafile,"r"))==NULL) {
786
787
		printf("\7ERROR couldn't open %s.\n",cfg.areafile);
		logprintf("ERROR line %d opening %s %s",__LINE__,cfg.areafile
788
			,strerror(errno));
789
790
791
792
793
		fclose(afileout);
		fclose(nmfile);
		free(outname);
		return; }
	while(!feof(afilein)) {
794
		if(!fgets(fields,sizeof(fields),afilein))
795
796
797
			break;
		truncsp(fields);
		p=fields;
798
		SKIP_WHITESPACE(p);
799
		if(*p==';') {    /* Skip Comment Lines */
800
			fprintf(afileout,"%s\n",fields);
801
			continue; }
802
		SAFECOPY(field1,p);         /* Internal Code Field */
803
		truncstr(field1," \t\r\n");
804
805
806
		FIND_WHITESPACE(p);
		SKIP_WHITESPACE(p);
		SAFECOPY(field2,p);         /* Areatag Field */
807
		truncstr(field2," \t\r\n");
808
809
		FIND_WHITESPACE(p);
		SKIP_WHITESPACE(p);
810
		if((tp=strchr(p,';'))!=NULL) {
811
812
			SAFECOPY(field3,p);     /* Comment Field (if any) */
			FIND_WHITESPACE(tp);
813
814
815
			*tp=0; }
		else
			field3[0]=0;
816
817
818
819
		if(del_area->tags) { 				/* Check for areas to remove */
			for(i=0;i<del_area->tags;i++) {
				if(!stricmp(del_area->tag[i],field2) ||
					!stricmp(del_area->tag[0],"-ALL"))     /* Match Found */
820
					break; }
821
			if(i<del_area->tags) {
822
823
824
825
826
827
				for(i=0;i<cfg.areas;i++) {
					if(!stricmp(field2,cfg.area[i].name)) {
						for(j=0;j<cfg.area[i].uplinks;j++)
							if(!memcmp(&cfg.area[i].uplink[j],&addr
								,sizeof(faddr_t)))
								break;
828
829
830
831
832
833
834
						if(j==cfg.area[i].uplinks) {
							fprintf(afileout,"%s\n",fields);
							/* bugfix here Mar-25-2004 (wasn't breaking for "-ALL") */
							if(stricmp(del_area->tag[0],"-ALL"))
								fprintf(nmfile,"%s not connected.\r\n",field2);
							break; 
						}
835

836
837
838
839
840
841
						/* Added 12/4/95 to remove uplink from connected uplinks */

						for(k=j;k<cfg.area[i].uplinks-1;k++)
							memcpy(&cfg.area[i].uplink[k],&cfg.area[i].uplink[k+1]
								,sizeof(faddr_t));
						--cfg.area[i].uplinks;
842
843
844
845
						if(cfg.area[i].uplinks==0) {
							FREE_AND_NULL(cfg.area[i].uplink);
						} else
							if((cfg.area[i].uplink=(faddr_t *)
deuce's avatar
deuce committed
846
								realloc(cfg.area[i].uplink,sizeof(faddr_t)
847
848
849
850
851
852
853
								*(cfg.area[i].uplinks)))==NULL) {
								printf("ERROR allocating memory for area #%u "
									"uplinks.\n",i+1);
								logprintf("ERROR line %d allocating memory for area "
									"#%u uplinks.\n",__LINE__,i+1);
								bail(1); 
							}
854
855
856
857
858
859
860

						fprintf(afileout,"%-16s%-23s ",field1,field2);
						for(j=0;j<cfg.area[i].uplinks;j++) {
							if(!memcmp(&cfg.area[i].uplink[j],&addr
								,sizeof(faddr_t)))
								continue;
							fprintf(afileout,"%s "
861
								,smb_faddrtoa(&cfg.area[i].uplink[j],NULL)); }
862
863
						if(field3[0])
							fprintf(afileout,"%s",field3);
864
						fprintf(afileout,"\n");
865
						fprintf(nmfile,"%s removed.\r\n",field2);
866
867
868
						break; 
					} 
				}
869
				if(i==cfg.areas)			/* Something screwy going on */
870
					fprintf(afileout,"%s\n",fields);
871
				continue; } }				/* Area match so continue on */
872
873
874
875
		if(add_area->tags) { 				/* Check for areas to add */
			for(i=0;i<add_area->tags;i++)
				if(!stricmp(add_area->tag[i],field2) ||
					!stricmp(add_area->tag[0],"+ALL"))      /* Match Found */
876
					break;
877
878
879
			if(i<add_area->tags) {
				if(stricmp(add_area->tag[i],"+ALL"))
					add_area->tag[i][0]=0;  /* So we can check other lists */
880
881
882
883
884
885
886
				for(i=0;i<cfg.areas;i++) {
					if(!stricmp(field2,cfg.area[i].name)) {
						for(j=0;j<cfg.area[i].uplinks;j++)
							if(!memcmp(&cfg.area[i].uplink[j],&addr
								,sizeof(faddr_t)))
								break;
						if(j<cfg.area[i].uplinks) {
887
							fprintf(afileout,"%s\n",fields);
888
							fprintf(nmfile,"%s already connected.\r\n",field2);
889
							break; }
890
						if(misc&ELIST_ONLY && !check_elists(field2,addr)) {
891
							fprintf(afileout,"%s\n",fields);
892
							break; }
893
894
895
896
897

						/* Added 12/4/95 to add uplink to connected uplinks */

						++cfg.area[i].uplinks;
						if((cfg.area[i].uplink=(faddr_t *)
deuce's avatar
deuce committed
898
							realloc(cfg.area[i].uplink,sizeof(faddr_t)
899
900
901
902
903
904
905
906
907
908
909
							*(cfg.area[i].uplinks)))==NULL) {
							printf("ERROR allocating memory for area #%u "
								"uplinks.\n",i+1);
							logprintf("ERROR line %d allocating memory for area "
								"#%u uplinks.\n",__LINE__,i+1);
							bail(1); }
						memcpy(&cfg.area[i].uplink[j],&addr,sizeof(faddr_t));

						fprintf(afileout,"%-16s%-23s ",field1,field2);
						for(j=0;j<cfg.area[i].uplinks;j++)
							fprintf(afileout,"%s "
910
								,smb_faddrtoa(&cfg.area[i].uplink[j],NULL));
911
912
						if(field3[0])
							fprintf(afileout,"%s",field3);
913
						fprintf(afileout,"\n");
914
915
916
						fprintf(nmfile,"%s added.\r\n",field2);
						break; } }
				if(i==cfg.areas)			/* Something screwy going on */
917
					fprintf(afileout,"%s\n",fields);
918
919
				continue; } 				/* Area match so continue on */
			nomatch=1; }					/* This area wasn't in there */
920
		fprintf(afileout,"%s\n",fields); }  /* No match so write back line */
921
	fclose(afilein);
922
	if(nomatch || (add_area->tags && !stricmp(add_area->tag[0],"+ALL"))) {
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
		i=matchnode(addr,0);
		if(i<cfg.nodecfgs) {
			for(j=0;j<cfg.listcfgs;j++) {
				match=0;
				for(k=0;k<cfg.listcfg[j].numflags;k++) {
					if(match) break;
					for(x=0;x<cfg.nodecfg[i].numflags;x++)
						if(!stricmp(cfg.listcfg[j].flag[k].flag
							,cfg.nodecfg[i].flag[x].flag)) {
							if((fwdfile=tmpfile())==NULL) {
								printf("\7ERROR couldn't open forwarding temp "
									"file.\n");
								logprintf("ERROR line %d opening forward temp "
									"file",__LINE__);
								match=1;
								break; }
939
							if((afilein=fopen(cfg.listcfg[j].listpath,"r"))==NULL) {
940
941
942
943
944
945
946
947
								printf("\7ERROR couldn't open %s.\n"
									,cfg.listcfg[j].listpath);
								logprintf("ERROR line %d opening %s"
									,__LINE__,cfg.listcfg[j].listpath);
								fclose(fwdfile);
								match=1;
								break; }
							while(!feof(afilein)) {
948
								if(!fgets(str,sizeof(str),afilein))
949
									break;
950
								p=str;
951
								SKIP_WHITESPACE(p);
952
953
								if(*p==';')     /* Ignore Comment Lines */
									continue;
954
955
956
957
958
959
								tp=p;
								FIND_WHITESPACE(tp);
								*tp=0;
								if(!stricmp(add_area->tag[0],"+ALL")) {
									SAFECOPY(tmp,p);
									tagcrc=crc32(strupr(tmp),0);
960
961
962
963
964
									for(y=0;y<cfg.areas;y++)
										if(tagcrc==cfg.area[y].tag)
											break;
									if(y<cfg.areas)
										continue; }
965
966
967
968
								for(y=0;y<add_area->tags;y++)
									if((!stricmp(add_area->tag[y],str) &&
										add_area->tag[y][0]) ||
										!stricmp(add_area->tag[0],"+ALL"))
969
										break;
970
								if(y<add_area->tags) {
971
972
973
									fprintf(afileout,"%-16s%-23s","P",str);
									if(cfg.listcfg[j].forward.zone)
										fprintf(afileout," %s"
974
975
											,smb_faddrtoa(&cfg.listcfg[j].forward,NULL));
									fprintf(afileout," %s\n",smb_faddrtoa(&addr,NULL));
976
									fprintf(nmfile,"%s added.\r\n",str);
977
978
									if(stricmp(add_area->tag[0],"+ALL"))
										add_area->tag[y][0]=0;
979
980
981
982
983
984
985
986
987
988
									if(!(cfg.listcfg[j].misc&NOFWD)
										&& cfg.listcfg[j].forward.zone)
										fprintf(fwdfile,"%s\r\n",str); } }
							fclose(afilein);
							if(!(cfg.listcfg[j].misc&NOFWD) && ftell(fwdfile)>0)
								file_to_netmail(fwdfile,cfg.listcfg[j].password
									,cfg.listcfg[j].forward,"Areafix");
							fclose(fwdfile);
							match=1;
							break; } } } } }
989
990
991
992
	if(add_area->tags && stricmp(add_area->tag[0],"+ALL")) {
		for(i=0;i<add_area->tags;i++)
			if(add_area->tag[i][0])
				fprintf(nmfile,"%s not found.\r\n",add_area->tag[i]); }
993
	if(!ftell(nmfile))
994
		create_netmail(NULL,"Area Change Request","No changes made.",addr,FALSE);
995
996
997
998
999
1000
	else
		file_to_netmail(nmfile,"Area Change Request",addr,0);
	fclose(nmfile);
	fclose(afileout);
	if(delfile(cfg.areafile))					/* Delete AREAS.BBS */
		logprintf("ERROR line %d removing %s %s",__LINE__,cfg.areafile
1001
			,strerror(errno));
1002
1003
1004
	if(rename(outname,cfg.areafile))		   /* Rename new AREAS.BBS file */
		logprintf("ERROR line %d renaming %s to %s",__LINE__,outname,cfg.areafile);
	free(outname);
1005
1006
1007
1008
1009
1010
1011
1012
1013
}
/******************************************************************************
 Used by AREAFIX to add/remove/change uplink info in the configuration file
 old = the old setting for this option, new = what the setting is changing to
 option = 0 for compression type change
		  1 for areafix password change
		  2 to set this node to passive
		  3 to set this node to active (remove passive)
******************************************************************************/
1014
void alter_config(faddr_t addr, char *old, char *new, int option)
1015
1016
{
	FILE *outfile,*cfgfile;
1017
1018
	char str[257],outpath[MAX_PATH+1],tmp[257],tmp2[257],*outname,*p,*tp
		,match=0;
1019
1020
1021
	int i,j,k,file;
	faddr_t taddr;

rswindell's avatar
rswindell committed
1022
	i=matchnode(addr,0);				  /* i = config number from here on */
1023
1024
	SAFECOPY(outpath,cfg.cfgfile);
	*getfname(outpath)=0;
rswindell's avatar
rswindell committed
1025
1026
1027
1028
	if((outname=tempname(outpath,"CFG"))==NULL) {
		printf("\7ERROR creating temporary file name for %s.\n",outpath);
		logprintf("ERROR tempnam(%s,CFG)",outpath);
		return; }
1029
	if((outfile=fopen(outname,"w+"))==NULL) {
rswindell's avatar
rswindell committed
1030
1031
		printf("\7ERROR couldn't open %s.\n",outname);
		logprintf("ERROR line %d opening %s %s",__LINE__,outname
1032
			,strerror(errno));
rswindell's avatar
rswindell committed
1033
1034
		free(outname);
		return; }
1035
	if((cfgfile=fopen(cfg.cfgfile,"r"))==NULL) {
rswindell's avatar
rswindell committed
1036
		printf("\7ERROR couldn't open %s.\n",cfg.cfgfile);
rswindell's avatar
rswindell committed
1037
		logprintf("ERROR line %d opening %s %s",__LINE__,cfg.cfgfile
1038
			,strerror(errno));
rswindell's avatar
rswindell committed
1039
1040
1041
		fclose(outfile);
		free(outname);
		return; }
1042

rswindell's avatar
rswindell committed
1043
	while(!feof(cfgfile)) {
1044
		if(!fgets(str,sizeof(str),cfgfile))
rswindell's avatar
rswindell committed
1045
1046
1047
			break;
		truncsp(str);
		p=str;
1048
		SKIP_WHITESPACE(p);
rswindell's avatar
rswindell committed
1049
		if(*p==';') {
1050
			fprintf(outfile,"%s\n",str);
1051
			continue; }
rswindell's avatar
rswindell committed
1052
		sprintf(tmp,"%-.25s",p);
1053
		tp=strchr(tmp,' ');
rswindell's avatar
rswindell committed
1054
1055
1056
		if(tp)
			*tp=0;								/* Chop off at space */
		strupr(tmp);							/* Convert code to uppercase */
1057
1058
		FIND_WHITESPACE(p);						/* Skip code */
		SKIP_WHITESPACE(p);						/* Skip white space */
rswindell's avatar
rswindell committed
1059
1060
1061
1062
1063
1064

		if(option==0 && !strcmp(tmp,"USEPACKER")) {     /* Change Compression */
			if(!*p)
				continue;
			strcpy(tmp2,p);
			p=tmp2;
1065
			FIND_WHITESPACE(p);
rswindell's avatar
rswindell committed
1066
1067
1068
			*p=0;
			p++;
			if(!stricmp(new,tmp2)) {   /* Add to new definition */
1069
				fprintf(outfile,"%-10s %s %s %s\n",tmp,tmp2
1070
					,smb_faddrtoa(&cfg.nodecfg[i].faddr,NULL)
rswindell's avatar
rswindell committed
1071
1072
					,(*p) ? p : "");
				match=1;
1073
				continue; }
rswindell's avatar
rswindell committed
1074
1075
1076
1077
1078
1079
1080
1081
1082
			else if(!stricmp(old,tmp2)) {	/* Remove from old def */
				for(j=k=0;j<cfg.nodecfgs;j++) {
					if(j==i)
						continue;
					if(!stricmp(cfg.arcdef[cfg.nodecfg[j].arctype].name,tmp2)) {
						if(!k) {
							fprintf(outfile,"%-10s %s",tmp,tmp2);
							k++; }
						fprintf(outfile," %s"
1083
							,smb_faddrtoa(&cfg.nodecfg[j].faddr,NULL)); } }
1084
				fprintf(outfile,"\n");
rswindell's avatar
rswindell committed
1085
1086
1087
1088
				continue; } }

		if(option==1 && !strcmp(tmp,"AREAFIX")) {       /* Change Password */
			if(!*p)
1089
				continue;
1090
			taddr=smb_atofaddr(&sys_faddr,p);
rswindell's avatar
rswindell committed
1091
			if(!memcmp(&cfg.nodecfg[i].faddr,&taddr,sizeof(faddr_t))) {
1092
				FIND_WHITESPACE(p); /* Skip over address */
1093
				SKIP_WHITESPACE(p);	/* Skip over whitespace */
1094
				FIND_WHITESPACE(p); /* Skip over password */
1095
				SKIP_WHITESPACE(p);	/* Skip over whitespace */
1096
				fprintf(outfile,"%-10s %s %s %s\n",tmp
1097
					,smb_faddrtoa(&cfg.nodecfg[i].faddr,NULL),new,p);
rswindell's avatar
rswindell committed
1098
1099
1100
1101
1102
1103
1104
				continue; } }

		if(option>1 && !strcmp(tmp,"PASSIVE")) {        /* Toggle Passive Areas */
			match=1;
			for(j=k=0;j<cfg.nodecfgs;j++) {
				if(option==2 && j==i) {
					if(!k) fprintf(outfile,"%-10s",tmp);
1105
					fprintf(outfile," %s",smb_faddrtoa(&cfg.nodecfg[j].faddr,NULL));
rswindell's avatar
rswindell committed
1106
1107
1108
1109
1110
1111
					k++;
					continue; }
				if(option==3 && j==i)
					continue;
				if(cfg.nodecfg[j].attr&ATTR_PASSIVE) {
					if(!k) fprintf(outfile,"%-10s",tmp);
1112
					fprintf(outfile," %s",smb_faddrtoa(&cfg.nodecfg[j].faddr,NULL));
rswindell's avatar
rswindell committed
1113
					k++; } }
1114
			if(k) fprintf(outfile,"\n");
rswindell's avatar
rswindell committed
1115
			continue; }
1116
		fprintf(outfile,"%s\n",str); }
rswindell's avatar
rswindell committed
1117
1118
1119

	if(!match) {
		if(option==0)
1120
			fprintf(outfile,"%-10s %s %s\n","USEPACKER",new
1121
				,smb_faddrtoa(&cfg.nodecfg[i].faddr,NULL));
rswindell's avatar
rswindell committed
1122
		if(option==2)
1123
			fprintf(outfile,"%-10s %s\n","PASSIVE"
1124
				,smb_faddrtoa(&cfg.nodecfg[i].faddr,NULL)); }
rswindell's avatar
rswindell committed
1125
1126
1127
1128
1129

	fclose(cfgfile);
	fclose(outfile);
	if(delfile(cfg.cfgfile))
		logprintf("ERROR line %d removing %s %s",__LINE__,cfg.cfgfile
1130
			,strerror(errno));
rswindell's avatar
rswindell committed
1131
1132
1133
	if(rename(outname,cfg.cfgfile))
		logprintf("ERROR line %d renaming %s to %s",__LINE__,outname,cfg.cfgfile);
	free(outname);
1134
1135
1136
1137
1138
1139
1140
}
/******************************************************************************
 Used by AREAFIX to process any '%' commands that come in via netmail
******************************************************************************/
void command(char *instr,faddr_t addr)
{
	FILE *stream,*tmpf;
1141
	char str[MAX_PATH+1],temp[256],*buf,*p;
1142
1143
1144
1145
1146
	int  file,i,node;
	long l;
	area_t add_area,del_area;

	node=matchnode(addr,0);
1147
	if(node>=cfg.nodecfgs)
1148