File: pre-3.0.patch

package info (click to toggle)
mason 1.0.0-13
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 2,300 kB
  • sloc: sh: 4,158; makefile: 104
file content (719 lines) | stat: -rw-r--r-- 32,068 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
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
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
Description: All the patches that had been directly applied before the
 conversion to source format 3.0 (quilt).
Last-Update: 2018-10-09

--- mason-1.0.0.orig/Makefile
+++ mason-1.0.0/Makefile
@@ -35,11 +35,13 @@ MASONVER = 1.0.0
 
 #No quotes around multi file specs.
 BINDIR=$(DESTDIR)/usr/bin/
-BINFILES=mason mason-gui-text mason-decide
+BINFILES=mason mason-gui-text 
 CONFDIR=$(DESTDIR)/etc/
 CONFFILE=masonrc
 LIBDIR=$(DESTDIR)/var/lib/mason/
-LIBFILES=masonlib baserules.sample graffiti-services moreservices nmap-services portsdb-services regression-test all-ip-numbers.txt
+LIBFILES=baserules.sample graffiti-services moreservices nmap-services portsdb-services regression-test all-ip-numbers.txt
+LIBSCRIPTDIR=$(DESTDIR)/var/lib/mason/
+LIBSCRIPTFILES=masonlib mason-decide
 DOCDIR=$(DESTDIR)/usr/doc/mason-${MASONVER}/
 DOCFILES=COPYING index.html mason.sgml mason.txt mason.html mason-1.html mason-2.html mason-3.html mason-4.html mason-5.html mason-6.html mason-7.html mason-8.html mason-9.html mason-10.html mason-11.html toc.gif prev.gif next.gif mason-banner.gif
 #DOCDIR=$(DESTDIR)/usr/doc/mason/
@@ -59,6 +61,8 @@ install:
 	@install -o root -g root -m 0755 -d ${LIBDIR}
 	@echo -n "${LIBFILES}... "
 	@install -o root -g root -m 0644 ${LIBFILES} ${LIBDIR}
+	@echo -n "${LIBSCRIPTFILES}... "
+	@install -o root -g root -m 0755 ${LIBSCRIPTFILES} ${LIBSCRIPTDIR}
 	@echo -n "doc directory... "
 	@install -o root -g root -m 0755 -d ${DOCDIR}
 	@echo -n "${DOCFILES}... "
@@ -90,7 +94,7 @@ install:
 docs:
 	sgml2html --imagebuttons mason.sgml \
 	&& sgml2txt -f mason.sgml \
-	&& makedoc mason.txt mason.pdb 'The Mason HOWTO'
+#	&& makedoc mason.txt mason.pdb 'The Mason HOWTO'
 
 regress:
 	@if ./regression-test ; then \
--- mason-1.0.0.orig/baserules.sample
+++ mason-1.0.0/baserules.sample
@@ -1,31 +1,45 @@
-#Put any fixed rules you wish here.  Example:
-
-#if [ -f /proc/net/ip_fwchains ]; then
-#	#Place the ipchains versions of your rules here
-#	/sbin/ipchains -A forward -s 172.16.0.0/24 -j MASQ		#Masquerade from internal lan out
-#elif [ -f /proc/net/ip_input ]; then
-#	#Place the ipfwadm versions of your rules here.
-#	/sbin/ipfwadm -F -a accept -m -S 172.16.0.0/24			#Masquerade from internal lan out
-#else		#The old >>>elif [ -n "`lsmod | grep '^ip_tables '`" ]; then<<<< doesn't work as iptables can be kernel-resident.  Cross your fingers.
-#	#Place the iptables versions of your rules here
-#	#The following loads all netfilter modules - this may or may not be appropriate for you
-#	MODDIR="/lib/modules/`uname -r`"
-#	for MOD in \
-#	 $MODDIR/ipv4/ip_* \
-#	 $MODDIR/ipv4/ipt_* \
-#	 $MODDIR/ipv4/iptable_* \
-#	 $MODDIR/kernel/net/ipv4/netfilter/ip_* \
-#	 $MODDIR/kernel/net/ipv4/netfilter/ipt_* \
-#	 $MODDIR/kernel/net/ipv4/netfilter/iptable_* ; do
-#	    insmod $MOD >/dev/null 2>/dev/null ; modprobe $MOD >/dev/null 2>/dev/null
-#	done
-#	#Masquerade from internal lan out - syntax from iptables howto; thanks, Rusty.
-#	iptables -A POSTROUTING -t nat -s 172.16.0.0/24 -o ppp0 -j MASQUERADE
-#	#The following will allow the response packets back in/out/through your firewall.
-#	#This, too, may or may not be appropriate for you and should not be taken as a suggestion.
-#	#It is only here as a convience.  If you use these, Mason will build a firewall
-#	#of opening packets only.
-#	iptables -A INPUT   -m state --state ESTABLISHED,RELATED                                                -j ACCEPT
-#	iptables -A FORWARD -m state --state ESTABLISHED,RELATED                                                -j ACCEPT
-#	iptables -A OUTPUT  -m state --state ESTABLISHED,RELATED                                                -j ACCEPT
-#fi
+##!/bin/sh
+##=============================================================================
+## Example of a mason firewall script
+##=============================================================================
+#
+## ---------------------------------------------------------------------
+## Allow all local connections
+## ---------------------------------------------------------------------
+#/sbin/iptables -A INPUT  -i lo -j ACCEPT
+#/sbin/iptables -A OUTPUT -o lo -j ACCEPT
+#
+## ---------------------------------------------------------------------
+## Allow ESTABLISHED and RELATED packets globally, to drastically reduce
+## the number of reported rules in learning mode
+## ---------------------------------------------------------------------
+## Hint: "There is a certain feature in iptables that is not so well 
+## documented and may therefore be overlooked by a lot of people [...]
+## If you use state NEW, packets with the SYN bit unset will get through 
+## your firewall." Cited from: 
+## http://iptables-tutorial.frozentux.net/iptables-tutorial.html#NEWNOTSYN
+## ---------------------------------------------------------------------
+#/sbin/iptables -A INPUT                  -m state --state ESTABLISHED -j ACCEPT
+#/sbin/iptables -A INPUT                  -m state --state RELATED     -j ACCEPT
+#/sbin/iptables -A INPUT                  -m state --state INVALID     -j DROP
+#
+#/sbin/iptables -A OUTPUT                 -m state --state ESTABLISHED -j ACCEPT
+#/sbin/iptables -A OUTPUT                 -m state --state RELATED     -j ACCEPT
+#/sbin/iptables -A OUTPUT                 -m state --state INVALID     -j DROP
+#
+## ---------------------------------------------------------------------
+## Drop all new new tcp-connections without a sys-flag
+## ---------------------------------------------------------------------
+## Info: "There is a certain feature in iptables that is not so well 
+## documented and may therefore be overlooked by a lot of people [...]
+## If you use state NEW, packets with the SYN bit unset will get through 
+## your firewall." Cited from: 
+## http://iptables-tutorial.frozentux.net/iptables-tutorial.html#NEWNOTSYN
+## ---------------------------------------------------------------------
+#/sbin/iptables -A INPUT   -p tcp ! --syn -m state --state NEW         -j DROP
+#/sbin/iptables -A OUTPUT  -p tcp ! --syn -m state --state NEW         -j DROP
+#
+## ---------------------------------------------------------------------
+## Allowed connections 
+## ---------------------------------------------------------------------
+#
--- mason-1.0.0.orig/firewall
+++ mason-1.0.0/firewall
@@ -3,12 +3,22 @@
 # firewall        Starts a Mason firewall.
 #
 #
+### BEGIN INIT INFO
+# Provides:          mason
+# Required-Start:    $network
+# Required-Stop:     $network
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Starts the mason firewall script
+# Description:       Starts the firewall script /etc/mason.baserules. The script was created with the mason firewall builder.
+### END INIT INFO
+#
 # chkconfig: 2345 18 92
 # description: firewall starts the firewall created by the Mason \
 # firewall builder.  As a firewall is important to system security, \
 # it should be always turned on.
 
-# Debian init script derived from original script by Jeff Licquia.
+# Debian init script derived from original script by Jeff Licquia
 
 # Debian flags for runlevels - similar to RH's chkconfig.
 FLAGS="defaults 19"
--- mason-1.0.0.orig/mason
+++ mason-1.0.0/mason
@@ -146,7 +146,7 @@ for ONEIF in $DYNIF ; do
 		echo "export ${ONEIF}ADDR=\"0/0\"	${CMNT} ${CMNT}Use this if you want to match any address on $ONEIF."
 	fi
 	if [ "$DYNIFMODE" != "SPECIFICIP" ]; then echo -n "$CMNT $CMNT" ; fi
-	echo "export ${ONEIF}ADDR=\"\`ifconfig $ONEIF 2>/dev/null | awk '/inet addr/{print substr($2,6)}'\`$SINGLEMACHSPEC\"	${CMNT} ${CMNT}Use this if you want to match a single address on $ONEIF."
+	echo "export ${ONEIF}ADDR=\"\`LC_ALL=C ifconfig $ONEIF 2>/dev/null | awk '/inet addr/{print substr(\$2,6)}'\`$SINGLEMACHSPEC\"	${CMNT} ${CMNT}Use this if you want to match a single address on $ONEIF."
 	if [ "$DYNIFMODE" != "SMALLESTRANGE" ]; then echo -n "$CMNT $CMNT" ; fi
 #FIXME - what if the file is empty?
 	echo "export ${ONEIF}ADDR=\"$(encompassingnetworkof $(cat ${MASONDIR}${ONEIF}-ips | sort | uniq) || logfail $LINENO return encompassing network for $ONEIF)\"	${CMNT} ${CMNT}Use this if you want to match all addresses seen so far on $ONEIF."
--- mason-1.0.0.orig/mason-decide
+++ mason-1.0.0/mason-decide
@@ -176,7 +176,7 @@ while [ "$EXITNOW" != "YES" ] && read IN
 				echo $ENH "${WARN}$0: Can't create temp file.${NORM}"
 			else
 				echo "$CURRLINE" >$TMPFILE
-				$EDITOR $TMPFILE <&10
+				eval $EDITOR $TMPFILE <&10
 				CURRLINE=`cat $TMPFILE`
 				rm -f $TMPFILE || :
 			fi	;;
--- mason-1.0.0.orig/mason-gui-text
+++ mason-1.0.0/mason-gui-text
@@ -4,6 +4,25 @@ set -e
 #See top of Mason script for copyright and licensing information.
 #Last YYYY code used: 0019, use 0020 next
 
+# ---------------------------------------------------------------------
+# Kill another instance of mason if this programm is started with
+# the option "--force" - 2008-06-27 - Scheffczyk
+# ---------------------------------------------------------------------
+if [ "$$"x != "`/bin/pidof -x /usr/bin/mason-gui-text`"x ]; then
+    if [ "$1"x == "--force"x ]; then
+	echo "Told to stop another instance of $0  ..."
+	kill -9 `ps aux | grep mason | egrep -v "(grep mason|$$)" | awk '{ print $2 }'`
+	if [ "$$"x != "`/bin/pidof -x /usr/bin/mason-gui-text`"x ]; then
+	    echo "Unable to stop another instance of $0. Exiting ...";
+	    exit 1;
+	fi;
+    else
+	echo "Another instance of $0 is running. Exiting ...";
+	exit 1;
+    fi;
+fi;
+
+
 CKPTMGT=" mgt: Ground0" ; #ckpt $CKPTMGT
 
 MASONDIR=${MASONDIR:-"/var/lib/mason/"}
@@ -118,21 +137,41 @@ killrunningmason
 
 while [ ! "$EXITCONTROL" = "YES" ]; do
 	clear
-	echo $ENH "${HEADER}---- ${BLUE}Mason${HEADER} firewall builder for Linux                         ----$NORM"
-	echo $ENH "${HEADER}---- Learning shell for Mason.                                ----$NORM"
-	echo $ENH "${HEADER}---- see http://www.pobox.com/~wstearns/mason/ for more info. ----$NORM"
-	echo $ENH "${HEADER}---- William Stearns <wstearns@pobox.com>                     ----$NORM"
+	echo "------------------------------------------------------------------"
+	echo $ENH "${HEADER}${BLUE}Mason${HEADER} firewall builder for Linux         $NORM"
+	echo "------------------------------------------------------------------"
+	echo $ENH "${HEADER}---- Learning shell for Mason.                                $NORM"
+	echo $ENH "${HEADER}---- see http://www.pobox.com/~wstearns/mason/ for more info. $NORM"
+	echo $ENH "${HEADER}---- Originally from William Stearns <wstearns@pobox.com>     $NORM"
 	if [ -n "$MASONVER" ]; then
-		echo $ENH "${HEADER}(This is release $MASONVER)$NORM"
+	    echo $ENH "${HEADER}---- This is release $MASONVER $NORM"
 	fi
+	echo "------------------------------------------------------------------"
+        if [ -z  "`/bin/pidof -x /sbin/klogd`" ]; then
+           echo "Warning: No instance of klogd (kernel log deamon) is running,"
+           echo "         mason will not be able to learn new rules."
+	   echo "------------------------------------------------------------------"
+        fi
+        if [ ! -f  "$PACKETLOGFILE" ]; then
+           echo "Warning: The syslog file $PACKETLOGFILE does not exist,"
+           echo "         mason will not be able to learn new rules."
+	   echo "------------------------------------------------------------------"
+	else
+		if [ -z "` find $PACKETLOGFILE -cmin -60`" ]; then
+	        	echo "Warning: No messages was written to the syslog file $PACKETLOGFILE"
+	        	echo "         the last hour, the file is probably not in use by a"
+        		echo "         syslog deamon. Mason will not be able to learn new rules."
+	  		echo "------------------------------------------------------------------"
+		fi
+        fi
 	if [ -n "$MASONPID$MASONTAILPID" ]; then
 		echo Mason is currently in learn mode.
-		echo
+		echo "------------------------------------------------------------------"
 		echo $ENH ${KEY}EL${NORM}: ${KEY}E${NORM}nd ${KEY}L${NORM}earning.
 		showstate 'Mason-gui-text: Main menu, learning in the background'
 	else
 		echo Mason IS NOT currently learning.
-		echo
+		echo "------------------------------------------------------------------"
 		echo $ENH ${KEY}BL${NORM}: ${KEY}B${NORM}egin ${KEY}L${NORM}earning.
 		showstate 'Mason-gui-text: Main menu, not learning'
 	fi
@@ -357,6 +396,12 @@ while [ ! "$EXITCONTROL" = "YES" ]; do
 		killrunningmason
 		flushfirewall
 		runfirewall STANDARD
+		# ---------------------------------------------------------------------
+		# Restart services that modify iptables rules - 2008-04-02 - Scheffczyk
+		# ---------------------------------------------------------------------
+		wrap Restarting services ...
+		RestartServices
+		wrap Done!
 																;;
 	*)	wrap ${WARN}Unknown choice.  Please enter the one or two character code.${NORM}
 																;;
--- mason-1.0.0.orig/mason-gui-text.1
+++ mason-1.0.0/mason-gui-text.1
@@ -1,20 +1,18 @@
-.TH MASON-GUI-TEXT 1 
 .\" NAME should be all caps, SECTION should be 1-8, maybe w/ subsection
 .\" other parms are allowed: see man(7), man(1)
-.SH NAME
+.TH "MASON-GUI-TEXT" "1" "" "" ""
+.SH "NAME"
 mason\-gui\-text \- front end to mason
-.SH SYNOPSIS
-.B mason\-gui\-text
+.SH "SYNOPSIS"
+.B \fBmason\-gui\-text\fR [\fB\-\-force\fR]
 .SH "DESCRIPTION"
 .B mason\-gui\-text
-is a "textual GUI" front end to mason, the interactive firewall
-builder.  When it is run, it allows you to control mason's behavior
-through simple keystroke commands.  It can start and stop mason, allow 
-you to edit the rules generated (and re-merge them into the currently
-running rule set), and change mason's settings.  It also has a
-"console lock" setting for locking the console down if necessary.
+is a "textual GUI" front end to mason, the interactive firewall builder.  When it is run, it allows you to control mason's behavior through simple keystroke commands.  It can start and stop mason, allow you to edit the rules generated (and re\-merge them into the currently running rule set), and change mason's settings.  It also has a "console lock" setting for locking the console down if necessary.
+.SH "OPTIONS"
+Default behaviour of mason\-gui\-text ist to exit if another instance of it is already running.
+.IP "\fB\-\-force\fR
+Try to stop other instances of mason\-gui\-text and continue running
 .SH "SEE ALSO"
-.B "QuickStart, mason(1)"
-.SH AUTHOR
-This manual page was written by Jeff Licquia <jeff@luci.org>,
-for the Debian GNU/Linux system (but may be used by others).
+.B "mason(1)"
+.SH "AUTHOR"
+This manual page was written by Jeff Licquia <jeff@luci.org> for the Debian GNU/Linux system (but may be used by others) and supplemented by Thomas Scheffczyk <scheffczyk@debian.org>.
--- mason-1.0.0.orig/mason.1
+++ mason-1.0.0/mason.1
@@ -1,17 +1,17 @@
-.TH MASON 1 
 .\" NAME should be all caps, SECTION should be 1-8, maybe w/ subsection
 .\" other parms are allowed: see man(7), man(1)
-.SH NAME
+.TH "MASON" "1" "" "" ""
+.SH "NAME"
 mason \- interactively create a firewall
-.SH SYNOPSIS
+.SH "SYNOPSIS"
 .B mason
 .I "< logfile > rulefile"
-.br
+.br 
 .SH "DESCRIPTION"
 This manual page briefly documents the
 .BR mason 
 command.
-.PP
+.PP 
 .B mason
 interactively generates a set of firewall rules for a Linux\-based
 firewall.  This is done by turning on full IP logging, watching the
@@ -21,20 +21,20 @@ seen.
 is familiar with most of the quirks of various connection types (such
 as ftp and IRC), and can output rules for 2.0.x ipfwadm, 2.2.x
 ipchains, and Cisco packet filters.
-.PP
+.PP 
 .B mason
 operates by reading in log file information from standard input and
 writing firewall rules to standard output.  This allows
 .B mason
-to work offline or on a separate system.  Real-time firewall
+to work offline or on a separate system.  Real\-time firewall
 generation can be achieved with a command like tail(1).
-.PP
+.PP 
 Most users will want to run mason with a user\-friendly interface such
 as mason\-gui\-text(1).
-.SH ENVIRONMENT
+.SH "ENVIRONMENT"
 .B mason
 is configured using the following environment variables.
-.TP
+.TP 
 .B ECHOCOMMAND
 Sets the type of firewall rules that
 .B mason
@@ -43,7 +43,7 @@ should output to standard out.  Allowed
 .B mason
 outputs whatever kind of rules are supported by the currently running
 Linux kernel.
-.TP
+.TP 
 .B DOCOMMAND
 Sets the type of firewall rules that
 .B mason
@@ -52,20 +52,20 @@ include "ipfwadm" and "ipchains".  By de
 .B mason
 outputs whatever kind of rules are supported by the currently running
 Linux kernel.
-.TP
+.TP 
 .B HEARTBEAT
 If set to "yes",
 .B mason
-will output a "+" or "-" to standard error whenever a rule generated
+will output a "+" or "\-" to standard error whenever a rule generated
 by
 .B mason
 has been triggered.
-.TP
+.TP 
 .B DYNIP
 Set this to the list of interfaces that have dynamically assigned
 addresses, separated by spaces.
 .SH "SEE ALSO"
-.B "mason.txt, mason\-gui\-text(1)"
-.SH AUTHOR
+.B "mason\-gui\-text(1)"
+.SH "AUTHOR"
 This manual page was written by Jeff Licquia <jeff@luci.org>,
 for the Debian GNU/Linux system (but may be used by others).
--- mason-1.0.0.orig/masonlib
+++ mason-1.0.0/masonlib
@@ -26,10 +26,10 @@
 #		  || logfail $LINENO masonlib: YYYY #### the_command_that_was_supposed_to_run
 #Last YYYY code used: 0149, use 0150 next
 
-if [ -f /usr/lib/samlib/samlib ]; then
-	. /usr/lib/samlib/samlib
+if [ -f /var/lib/mason/samlib ]; then
+	. /var/lib/mason/samlib
 else
-	echo "/usr/lib/samlib/samlib is missing - please get it from" >/dev/stderr
+	echo "/var/lib/mason/samlib is missing - please get it from" >/dev/stderr
 	echo "http://www.stearns.org/samlib/" >/dev/stderr
 	echo "Exiting." >/dev/stderr
 	exit 1
@@ -44,7 +44,7 @@ for ONEFUNC in askYN encompassingnetwork
 	fi
 done
 
-MASONVER="1.0.0, 5/12/2002"
+MASONVER="1.0.0-11 - 2008-06-27"
 
 #-------------------------------------------------------------------------
 # addcounts procedure, adds the packet counts to the rules in a file.
@@ -289,7 +289,7 @@ checkconf () {
 	#SYSTEMRULEFILE=${SYSTEMRULEFILE:-"${MASONDIR}systemrules"} ;	if [ ! -f $SYSTEMRULEFILE ]; then touch $SYSTEMRULEFILE || logfail $LINENO masonlib: 0015 touch $SYSTEMRULEFILE ; fi
 	PACKETLOGFILE=${PACKETLOGFILE:-"/var/log/messages"}
 	MASONEXE=${MASONEXE:-"/usr/bin/mason"}
-	MASONDECIDE=${MASONDECIDE:-"/usr/bin/mason-decide"}
+	MASONDECIDE=${MASONDECIDE:-"/var/lib/mason/mason-decide"}
 
 	CKPTCHECKCONF=" checkconf: Set up ANSI escape codes" ; #ckpt $CKPTCHECKCONF
 	if [ "$USEANSI" != "NO" ]; then
@@ -301,7 +301,8 @@ checkconf () {
 		     BLUE="\033[1;34m"
 		     PINK="\033[1;35m"
 		TURQUOISE="\033[1;36m"
-		     NORM="\033[1;37m"
+#		     NORM="\033[1;37m"
+		     NORM="`tput sgr0 2`"
 		   BRIGHT="\033[1;39m"
 	else
 		      ENH=""
@@ -448,7 +449,7 @@ checkconf () {
 	[Nn][Oo]|[Nn][Oo][Nn][Ee])									ECHOCOMMAND="none"		;;
 	*)	if [ -f /proc/net/ip_fwchains ]; then					ECHOCOMMAND="ipchains"
 		elif [ -f /proc/net/ip_input ]; then					ECHOCOMMAND="ipfwadm"
-		elif [ -n "`lsmod | grep '^ip_tables '`" ]; then		ECHOCOMMAND="iptables"
+		elif [ -f /proc/net/ip_tables_names ]; then		ECHOCOMMAND="iptables"
 		else													ECHOCOMMAND="ipchains"			#Set default here
 		fi																				;;
 	esac
@@ -478,7 +479,7 @@ checkconf () {
 	[Ii][Pp][Tt][Aa][Bb][Ll][Ee][Ss])
 		DOCOMMAND="iptables"
 		#FIXME - how to reliably test for kernel iptables support
-		#if [ -z "`lsmod | grep '^ip_tables '`" ]; then
+		#if -z "`lsmod | grep '^ip_tables '`" ]; then
 		#	wrap ${WARN}WARNING! User has requested iptables, but it appears to be unavailable. Proceeding, but this is not likely to work.${NORM} >/dev/stderr
 		#	sleep 10
 		#fi
@@ -682,10 +683,15 @@ checkconf () {
 
 	CKPTCHECKCONF=" checkconf: Check editor" ; #ckpt $CKPTCHECKCONF
 	if [ -z "$EDITOR" ]; then
-		for TRYEDITOR in `type -path mcedit || :` `type -path pico || :` `type -path vi || :` `type -path jove || :` `type -path nedit || :` `type -path emacs || :` ; do
+		for TRYEDITOR in `type -path emacs || :` `type -path vi || :` `type -path nano || :` `type -path mcedit || :` `type -path pico || :` `type -path jove || :` `type -path nedit || :`  ; do
+		        # 2008-06-27 - Scheffczyk: Added the -nw switch if emacs is choosen as an editor 
 			if [ -z "$EDITOR" ]; then
+			    if [ "$TRYEDITOR"x == "emacs"x ]; then
+				EDITOR="emacs -nw";
+			    else
 				EDITOR=$TRYEDITOR
-				wrap Editor default of $EDITOR taken. >/dev/stderr
+			    fi
+			    wrap Editor default of $EDITOR taken. >/dev/stderr
 			fi
 		done
 		unset TRYEDITOR || :
@@ -716,7 +722,7 @@ checksys () {
 		exit 0
 	fi
 
-	if [ ! -f /proc/net/ip_fwchains ] && [ ! -f /proc/net/ip_input ] && [ -z "`lsmod | grep '^ip_tables '`" ]; then
+	if [ ! -f /proc/net/ip_fwchains ] && [ ! -f /proc/net/ip_input ] && [ ! -f /proc/net/ip_tables_names ]; then
 		wrap ${WARN}This kernel does not support ipchains, ipfwadm or iptables!${NORM} >/dev/stderr
 		#DOCOMMAND="none"		#Should we force to none?
 	fi
@@ -1199,13 +1205,12 @@ dorule () {
 	esac #Case $1=action
 } #End of dorule
 
-
-
 #-------------------------------------------------------------------------
 #Flush the existing rules so we start with a clean slate.
 #-------------------------------------------------------------------------
 flushfirewall () {	#SUDO checked
 	CKPTFLUSHFIREWALL=" flushfirewall: Start" ; #ckpt $CKPTFLUSHFIREWALL
+	savepacketstats
 	updatecounts
 	echo -n Flushing... >/dev/stderr
 
@@ -1229,7 +1234,7 @@ flushfirewall () {	#SUDO checked
 		dorule f "$ONECHAIN" '' '' '' '' '' '' '' '' '' '' '' '' '' || logfail $LINENO masonlib: 0039/0041/0043/0048/0050/0052
 	done
 
-	if [ -f /proc/net/ip_fwchains ] || [ -n "`lsmod | grep '^ip_tables '`" ]; then
+	if [ -f /proc/net/ip_fwchains ] || [ -f /proc/net/ip_tables_names ]; then
 		#Flush the nolog chains if they exist, create them if not.
 		CKPTFLUSHFIREWALL=" flushfirewall: Create or flush nolog chains." ; #ckpt $CKPTFLUSHFIREWALL
 		if [ -n "$NOLOGSUFFIX" ]; then
@@ -1257,15 +1262,19 @@ flushornewchain () {	#SUDO checked
 		if [ -f /proc/net/ip_fwchains ]; then
 			#REMOVEME
 			#if [ `$SUDO $IPCHAINSBIN -L -n | grep "^Chain $CHAINNAME" | wc -l` -gt 0 ]; then
-			if $SUDO $IPCHAINSBIN -L $CHAINNAME >/dev/null 2>/dev/null ; then	#If chain exists
+		        # 2008-03-25 - Scheffczyk: Added the '-n' switch to the call of 'iptables -L' 
+		        # to avoid DNS calls when merely checking for the exisitence of a chain.
+			if $SUDO $IPCHAINSBIN -n -L $CHAINNAME >/dev/null 2>/dev/null ; then	#If chain exists
 				$SUDO $IPCHAINSBIN -F $CHAINNAME >/dev/null 2>/dev/null || logfail $LINENO masonlib: 0044/0070/0089/0134 $IPCHAINSBIN -F $CHAINNAME
 			else
 				$SUDO $IPCHAINSBIN -N $CHAINNAME >/dev/null 2>/dev/null || logfail $LINENO masonlib: 0045/0071/0090 $IPCHAINSBIN -N $CHAINNAME
 			fi
-		elif [ -n "`lsmod | grep '^ip_tables '`" ]; then
+		elif [ -f /proc/net/ip_tables_names ]; then
 #FIXME, check everywhere.
 #if iptables -L -n >/dev/null 2>/dev/null ; then echo iptables successful ; fi
-			if $SUDO $IPTABLESBIN -L $CHAINNAME >/dev/null 2>/dev/null ; then	#If chain exists
+		        # 2008-03-25 - Scheffczyk: Added the '-n' switch to the call of 'iptables -L' 
+		        # to avoid DNS calls when merely checking for the exisitence of a chain.
+			if $SUDO $IPTABLESBIN -n -L $CHAINNAME >/dev/null 2>/dev/null ; then	#If chain exists
 				$SUDO $IPTABLESBIN -F $CHAINNAME >/dev/null 2>/dev/null || logfail $LINENO masonlib: 0135 $IPTABLESBIN -F $CHAINNAME
 			else
 				$SUDO $IPTABLESBIN -N $CHAINNAME >/dev/null 2>/dev/null || logfail $LINENO masonlib: 0136 $IPTABLESBIN -N $CHAINNAME
@@ -1901,7 +1910,7 @@ runfirewall () {	#SUDO checked
 		done
 	else echo -n No Blockedhost blocks... ; fi
 
-	if [ -f /proc/net/ip_fwchains ] || [ -n "`lsmod | grep '^ip_tables '`" ]; then
+	if [ -f /proc/net/ip_fwchains ] || [ -f /proc/net/ip_tables_names ]; then
 		CKPTRUNFIREWALL=" runfirewall: ipchains/iptables spoofblocks" ; #ckpt $CKPTRUNFIREWALL
 		if [ "$SPOOFBLOCKS" = "YES" ]; then
 			echo -n Spoof blocks...
@@ -1913,7 +1922,7 @@ runfirewall () {	#SUDO checked
 			#$IPCHAINSBIN -I input -j NoSpoof || logfail $LINENO masonlib: YYYY 0072
 			dorule i input '' '' '' '' '' '' '' '' '' "NoSpoof" '' '' '' || logfail $LINENO masonlib: YYYY 0072
 			#In iptables, we have to check for spoofing on the forward chain as well.
-			if [ -n "`lsmod | grep '^ip_tables '`" ]; then
+			if [ -f /proc/net/ip_tables_names ]; then
 				dorule i forward '' '' '' '' '' '' '' '' '' "NoSpoof" '' '' '' || logfail $LINENO masonlib: YYYY 0137
 			fi
 
@@ -2313,7 +2322,9 @@ sortrulefile () {
 		for SECTION in `seqfunc 0 $FILECOUNT` ; do
 			if [ -f "$ONEFILE.$SECTION" ]; then
 				if [ `grep '#\^' $ONEFILE.$SECTION | wc -l` -gt 0 ]; then
-					sort -t '^' +1 -n -r $ONEFILE.$SECTION >>$ONEFILE.new || logfail $LINENO masonlib: YYYY 0120
+					# 2007-03-23 Scheffczyk
+					# Original line was: sort -t '^' +1 -n -r $ONEFILE.$SECTION >>$ONEFILE.new || logfail $LINENO masonlib: YYYY 0120
+					sort -t '^' -k 1 -n -r $ONEFILE.$SECTION >>$ONEFILE.new || logfail $LINENO masonlib: YYYY 0120
 				else
 					cat $ONEFILE.$SECTION >>$ONEFILE.new || logfail $LINENO masonlib: YYYY 0121
 				fi
@@ -2350,12 +2361,14 @@ uniqrulefile () {
 	cp -pf $1 $1.bak || logfail $LINENO masonlib: YYYY 0125
 	#sort -t '#' +1 $1 | uniq >$1.sorted			#This worked until we had mark values.
 	CKPTUNIQRULEFILE=" uniqrulefile: main pipeline" ; #ckpt $CKPTUNIQRULEFILE
+        # 2007-03-23 Scheffczyk
+	# Original line was: sort -t '#' +1 | \
 	cat $1 | \
 	sed -e 's/^/!!! /' \
 		-e 's/^!!! \(.* -m \)\([0-9][0-9]*\)\( .*\)/\2 \1ZzMaRkZz\3/' | \
 	sort +1 | \
 	uniq -1 | \
-	sort -t '#' +1 | \
+	sort -t '#' -k 1 | \
 	uniq -1 | \
 	sed -e 's/^\([0-9][0-9]*\) \(.* -m \)ZzMaRkZz\( .*\)/\2\1\3/' \
 		-e 's/^!!! //' >$1.sorted || logfail $LINENO masonlib: YYYY 0126
@@ -2419,3 +2432,49 @@ updatecounts () {
 } #End of updatecounts
 
 
+#-------------------------------------------------------------------------
+# Save packet stats to a file for each chain - 2008-04-03 - Scheffczyk
+#-------------------------------------------------------------------------
+savepacketstats () {
+    if [ "$PACKETSTATS_SAVE"x = "yes"x ]
+    then
+	if [ -z "$PACKETSTATS_LOGDIR" ]; then
+	    $PACKETSTATS_LOGDIR="/var/log/mason";
+	fi;
+	if [ ! -d "$PACKETSTATS_LOGDIR" ]; then
+	    mkdir -p $PACKETSTATS_LOGDIR;
+	fi;
+	if [ -z "$PACKETSTATS_MAX_AGE" ]
+	then
+	     find $PACKETSTATS_LOGDIR/ -mtime +$PACKETSTATS_MAX_AGE -exec rm {} \;
+	fi
+	PACKETSTATS_TIMESTAMP=$(date +%Y.%m.%d.%H.%M.%S)
+	TABLES="nat filter"
+	for TABLE in $TABLES
+	do
+	  CHAINS=`$IPTABLESBIN -L -n -t $TABLE | fgrep Chain | awk '{ print $2; }'`
+	  for CHAIN in $CHAINS
+	  do
+	    $IPTABLESBIN -n -x -v -t $TABLE -L $CHAIN > $PACKETSTATS_LOGDIR/$TABLE.$CHAIN.$PACKETSTATS_TIMESTAMP
+	  done
+	done
+    fi 
+}
+
+# ---------------------------------------------------------------------
+# Restart services that modify iptables rules - 2008-04-02 - Scheffczyk
+# ---------------------------------------------------------------------
+RestartServices() {
+    unset SERVICE;
+    if [ -z "$SERVICE_RESTART_DIR" ]; then
+	SERVICE_RESTART_DIR="/etc/mason.d/restart.d";
+    fi;
+    if [ ! -d "$SERVICE_RESTART_DIR" ]; then
+	mkdir -p $SERVICE_RESTART_DIR;
+    fi;
+    if [ $(ls -1 "$SERVICE_RESTART_DIR/" | wc -l) -ne 0 ]; then
+	for SERVICE in $(ls -1 $SERVICE_RESTART_DIR/*| egrep -v "[#~]"); do
+	    $SERVICE restart
+	done;
+    fi;
+}
--- mason-1.0.0.orig/masonrc
+++ mason-1.0.0/masonrc
@@ -1,5 +1,8 @@
-#WARNING - If you are upgrading from a previous version, the uncommented
-#lines in your old masonrc have been appended to the end of this file.  
+#===========================================================
+# WARNING - If you are upgrading from a previous version, the uncommented
+# lines in your old masonrc have been appended to the end of this file.  
+#===========================================================
+
 #Please note that the NAMECACHE, NETCACHE, and SERVICES fields are no longer used.
 
 #For instructions on how to set the parameters in this file, refer to 
@@ -60,6 +63,59 @@
 #FLUSHEDPOLICY="reject"
 #FLUSHEDPOLICY="deny"
 
+#===========================================================
+# New settings for the debian version of mason - BEGIN
+#===========================================================
+# Property: SERVICE_RESTART_DIR 
+#-----------------------------------------------------------
+# Type    : string
+# value   : the name of a directory
+# Default : /etc/mason.d/restart.d
+# Descr.  : All scripts in this directory will be executed 
+#           with the command line parameter 'restart'. 
+# Hints   : - A common way to use this feature is to link to 
+#             init scripts, for example:
+#             ln -s /etc/init.d/fail2ban /etc/mason.d/restart.d/
+#-----------------------------------------------------------
+# SERVICE_RESTART_DIR="/etc/mason.d/restart.d"
+
+#-----------------------------------------------------------
+# Property: PACKETSTATS_SAVE 
+#-----------------------------------------------------------
+# Type    : string
+# value   : "yes" or "no"
+# Default : "no"
+# Descr.  : If the value of this property is set to "yes" 
+#           the counters for each rule a saved before the
+#           iptables chains are flushed 
+#-----------------------------------------------------------
+# PACKETSTATS_SAVE="no"
+
+#-----------------------------------------------------------
+# Property: PACKETSTATS_MAX_AGE
+#-----------------------------------------------------------
+# Type    : integer
+# value   : maximum age of saved saved counters in days
+# Default : 30
+# Descr.  : If the value of this property is set, saved
+#           counters are deleted when older as set here
+#-----------------------------------------------------------
+# PACKETSTATS_MAX_AGE=30
+
+#-----------------------------------------------------------
+# Property: PACKETSTATS_LOGDIR
+#-----------------------------------------------------------
+# Type    : string
+# value   : the name of a directory
+# Default : /var/log/mason
+# Descr.  : The directory where the counters are saved
+#-----------------------------------------------------------
+# PACKETSTATS_LOGDIR="/var/log/mason"
+
+#===========================================================
+# New settings for the debian version of mason - END
+#===========================================================
+
 #-----------------------------------------------------------
 # Moderate likelihood you may wish to tune these, probably once.
 #-----------------------------------------------------------
@@ -154,6 +210,7 @@
 #Use ANSI escape sequences to enhance display.  Default YES.
 #Set this to no if your terminal doesn't support ANSI colors, etc.
 #USEANSI="YES"
+USEANSI="NO"
 
 # The range of ports considered to be IRC server ports.
 # Default: 6666 to 6671
@@ -458,7 +515,7 @@
 #Location of runtime changeable files and configuration.
 #Make sure you include the trailing slash.
 # Default: "/var/lib/mason/"
-#MASONDIR="/var/lib/mason/"
+MASONDIR="/var/lib/mason/"
 
 #This is the configuration file mason uses.  It can be changed while
 #Mason is running as long as the SIGUSR1 signal is sent to Mason afterwards.
@@ -507,7 +564,7 @@
 #/etc/rc.d/init.d/firewall start
 #
 #MASONEXE="/usr/bin/mason"
-#MASONDECIDE="/usr/bin/mason-decide"
+#MASONDECIDE="/var/lib/mason/mason-decide"
 #IPFWADMBIN="/sbin/ipfwadm"
 #IPCHAINSBIN="/sbin/ipchains"
 #Note - ipnatctl is not used any more.
--- mason-1.0.0.orig/samlib
+++ mason-1.0.0/samlib
@@ -617,7 +617,7 @@ fi
 requireutil ifconfig awk || exit 1
 #Checks done on the following function: 
 ipof () {	#SUDO checked
-    ifconfig $1 2>/dev/null | awk '/inet addr/{print substr($2,6)}'
+    LC_ALL=C ifconfig $1 2>/dev/null | awk '/inet addr/{print substr($2,6)}'
 } #End of ipof
 if [ "$DOREGRESSIONTEST" = "YES" ]; then
 	echo -n ipof...