1Upstream-Status: Inappropriate [No upstream maintenance]
2
3Signed-off-by: Anne Mulhern <mulhern@yoctoproject.org>
4
5---
6
7Index: Bastille/Bastille/API.pm
8===================================================================
9--- Bastille.orig/Bastille/API.pm	2013-08-22 04:32:38.269968002 -0400
10+++ Bastille/Bastille/API.pm	2013-08-22 11:29:53.137968002 -0400
11@@ -141,7 +141,7 @@
12     checkProcsForService
13
14
15-    $GLOBAL_OS $GLOBAL_ACTUAL_OS $CLI
16+    $CLI
17     $GLOBAL_LOGONLY $GLOBAL_VERBOSE $GLOBAL_DEBUG $GLOBAL_AUDITONLY $GLOBAL_AUDIT_NO_BROWSER $errorFlag
18     %GLOBAL_BIN %GLOBAL_DIR %GLOBAL_FILE
19     %GLOBAL_BDIR %GLOBAL_BFILE
20@@ -198,7 +198,7 @@
21 my $err ="ERROR:  ";
22 my $spc ="        ";
23 my $GLOBAL_OS="None";
24-my $GLOBAL_ACTUAL_OS="None";
25+my $GLOBAL_INFERRED_OS="None";
26 my %GLOBAL_SUMS=();
27 my $CLI='';
28
29@@ -306,7 +306,7 @@
30
31 ###########################################################################
32 #
33-# GetDistro checks to see if the target is a known distribution and reports
34+# InferDistro checks to see if the target is a known distribution and reports
35 # said distribution.
36 #
37 # This is used throughout the script, but also by ConfigureForDistro.
38@@ -314,205 +314,194 @@
39 #
40 ###########################################################################
41
42-sub GetDistro() {
43+sub InferDistro() {
44
45     my ($release,$distro);
46
47-    # Only read files for the distro once.
48-    # if the --os option was used then
49-    if ($GLOBAL_OS eq "None") {
50-	if ( -e "/etc/mandrake-release" ) {
51-	    open(MANDRAKE_RELEASE,"/etc/mandrake-release");
52-	    $release=<MANDRAKE_RELEASE>;
53-
54-	    if ( ($release =~ /^Mandrake Linux release (\d+\.\d+\w*)/) or ($release =~ /^Linux Mandrake release (\d+\.\d+\w*)/) ) {
55-		$distro="MN$1";
56-	    }
57-	    elsif ( $release =~ /^Mandrakelinux release (\d+\.\d+)\b/ ) {
58-                $distro="MN$1";
59-            }
60-            else {
61-		print STDERR "$err Couldn't determine Mandrake/Mandriva version! Setting to 10.1!\n";
62-		$distro="MN10.1";
63-	    }
64-
65-	    close(MANDRAKE_RELEASE);
66-	}
67-	elsif ( -e "/etc/immunix-release" ) {
68-	    open(IMMUNIX_RELEASE,"/etc/immunix-release");
69-	    $release=<IMMUNIX_RELEASE>;
70-	    unless ($release =~ /^Immunix Linux release (\d+\.\d+\w*)/) {
71-		print STDERR "$err Couldn't determine Immunix version! Setting to 6.2!\n";
72-		$distro="RH6.2";
73-	    }
74-	    else {
75-		$distro="RH$1";
76-	    }
77-	    close(*IMMUNIX_RELEASE);
78-	}
79-	elsif ( -e '/etc/fedora-release' ) {
80-            open(FEDORA_RELEASE,'/etc/fedora-release');
81-            $release=<FEDORA_RELEASE>;
82-            close FEDORA_RELEASE;
83-            if ($release =~ /^Fedora Core release (\d+\.?\d*)/) {
84-                $distro = "RHFC$1";
85-            }
86-	    elsif ($release =~ /^Fedora release (\d+\.?\d*)/) {
87-                $distro = "RHFC$1";
88-            }
89-            else {
90-                print STDERR "$err Could not determine Fedora version! Setting to Fedora Core 8\n";
91-                $distro='RHFC8';
92-            }
93+    if ( -e "/etc/mandrake-release" ) {
94+        open(MANDRAKE_RELEASE,"/etc/mandrake-release");
95+        $release=<MANDRAKE_RELEASE>;
96+
97+        if ( ($release =~ /^Mandrake Linux release (\d+\.\d+\w*)/) or ($release =~ /^Linux Mandrake release (\d+\.\d+\w*)/) ) {
98+	    $distro="MN$1";
99+	}
100+	elsif ( $release =~ /^Mandrakelinux release (\d+\.\d+)\b/ ) {
101+            $distro="MN$1";
102+        }
103+        else {
104+            print STDERR "$err Could not infer Mandrake/Mandriva version! Setting to 10.1!\n";
105+	    $distro="MN10.1";
106+	}
107+
108+        close(MANDRAKE_RELEASE);
109+    }
110+    elsif ( -e "/etc/immunix-release" ) {
111+        open(IMMUNIX_RELEASE,"/etc/immunix-release");
112+        $release=<IMMUNIX_RELEASE>;
113+        unless ($release =~ /^Immunix Linux release (\d+\.\d+\w*)/) {
114+            print STDERR "$err Could not infer Immunix version! Setting to 6.2!\n";
115+	    $distro="RH6.2";
116+        }
117+	else {
118+	    $distro="RH$1";
119 	}
120-	elsif ( -e "/etc/redhat-release" ) {
121-	    open(*REDHAT_RELEASE,"/etc/redhat-release");
122-	    $release=<REDHAT_RELEASE>;
123-	    if ($release =~ /^Red Hat Linux release (\d+\.?\d*\w*)/) {
124-		$distro="RH$1";
125-	    }
126-            elsif ($release =~ /^Red Hat Linux .+ release (\d+)\.?\d*([AEW]S)/) {
127-                $distro="RHEL$1$2";
128-            }
129-	    elsif ($release =~ /^Red Hat Enterprise Linux ([AEW]S) release (\d+)/) {
130-		$distro="RHEL$2$1";
131+	close(*IMMUNIX_RELEASE);
132+    }
133+    elsif ( -e '/etc/fedora-release' ) {
134+        open(FEDORA_RELEASE,'/etc/fedora-release');
135+        $release=<FEDORA_RELEASE>;
136+        close FEDORA_RELEASE;
137+        if ($release =~ /^Fedora Core release (\d+\.?\d*)/) {
138+            $distro = "RHFC$1";
139+        }
140+	elsif ($release =~ /^Fedora release (\d+\.?\d*)/) {
141+            $distro = "RHFC$1";
142+        }
143+        else {
144+            print STDERR "$err Could not infer Fedora version! Setting to Fedora Core 8\n";
145+            $distro='RHFC8';
146+        }
147+    }
148+    elsif ( -e "/etc/redhat-release" ) {
149+        open(*REDHAT_RELEASE,"/etc/redhat-release");
150+        $release=<REDHAT_RELEASE>;
151+        if ($release =~ /^Red Hat Linux release (\d+\.?\d*\w*)/) {
152+	    $distro="RH$1";
153+	}
154+        elsif ($release =~ /^Red Hat Linux .+ release (\d+)\.?\d*([AEW]S)/) {
155+            $distro="RHEL$1$2";
156+        }
157+	elsif ($release =~ /^Red Hat Enterprise Linux ([AEW]S) release (\d+)/) {
158+	    $distro="RHEL$2$1";
159+	}
160+	elsif ($release =~ /^CentOS release (\d+\.\d+)/) {
161+	    my $version = $1;
162+	    if ($version =~ /^4\./) {
163+	        $distro='RHEL4AS';
164 	    }
165-	    elsif ($release =~ /^CentOS release (\d+\.\d+)/) {
166-		my $version = $1;
167-		if ($version =~ /^4\./) {
168-		    $distro='RHEL4AS';
169-		}
170-		elsif ($version =~ /^3\./) {
171-		    $distro='RHEL3AS';
172-		}
173-		else {
174-		    print STDERR "$err Could not determine CentOS version! Setting to Red Hat Enterprise 4 AS.\n";
175-		    $distro='RHEL4AS';
176-                 }
177-	    }
178- 	    else {
179-		# JJB/HP - Should this be B_log?
180-		print STDERR "$err Couldn't determine Red Hat version! Setting to 9!\n";
181-		$distro="RH9";
182-	    }
183-	    close(REDHAT_RELEASE);
184-
185-	}
186-	elsif ( -e "/etc/debian_version" ) {
187-	    $stable="3.1"; #Change this when Debian stable changes
188-	    open(*DEBIAN_RELEASE,"/etc/debian_version");
189-	    $release=<DEBIAN_RELEASE>;
190-	    unless ($release =~ /^(\d+\.\d+\w*)/) {
191-		print STDERR "$err System is not running a stable Debian GNU/Linux version. Setting to $stable.\n";
192-		$distro="DB$stable";
193+	    elsif ($version =~ /^3\./) {
194+	        $distro='RHEL3AS';
195 	    }
196 	    else {
197-		$distro="DB$1";
198-	    }
199-	    close(DEBIAN_RELEASE);
200-	}
201-	elsif ( -e "/etc/SuSE-release" ) {
202-	    open(*SUSE_RELEASE,"/etc/SuSE-release");
203-	    $release=<SUSE_RELEASE>;
204-	    if ($release =~ /^SuSE Linux (\d+\.\d+\w*)/i) {
205-		$distro="SE$1";
206-	    }
207-	    elsif ($release =~ /^SUSE LINUX Enterprise Server (\d+\.?\d?\w*)/i) {
208-		$distro="SESLES$1";
209-	    }
210-	    elsif ($release =~ /^SUSE Linux Enterprise Server (\d+\.?\d?\w*)/i) {
211-		$distro="SESLES$1";
212-	    }
213-            elsif ($release =~ /^openSuSE (\d+\.\d+\w*)/i) {
214-                $distro="SE$1";
215+	        print STDERR "$err Could not infer CentOS version! Setting to Red Hat Enterprise 4 AS.\n";
216+	        $distro='RHEL4AS';
217             }
218-	    else {
219-		print STDERR "$err Couldn't determine SuSE version! Setting to 10.3!\n";
220-		$distro="SE10.3";
221-	    }
222-	    close(SUSE_RELEASE);
223-	}
224-	elsif ( -e "/etc/turbolinux-release") {
225-	    open(*TURBOLINUX_RELEASE,"/etc/turbolinux-release");
226-	    $release=<TURBOLINUX_RELEASE>;
227-	    unless ($release =~ /^Turbolinux Workstation (\d+\.\d+\w*)/) {
228-		print STDERR "$err Couldn't determine TurboLinux version! Setting to 7.0!\n";
229-		$distro="TB7.0";
230-	    }
231-	    else {
232-		$distro="TB$1";
233-	    }
234-	    close(TURBOLINUX_RELEASE);
235+        }
236+ 	else {
237+	    # JJB/HP - Should this be B_log?
238+	    print STDERR "$err Could not infer Red Hat version! Setting to 9!\n";
239+	    $distro="RH9";
240+	}
241+	close(REDHAT_RELEASE);
242+
243+    }
244+    elsif ( -e "/etc/debian_version" ) {
245+        $stable="3.1"; #Change this when Debian stable changes
246+        open(*DEBIAN_RELEASE,"/etc/debian_version");
247+        $release=<DEBIAN_RELEASE>;
248+        unless ($release =~ /^(\d+\.\d+\w*)/) {
249+  	    print STDERR "$err System is not running a stable Debian GNU/Linux version. Setting to $stable.\n";
250+	    $distro="DB$stable";
251+        }
252+        else {
253+	    $distro="DB$1";
254+	}
255+	close(DEBIAN_RELEASE);
256+    }
257+    elsif ( -e "/etc/SuSE-release" ) {
258+        open(*SUSE_RELEASE,"/etc/SuSE-release");
259+        $release=<SUSE_RELEASE>;
260+        if ($release =~ /^SuSE Linux (\d+\.\d+\w*)/i) {
261+	    $distro="SE$1";
262+        }
263+        elsif ($release =~ /^SUSE LINUX Enterprise Server (\d+\.?\d?\w*)/i) {
264+	    $distro="SESLES$1";
265+        }
266+	elsif ($release =~ /^SUSE Linux Enterprise Server (\d+\.?\d?\w*)/i) {
267+	    $distro="SESLES$1";
268+	}
269+        elsif ($release =~ /^openSuSE (\d+\.\d+\w*)/i) {
270+            $distro="SE$1";
271+        }
272+	else {
273+	    print STDERR "$err Could not infer SuSE version! Setting to 10.3!\n";
274+	    $distro="SE10.3";
275 	}
276+	close(SUSE_RELEASE);
277+    }
278+    elsif ( -e "/etc/turbolinux-release") {
279+        open(*TURBOLINUX_RELEASE,"/etc/turbolinux-release");
280+        $release=<TURBOLINUX_RELEASE>;
281+        unless ($release =~ /^Turbolinux Workstation (\d+\.\d+\w*)/) {
282+	    print STDERR "$err Could not infer TurboLinux version! Setting to 7.0!\n";
283+	    $distro="TB7.0";
284+        }
285 	else {
286-	    # We're either on Mac OS X, HP-UX or an unsupported O/S.
287-            if ( -x '/usr/bin/uname') {
288+	    $distro="TB$1";
289+	}
290+	close(TURBOLINUX_RELEASE);
291+    }
292+    else {
293+        # We're either on Mac OS X, HP-UX or an unsupported O/S.
294+        if ( -x '/usr/bin/uname') {
295 		# uname is in /usr/bin on Mac OS X and HP-UX
296-		$release=`/usr/bin/uname -sr`;
297-	    }
298-	    else {
299-                print STDERR "$err Could not determine operating system version!\n";
300-		$distro="unknown"
301-            }
302-
303-	    # Figure out what kind of system we're on.
304-	    if ($release ne "") {
305-		if ($release =~ /^Darwin\s+(\d+)\.(\d+)/) {
306-		    if ($1 == 6 ) {
307-			$distro = "OSX10.2";
308-		    }
309-		    elsif ($1 == 7) {
310-			$distro = "OSX10.3";
311-		    }
312-                    elsif ($1 == 8) {
313-                        $distro = "OSX10.3";
314-                    }
315-		    else {
316-		        $distro = "unknown";
317-		    }
318+	    $release=`/usr/bin/uname -sr`;
319+	}
320+	else {
321+            print STDERR "$err Could not infer operating system version from filesystem context. Setting inferred distro to 'unknown'.\n";
322+	    $distro="unknown";
323+        }
324+
325+	# Figure out what kind of system we're on.
326+	if ($release ne "") {
327+	    if ($release =~ /^Darwin\s+(\d+)\.(\d+)/) {
328+	        if ($1 == 6 ) {
329+		    $distro = "OSX10.2";
330 		}
331-	        elsif ( $release =~ /(^HP-UX)\s*B\.(\d+\.\d+)/ ) {
332-		   $distro="$1$2";
333+		elsif ($1 == 7) {
334+		    $distro = "OSX10.3";
335 		}
336+                elsif ($1 == 8) {
337+                    $distro = "OSX10.3";
338+                }
339 		else {
340-		   print STDERR "$err Could not determine operating system version!\n";
341-	           $distro="unknown";
342+                    print STDERR "$err Could not infer operating system version from filesystem context. Setting inferred distro to 'unknown'.\n";
343+		    $distro = "unknown";
344 		}
345 	    }
346+	    elsif ( $release =~ /(^HP-UX)\s*B\.(\d+\.\d+)/ ) {
347+	        $distro="$1$2";
348+	    }
349+	    else {
350+                print STDERR "$err Could not infer operating system version from filesystem context. Setting inferred distro to 'unknown'.\n";
351+	        $distro="unknown";
352+	    }
353 	}
354-
355-	$GLOBAL_OS=$distro;
356-    } elsif (not (defined $GLOBAL_OS)) {
357-        print "ERROR: GLOBAL OS Scoping Issue\n";
358-    } else {
359-        $distro = $GLOBAL_OS;
360     }
361-
362     return $distro;
363 }
364
365 ###################################################################################
366-#   &getActualDistro;                                                             #
367+#   &getInferredDistro;                                                             #
368 #                                                                                 #
369 #    This subroutine returns the actual os version in which is running on.  This  #
370 #    os version is independent of the --os switch feed to bastille.               #
371 #                                                                                 #
372 ###################################################################################
373-sub getActualDistro {
374-    # set local variable to $GLOBAL_OS
375+sub getInferredDistro {
376+    if ($GLOBAL_INFERRED_OS eq "None") {
377+        $GLOBAL_INFERRED_OS = &InferDistro;
378+    }
379+    return $GLOBAL_INFERRED_OS;
380+}
381
382-    if ($GLOBAL_ACTUAL_OS eq "None") {
383-        my $os = $GLOBAL_OS;
384-        # undef GLOBAL_OS so that the GetDistro routine will return
385-        # the actualDistro, it might otherwise return the distro set
386-        # by the --os switch.
387-        $GLOBAL_OS = "None";
388-        $GLOBAL_ACTUAL_OS = &GetDistro;
389-        # reset the GLOBAL_OS variable
390-        $GLOBAL_OS = $os;
391+sub GetDistro {
392+    if ($GLOBAL_OS eq "None") {
393+        return &getInferredDistro;
394     }
395-    return $GLOBAL_ACTUAL_OS;
396+    return $GLOBAL_OS;
397 }
398+
399 # These are helper routines which used to be included inside GetDistro
400 sub is_OS_supported($) {
401    my $os=$_[0];
402@@ -556,7 +545,8 @@
403 			      "SE7.2","SE7.3", "SE8.0","SE8.1","SE9.0","SE9.1",
404 			      "SE9.2","SE9.3","SE10.0","SE10.1","SE10.2","SE10.3",
405 			      "SESLES8","SESLES9","SESLES10",
406-			      "TB7.0"
407+			      "TB7.0",
408+                              "Yocto"
409 			      ],
410
411 		  "HP-UX" => [
412@@ -882,23 +872,19 @@
413 ###########################################################################
414 sub ConfigureForDistro {
415
416-    my $retval=1;
417-
418-    # checking to see if the os version given is in fact supported
419     my $distro = &GetDistro;
420
421-    # checking to see if the actual os version is in fact supported
422-    my $actualDistro = &getActualDistro;
423+    my $inferredDistro = &getInferredDistro;
424+
425+    if (! ($inferredDistro eq $distro) ) {
426+        print STDERR "WARNING: Inferred distro $inferredDistro is not the same as specified distro $distro. Using specified distro.\n";
427+    }
428+
429     $ENV{'LOCALE'}=''; # So that test cases checking for english results work ok.
430-    if ((! &is_OS_supported($distro)) or (! &is_OS_supported($actualDistro))  ) {
431-	# if either is not supported then print out a list of supported versions
432-	if (! &is_OS_supported($distro)) {
433-	    print STDERR "$err '$distro' is not a supported operating system.\n";
434-	}
435-	else {
436-	    print STDERR "$err Bastille is unable to operate correctly on this\n";
437-	    print STDERR "$spc $distro operating system.\n";
438-	}
439+
440+    if (! &is_OS_supported($distro)) {
441+	print STDERR "$err '$distro' is not a supported operating system.\n";
442+
443 	my %supportedOSHash = &getSupportedOSHash;
444 	print STDERR "$spc Valid operating system versions are as follows:\n";
445
446@@ -930,7 +916,7 @@
447     # intend via setting the Perl umask
448     umask(077);
449
450-    &getFileAndServiceInfo($distro,$actualDistro);
451+    &getFileAndServiceInfo($distro,$distro);
452
453 #    &dumpFileInfo;  # great for debuging file location issues
454 #    &dumpServiceInfo; # great for debuging service information issues
455@@ -942,7 +928,7 @@
456 	    "$spc You must use Bastille\'s -n flag (for example:\n" .
457 	    "$spc bastille -f -n) or \'touch $nodisclaim_file \'\n";
458
459-    return $retval;
460+    return 1;
461 }
462
463
464Index: Bastille/Bastille/LogAPI.pm
465===================================================================
466--- Bastille.orig/Bastille/LogAPI.pm	2013-08-22 04:32:38.269968002 -0400
467+++ Bastille/Bastille/LogAPI.pm	2013-08-22 04:32:47.509968002 -0400
468@@ -111,7 +111,7 @@
469    # do this here to prevent bootstrapping problem, where we need to
470    # write an error that the errorlog location isn't defined.
471    my $logdir="/var/log/Bastille";
472-   if(&getActualDistro =~ "^HP-UX"){
473+   if(&getInferredDistro =~ "^HP-UX"){
474        $logdir = "/var/opt/sec_mgmt/bastille/log/";
475    }
476
477