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
69
70
71
72
73
74
75
76
77
78
#include "sbbs.h"			/* load_cfg() */
#include "sbbsdefs.h"
#include "smblib.h"
#include "scfglib.h"
#include "lzh.h"
#include "sbbsecho.h"

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;
79
BOOL twit_list;
80

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

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

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

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

102
#if defined(__unix__)	/* borrowed from MSVC */
rswindell's avatar
rswindell committed
103
unsigned _rotr (
104
105
106
107
        unsigned val,
        int shift
        )
{
108
109
110
111
112
113
114
115
116
117
118
    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 */
	}
119

120
    return num;
121
122
123
}
#endif

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

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

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

152
153
154
155
156
157
158
159
	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);
160
	fprintf(fidologfile,"%02u/%02u/%02u %02u:%02u:%02u %s\n"
161
162
		,gm->tm_mon+1,gm->tm_mday,TM_YEAR(gm->tm_year),gm->tm_hour,gm->tm_min,gm->tm_sec
		,buf);
163
164
165
166
167
}

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

174
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
	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 */
235
					strcat(cmd,cfg->exec_dir);
236
					break;
237
238
239
240
241
                case '@':   /* EXEC Directory for DOS/OS2/Win32, blank for Unix */
#ifndef __unix__
                    strcat(cmd,cfg->exec_dir);
#endif
                    break;
242
243
244
245
246
247
248
249
250
251
252
				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;
253
254
255
256
257
258
259
260
261
262
263
264
265
266
				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;
267
268
269
270
271
272
273
274
275
276
				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;
277

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

/****************************************************************************/
/* Runs an external program directly using spawnvp							*/
/****************************************************************************/
int execute(char *cmdline)
{
rswindell's avatar
rswindell committed
286
#if 1
287
	return system(cmdline);
rswindell's avatar
rswindell committed
288
#else
289
290
291
292
293
294
295
	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 */
296
		if(str[c]==' ') {
297
298
299
300
301
302
			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
303
#endif
304
}
305

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

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

319
320
321
322
323
/******************************************************************************
 This function creates or appends on existing Binkley compatible .?LO file
 attach file.
 Returns 0 on success.
******************************************************************************/
324
int write_flofile(char *attachment, faddr_t dest, BOOL bundle)
325
{
326
327
328
329
330
	char fname[MAX_PATH+1];
	char outbound[MAX_PATH+1];
	char str[MAX_PATH+1];
	char ch;
	char searchstr[MAX_PATH+1];
331
332
333
334
335
336
337
338
	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
339
340
341
342
	if(attr&ATTR_CRASH) ch='c';
	else if(attr&ATTR_HOLD) ch='h';
	else if(attr&ATTR_DIRECT) ch='d';
	else ch='f';
343
	if(dest.zone==sys_faddr.zone)		/* Default zone, use default outbound */
344
		strcpy(outbound,cfg.outbound);
345
346
	else {								/* Inter-zone outbound is OUTBOUND.XXX */
		sprintf(outbound,"%.*s.%03x"
rswindell's avatar
rswindell committed
347
			,(int)strlen(cfg.outbound)-1,cfg.outbound,dest.zone);
348
349
350
		MKDIR(outbound);
		backslash(outbound);
	}
351
	if(dest.point) {					/* Point destination is OUTBOUND\*.PNT */
rswindell's avatar
rswindell committed
352
		sprintf(str,"%04x%04x.pnt"
353
354
			,dest.net,dest.node);
		strcat(outbound,str); }
rswindell's avatar
rswindell committed
355
356
	if(outbound[strlen(outbound)-1]=='\\'
		|| outbound[strlen(outbound)-1]=='/')
357
		outbound[strlen(outbound)-1]=0;
rswindell's avatar
rswindell committed
358
	MKDIR(outbound);
359
	backslash(outbound);
360
	if(dest.point)
rswindell's avatar
rswindell committed
361
		sprintf(fname,"%s%08x.%clo",outbound,dest.point,ch);
362
	else
rswindell's avatar
rswindell committed
363
		sprintf(fname,"%s%04x%04x.%clo",outbound,dest.net,dest.node,ch);
364
365
366
367
	if(bundle && misc&TRUNC_BUNDLES)
		ch='#';
	else
		ch='^';
368
369
370
	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 */
371
	sprintf(searchstr,"%c%s",ch,attachment);
372
373
	if(findstr(searchstr,fname))	/* file already in FLO file */
		return(0);
374
	if((stream=fopen(fname,"a"))==NULL) {
375
376
		printf("\7ERROR line %d opening %s %s\n",__LINE__,fname,strerror(errno));
		logprintf("ERROR line %d opening %s %s",__LINE__,fname,strerror(errno));
377
378
		return(-1); 
	}
379
	fprintf(stream,"%s\n",searchstr);
380
381
382
383
	fclose(stream);
	return(0);
}

384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
/* 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);
}

407
408
409
410
411
/******************************************************************************
 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.
******************************************************************************/
412
int create_netmail(char *to, char *subject, char *body, faddr_t dest, BOOL file_attached)
413
414
{
	FILE *fstream;
415
	char str[256],fname[MAX_PATH+1];
416
417
418
419
420
421
422
423
424
	ushort attr=0;
	int fmsg;
	uint i;
	static uint startmsg;
	time_t t;
	faddr_t	faddr;
	fmsghdr_t hdr;
	struct tm *tm;

425
426
427
428
429
430
431
432
433
434
435
	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++) {
436
			sprintf(fname,"%s%u.msg",scfg.netmail_dir,i);
437
438
439
			if(!fexistcase(fname))
				break; 
		}
440
441
442
443
444
445
		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) {
446
447
			printf("\7ERROR line %d opening %s %s\n",__LINE__,fname,strerror(errno));
			logprintf("ERROR line %d opening %s %s",__LINE__,fname,strerror(errno));
448
			return(-1); }
449

450
451
452
453
454
455
456
457
458
459
460
461
		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);
462
		if(file_attached)
463
			hdr.attr|=FIDO_FILE;
464

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

470
471
472
473
474
475
476
477
478
		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)
479
			SAFECOPY(hdr.to,to);
480
		else
481
			SAFECOPY(hdr.to,"SYSOP");
482

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

		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);
490
491
492
493
494
495
496
497

		/* 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");
498
			else
499
500
501
502
				fprintf(fstream," KFS");
		}
		fprintf(fstream,"\r");

503
504
505
506
507
508
		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); }
509
		if(!file_attached || (!(attr&ATTR_DIRECT) && file_attached))
510
			fwrite_crlf(body,strlen(body)+1,fstream);	/* Write additional NULL */
511
512
513
		else
			fwrite("\0",1,1,fstream);               /* Write NULL */
		fclose(fstream);
514
	} while(!fexistcase(fname));
515
	return(0);
516
517
518
519
520
521
522
523
524
525
526
}

/******************************************************************************
 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;

527
528
529
530
	l=len=ftell(infile);
	if(len>8192L)
		len=8192L;
	rewind(infile);
deuce's avatar
deuce committed
531
	if((buf=(char *)malloc(len+1))==NULL) {
532
533
534
535
536
537
538
		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) {
539
			p++;
540
541
			if(*p) {
				*p=0;
542
				p++;
543
544
545
546
547
548
				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");
549
550
		create_netmail(to,title,buf,addr,FALSE); 
	}
deuce's avatar
deuce committed
551
	free(buf);
552
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
}
/******************************************************************************
 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).
******************************************************************************/
613
void netmail_arealist(int type, faddr_t addr)
614
615
{
	FILE *stream,*tmpf;
616
	char str[256],temp[256],title[128],match,*p,*tp;
617
618
619
620
621
622
623
624
625
626
627
628
629
630
	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; }

631
	if(type==1 || !(misc&ELIST_ONLY)) {
632
633
634
635
636
637
638
		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))
639
						fprintf(tmpf,"%s\r\n",cfg.area[i].name); }
640
			else
641
				fprintf(tmpf,"%s\r\n",cfg.area[i].name); } }
642
643
644
645
646
647
648
649
650
651
652

	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)) {
653
							if((stream=fopen(cfg.listcfg[j].listpath,"r"))==NULL) {
654
655
656
657
								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
658
									,strerror(errno));
659
660
661
								match=1;
								break; }
							while(!feof(stream)) {
662
								if(!fgets(str,sizeof(str),stream))
663
664
									break;
								p=str;
665
								SKIP_WHITESPACE(p);
666
667
								if(*p==';')     /* Ignore Comment Lines */
									continue;
668
669
670
								tp=p;
								FIND_WHITESPACE(tp);
								*tp=0;
671
672
								if(!(misc&ELIST_ONLY)) {
									for(y=0;y<cfg.areas;y++)
673
										if(!stricmp(cfg.area[y].name,p))
674
675
											break;
									if(y==cfg.areas)
676
										fprintf(tmpf,"%s\r\n",p); }
677
								else
678
									fprintf(tmpf,"%s\r\n",p); }
679
680
681
682
683
							fclose(stream);
							match=1;
							break; } } } } }

	if(!ftell(tmpf))
684
		create_netmail(NULL,title,"None.",addr,FALSE);
685
686
687
688
689
690
691
692
693
	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)
{
694
	char str[MAX_PATH+1],*p;
695
696
	int i;

697
698
699
700
701
702
703
704
705
706
707
708
709
	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);
710
711
}

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

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

766
767
	SAFECOPY(outpath,cfg.areafile);
	*getfname(outpath)=0;
768
769
770
771
772
773
774
775
776
	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; }
777
	if((afileout=fopen(outname,"w+"))==NULL) {
778
779
		printf("\7ERROR couldn't open %s.\n",outname);
		logprintf("ERROR line %d opening %s %s",__LINE__,outname
780
			,strerror(errno));
781
782
783
		fclose(nmfile);
		free(outname);
		return; }
784
	if((afilein=fopen(cfg.areafile,"r"))==NULL) {
785
786
		printf("\7ERROR couldn't open %s.\n",cfg.areafile);
		logprintf("ERROR line %d opening %s %s",__LINE__,cfg.areafile
787
			,strerror(errno));
788
789
790
791
792
		fclose(afileout);
		fclose(nmfile);
		free(outname);
		return; }
	while(!feof(afilein)) {
793
		if(!fgets(fields,sizeof(fields),afilein))
794
795
796
			break;
		truncsp(fields);
		p=fields;
797
		SKIP_WHITESPACE(p);
798
		if(*p==';') {    /* Skip Comment Lines */
799
			fprintf(afileout,"%s\n",fields);
800
			continue; }
801
		SAFECOPY(field1,p);         /* Internal Code Field */
802
		truncstr(field1," \t\r\n");
803
804
805
		FIND_WHITESPACE(p);
		SKIP_WHITESPACE(p);
		SAFECOPY(field2,p);         /* Areatag Field */
806
		truncstr(field2," \t\r\n");
807
808
		FIND_WHITESPACE(p);
		SKIP_WHITESPACE(p);
809
		if((tp=strchr(p,';'))!=NULL) {
810
811
			SAFECOPY(field3,p);     /* Comment Field (if any) */
			FIND_WHITESPACE(tp);
812
813
814
			*tp=0; }
		else
			field3[0]=0;
815
816
817
818
		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 */
819
					break; }
820
			if(i<del_area->tags) {
821
822
823
824
825
826
				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;
827
828
829
830
831
832
833
						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; 
						}
834

835
836
837
838
839
840
						/* 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;
841
842
843
844
						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
845
								realloc(cfg.area[i].uplink,sizeof(faddr_t)
846
847
848
849
850
851
852
								*(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); 
							}
853
854
855
856
857
858
859

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

						/* 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
897
							realloc(cfg.area[i].uplink,sizeof(faddr_t)
898
899
900
901
902
903
904
905
906
907
908
							*(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 "
909
								,smb_faddrtoa(&cfg.area[i].uplink[j],NULL));
910
911
						if(field3[0])
							fprintf(afileout,"%s",field3);
912
						fprintf(afileout,"\n");
913
914
915
						fprintf(nmfile,"%s added.\r\n",field2);
						break; } }
				if(i==cfg.areas)			/* Something screwy going on */
916
					fprintf(afileout,"%s\n",fields);
917
918
				continue; } 				/* Area match so continue on */
			nomatch=1; }					/* This area wasn't in there */
919
		fprintf(afileout,"%s\n",fields); }  /* No match so write back line */
920
	fclose(afilein);
921
	if(nomatch || (add_area->tags && !stricmp(add_area->tag[0],"+ALL"))) {
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
		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; }
938
							if((afilein=fopen(cfg.listcfg[j].listpath,"r"))==NULL) {
939
940
941
942
943
944
945
946
								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)) {
947
								if(!fgets(str,sizeof(str),afilein))
948
									break;
949
								p=str;
950
								SKIP_WHITESPACE(p);
951
952
								if(*p==';')     /* Ignore Comment Lines */
									continue;
953
954
955
956
957
958
								tp=p;
								FIND_WHITESPACE(tp);
								*tp=0;
								if(!stricmp(add_area->tag[0],"+ALL")) {
									SAFECOPY(tmp,p);
									tagcrc=crc32(strupr(tmp),0);
959
960
961
962
963
									for(y=0;y<cfg.areas;y++)
										if(tagcrc==cfg.area[y].tag)
											break;
									if(y<cfg.areas)
										continue; }
964
965
966
967
								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"))
968
										break;
969
								if(y<add_area->tags) {
970
971
972
									fprintf(afileout,"%-16s%-23s","P",str);
									if(cfg.listcfg[j].forward.zone)
										fprintf(afileout," %s"
973
974
											,smb_faddrtoa(&cfg.listcfg[j].forward,NULL));
									fprintf(afileout," %s\n",smb_faddrtoa(&addr,NULL));
975
									fprintf(nmfile,"%s added.\r\n",str);
976
977
									if(stricmp(add_area->tag[0],"+ALL"))
										add_area->tag[y][0]=0;
978
979
980
981
982
983
984
985
986
987
									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; } } } } }
988
989
990
991
	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]); }
992
	if(!ftell(nmfile))
993
		create_netmail(NULL,"Area Change Request","No changes made.",addr,FALSE);
994
995
996
997
998
999
	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
1000
			,strerror(errno));
1001
1002
1003
	if(rename(outname,cfg.areafile))		   /* Rename new AREAS.BBS file */
		logprintf("ERROR line %d renaming %s to %s",__LINE__,outname,cfg.areafile);
	free(outname);
1004
1005
1006
1007
1008
1009
1010
1011
1012
}
/******************************************************************************
 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)
******************************************************************************/
1013
void alter_config(faddr_t addr, char *old, char *new, int option)
1014
1015
{
	FILE *outfile,*cfgfile;
1016
1017
	char str[257],outpath[MAX_PATH+1],tmp[257],tmp2[257],*outname,*p,*tp
		,match=0;
1018
1019
1020
	int i,j,k,file;
	faddr_t taddr;

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

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

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

		if(option==1 && !strcmp(tmp,"AREAFIX")) {       /* Change Password */
			if(!*p)
1088
				continue;
1089
			taddr=smb_atofaddr(&sys_faddr,p);
rswindell's avatar
rswindell committed
1090
			if(!memcmp(&cfg.nodecfg[i].faddr,&taddr,sizeof(faddr_t))) {
1091
				FIND_WHITESPACE(p); /* Skip over address */
1092
				SKIP_WHITESPACE(p);	/* Skip over whitespace */
1093
				FIND_WHITESPACE(p); /* Skip over password */
1094
				SKIP_WHITESPACE(p);	/* Skip over whitespace */
1095
				fprintf(outfile,"%-10s %s %s %s\n",tmp
1096
					,smb_faddrtoa(&cfg.nodecfg[i].faddr,NULL),new,p);
rswindell's avatar
rswindell committed
1097
1098
1099
1100
1101
1102
1103
				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);
1104
					fprintf(outfile," %s",smb_faddrtoa(&cfg.nodecfg[j].faddr,NULL));
rswindell's avatar
rswindell committed
1105
1106
1107
1108
1109
1110
					k++;
					continue; }
				if(option==3 && j==i)
					continue;
				if(cfg.nodecfg[j].attr&ATTR_PASSIVE) {
					if(!k) fprintf(outfile,"%-10s",tmp);
1111
					fprintf(outfile," %s",smb_faddrtoa(&cfg.nodecfg[j].faddr,NULL));
rswindell's avatar
rswindell committed
1112
					k++; } }
1113
			if(k) fprintf(outfile,"\n");
rswindell's avatar
rswindell committed
1114
			continue; }
1115
		fprintf(outfile,"%s\n",str); }
rswindell's avatar
rswindell committed
1116
1117
1118

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

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

	node=matchnode(addr,0);
1146
	if(node>=cfg.nodecfgs)
1147
1148
1149
1150
1151
		return;
	memset(&add_area,0,sizeof(area_t));
	memset(&del_area,0,sizeof(area_t));
	strupr(instr);
	if((p=strstr(instr,"HELP"))!=NULL) {