aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-security/bastille/files/organize_distro_discovery.patch
blob: d64d1e26e40aa2fba7dc4ef407b4d9fee6ba5ca7 (plain)
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
Upstream Status: Inappropriate [No upstream maintenance]

Signed-off-by: Anne Mulhern <mulhern@yoctoproject.org>

---

Index: Bastille/Bastille/API.pm
===================================================================
--- Bastille.orig/Bastille/API.pm	2013-08-22 04:32:38.269968002 -0400
+++ Bastille/Bastille/API.pm	2013-08-22 11:29:53.137968002 -0400
@@ -141,7 +141,7 @@
     checkProcsForService
     
     
-    $GLOBAL_OS $GLOBAL_ACTUAL_OS $CLI
+    $CLI
     $GLOBAL_LOGONLY $GLOBAL_VERBOSE $GLOBAL_DEBUG $GLOBAL_AUDITONLY $GLOBAL_AUDIT_NO_BROWSER $errorFlag
     %GLOBAL_BIN %GLOBAL_DIR %GLOBAL_FILE
     %GLOBAL_BDIR %GLOBAL_BFILE
@@ -198,7 +198,7 @@
 my $err ="ERROR:  ";
 my $spc ="        ";
 my $GLOBAL_OS="None";
-my $GLOBAL_ACTUAL_OS="None";
+my $GLOBAL_INFERRED_OS="None";
 my %GLOBAL_SUMS=();
 my $CLI='';
 
@@ -306,7 +306,7 @@
 
 ###########################################################################
 #
-# GetDistro checks to see if the target is a known distribution and reports
+# InferDistro checks to see if the target is a known distribution and reports
 # said distribution.
 #
 # This is used throughout the script, but also by ConfigureForDistro.
@@ -314,205 +314,194 @@
 #
 ###########################################################################
 
-sub GetDistro() {
+sub InferDistro() {
 
     my ($release,$distro);
 
-    # Only read files for the distro once.
-    # if the --os option was used then
-    if ($GLOBAL_OS eq "None") {
-	if ( -e "/etc/mandrake-release" ) {
-	    open(MANDRAKE_RELEASE,"/etc/mandrake-release");
-	    $release=<MANDRAKE_RELEASE>;
-
-	    if ( ($release =~ /^Mandrake Linux release (\d+\.\d+\w*)/) or ($release =~ /^Linux Mandrake release (\d+\.\d+\w*)/) ) {
-		$distro="MN$1";
-	    }
-	    elsif ( $release =~ /^Mandrakelinux release (\d+\.\d+)\b/ ) {
-                $distro="MN$1";
-            }
-            else {
-		print STDERR "$err Couldn't determine Mandrake/Mandriva version! Setting to 10.1!\n";
-		$distro="MN10.1";
-	    }
-
-	    close(MANDRAKE_RELEASE);
-	}
-	elsif ( -e "/etc/immunix-release" ) {
-	    open(IMMUNIX_RELEASE,"/etc/immunix-release");
-	    $release=<IMMUNIX_RELEASE>;
-	    unless ($release =~ /^Immunix Linux release (\d+\.\d+\w*)/) {
-		print STDERR "$err Couldn't determine Immunix version! Setting to 6.2!\n";
-		$distro="RH6.2";
-	    }
-	    else {
-		$distro="RH$1";
-	    }
-	    close(*IMMUNIX_RELEASE);
-	}
-	elsif ( -e '/etc/fedora-release' ) {
-            open(FEDORA_RELEASE,'/etc/fedora-release');
-            $release=<FEDORA_RELEASE>;
-            close FEDORA_RELEASE;
-            if ($release =~ /^Fedora Core release (\d+\.?\d*)/) {
-                $distro = "RHFC$1";
-            }
-	    elsif ($release =~ /^Fedora release (\d+\.?\d*)/) {
-                $distro = "RHFC$1";
-            } 
-            else {
-                print STDERR "$err Could not determine Fedora version! Setting to Fedora Core 8\n";
-                $distro='RHFC8';
-            }
+    if ( -e "/etc/mandrake-release" ) {
+        open(MANDRAKE_RELEASE,"/etc/mandrake-release");
+        $release=<MANDRAKE_RELEASE>;
+
+        if ( ($release =~ /^Mandrake Linux release (\d+\.\d+\w*)/) or ($release =~ /^Linux Mandrake release (\d+\.\d+\w*)/) ) {
+	    $distro="MN$1";
+	}
+	elsif ( $release =~ /^Mandrakelinux release (\d+\.\d+)\b/ ) {
+            $distro="MN$1";
+        }
+        else {
+            print STDERR "$err Could not infer Mandrake/Mandriva version! Setting to 10.1!\n";
+	    $distro="MN10.1";
+	}
+
+        close(MANDRAKE_RELEASE);
+    }
+    elsif ( -e "/etc/immunix-release" ) {
+        open(IMMUNIX_RELEASE,"/etc/immunix-release");
+        $release=<IMMUNIX_RELEASE>;
+        unless ($release =~ /^Immunix Linux release (\d+\.\d+\w*)/) {
+            print STDERR "$err Could not infer Immunix version! Setting to 6.2!\n";
+	    $distro="RH6.2";
+        }
+	else {
+	    $distro="RH$1";
 	}
-	elsif ( -e "/etc/redhat-release" ) {
-	    open(*REDHAT_RELEASE,"/etc/redhat-release");
-	    $release=<REDHAT_RELEASE>;
-	    if ($release =~ /^Red Hat Linux release (\d+\.?\d*\w*)/) {
-		$distro="RH$1";
-	    }
-            elsif ($release =~ /^Red Hat Linux .+ release (\d+)\.?\d*([AEW]S)/) {
-                $distro="RHEL$1$2";
-            }
-	    elsif ($release =~ /^Red Hat Enterprise Linux ([AEW]S) release (\d+)/) {
-		$distro="RHEL$2$1";
+	close(*IMMUNIX_RELEASE);
+    }
+    elsif ( -e '/etc/fedora-release' ) {
+        open(FEDORA_RELEASE,'/etc/fedora-release');
+        $release=<FEDORA_RELEASE>;
+        close FEDORA_RELEASE;
+        if ($release =~ /^Fedora Core release (\d+\.?\d*)/) {
+            $distro = "RHFC$1";
+        }
+	elsif ($release =~ /^Fedora release (\d+\.?\d*)/) {
+            $distro = "RHFC$1";
+        }
+        else {
+            print STDERR "$err Could not infer Fedora version! Setting to Fedora Core 8\n";
+            $distro='RHFC8';
+        }
+    }
+    elsif ( -e "/etc/redhat-release" ) {
+        open(*REDHAT_RELEASE,"/etc/redhat-release");
+        $release=<REDHAT_RELEASE>;
+        if ($release =~ /^Red Hat Linux release (\d+\.?\d*\w*)/) {
+	    $distro="RH$1";
+	}
+        elsif ($release =~ /^Red Hat Linux .+ release (\d+)\.?\d*([AEW]S)/) {
+            $distro="RHEL$1$2";
+        }
+	elsif ($release =~ /^Red Hat Enterprise Linux ([AEW]S) release (\d+)/) {
+	    $distro="RHEL$2$1";
+	}
+	elsif ($release =~ /^CentOS release (\d+\.\d+)/) {
+	    my $version = $1;
+	    if ($version =~ /^4\./) {
+	        $distro='RHEL4AS';
 	    }
-	    elsif ($release =~ /^CentOS release (\d+\.\d+)/) {
-		my $version = $1;
-		if ($version =~ /^4\./) {
-		    $distro='RHEL4AS';
-		}
-		elsif ($version =~ /^3\./) {
-		    $distro='RHEL3AS';
-		}
-		else {
-		    print STDERR "$err Could not determine CentOS version! Setting to Red Hat Enterprise 4 AS.\n";
-		    $distro='RHEL4AS';
-                 }
-	    }
- 	    else {
-		# JJB/HP - Should this be B_log?
-		print STDERR "$err Couldn't determine Red Hat version! Setting to 9!\n";
-		$distro="RH9";
-	    }
-	    close(REDHAT_RELEASE);
-
-	}
-	elsif ( -e "/etc/debian_version" ) {
-	    $stable="3.1"; #Change this when Debian stable changes
-	    open(*DEBIAN_RELEASE,"/etc/debian_version");
-	    $release=<DEBIAN_RELEASE>;
-	    unless ($release =~ /^(\d+\.\d+\w*)/) {
-		print STDERR "$err System is not running a stable Debian GNU/Linux version. Setting to $stable.\n";
-		$distro="DB$stable";
+	    elsif ($version =~ /^3\./) {
+	        $distro='RHEL3AS';
 	    }
 	    else {
-		$distro="DB$1";
-	    }
-	    close(DEBIAN_RELEASE);
-	}
-	elsif ( -e "/etc/SuSE-release" ) {
-	    open(*SUSE_RELEASE,"/etc/SuSE-release");
-	    $release=<SUSE_RELEASE>;
-	    if ($release =~ /^SuSE Linux (\d+\.\d+\w*)/i) {
-		$distro="SE$1";
-	    }
-	    elsif ($release =~ /^SUSE LINUX Enterprise Server (\d+\.?\d?\w*)/i) {
-		$distro="SESLES$1";
-	    }
-	    elsif ($release =~ /^SUSE Linux Enterprise Server (\d+\.?\d?\w*)/i) {
-		$distro="SESLES$1";
-	    }
-            elsif ($release =~ /^openSuSE (\d+\.\d+\w*)/i) {
-                $distro="SE$1";
+	        print STDERR "$err Could not infer CentOS version! Setting to Red Hat Enterprise 4 AS.\n";
+	        $distro='RHEL4AS';
             }
-	    else {
-		print STDERR "$err Couldn't determine SuSE version! Setting to 10.3!\n";
-		$distro="SE10.3";
-	    }
-	    close(SUSE_RELEASE);
-	}
-	elsif ( -e "/etc/turbolinux-release") {
-	    open(*TURBOLINUX_RELEASE,"/etc/turbolinux-release");
-	    $release=<TURBOLINUX_RELEASE>;
-	    unless ($release =~ /^Turbolinux Workstation (\d+\.\d+\w*)/) {
-		print STDERR "$err Couldn't determine TurboLinux version! Setting to 7.0!\n";
-		$distro="TB7.0";
-	    }
-	    else {
-		$distro="TB$1";
-	    }
-	    close(TURBOLINUX_RELEASE);
+        }
+ 	else {
+	    # JJB/HP - Should this be B_log?
+	    print STDERR "$err Could not infer Red Hat version! Setting to 9!\n";
+	    $distro="RH9";
+	}
+	close(REDHAT_RELEASE);
+
+    }
+    elsif ( -e "/etc/debian_version" ) {
+        $stable="3.1"; #Change this when Debian stable changes
+        open(*DEBIAN_RELEASE,"/etc/debian_version");
+        $release=<DEBIAN_RELEASE>;
+        unless ($release =~ /^(\d+\.\d+\w*)/) {
+  	    print STDERR "$err System is not running a stable Debian GNU/Linux version. Setting to $stable.\n";
+	    $distro="DB$stable";
+        }
+        else {
+	    $distro="DB$1";
+	}
+	close(DEBIAN_RELEASE);
+    }
+    elsif ( -e "/etc/SuSE-release" ) {
+        open(*SUSE_RELEASE,"/etc/SuSE-release");
+        $release=<SUSE_RELEASE>;
+        if ($release =~ /^SuSE Linux (\d+\.\d+\w*)/i) {
+	    $distro="SE$1";
+        }
+        elsif ($release =~ /^SUSE LINUX Enterprise Server (\d+\.?\d?\w*)/i) {
+	    $distro="SESLES$1";
+        }
+	elsif ($release =~ /^SUSE Linux Enterprise Server (\d+\.?\d?\w*)/i) {
+	    $distro="SESLES$1";
+	}
+        elsif ($release =~ /^openSuSE (\d+\.\d+\w*)/i) {
+            $distro="SE$1";
+        }
+	else {
+	    print STDERR "$err Could not infer SuSE version! Setting to 10.3!\n";
+	    $distro="SE10.3";
 	}
+	close(SUSE_RELEASE);
+    }
+    elsif ( -e "/etc/turbolinux-release") {
+        open(*TURBOLINUX_RELEASE,"/etc/turbolinux-release");
+        $release=<TURBOLINUX_RELEASE>;
+        unless ($release =~ /^Turbolinux Workstation (\d+\.\d+\w*)/) {
+	    print STDERR "$err Could not infer TurboLinux version! Setting to 7.0!\n";
+	    $distro="TB7.0";
+        }
 	else {
-	    # We're either on Mac OS X, HP-UX or an unsupported O/S.
-            if ( -x '/usr/bin/uname') {
+	    $distro="TB$1";
+	}
+	close(TURBOLINUX_RELEASE);
+    }
+    else {
+        # We're either on Mac OS X, HP-UX or an unsupported O/S.
+        if ( -x '/usr/bin/uname') {
 		# uname is in /usr/bin on Mac OS X and HP-UX
-		$release=`/usr/bin/uname -sr`;
-	    }
-	    else {
-                print STDERR "$err Could not determine operating system version!\n";
-		$distro="unknown"
-            }
-
-	    # Figure out what kind of system we're on.
-	    if ($release ne "") {
-		if ($release =~ /^Darwin\s+(\d+)\.(\d+)/) {
-		    if ($1 == 6 ) {
-			$distro = "OSX10.2";
-		    }
-		    elsif ($1 == 7) {
-			$distro = "OSX10.3";
-		    }
-                    elsif ($1 == 8) {
-                        $distro = "OSX10.3";
-                    }
-		    else {
-		        $distro = "unknown";
-		    }
+	    $release=`/usr/bin/uname -sr`;
+	}
+	else {
+            print STDERR "$err Could not infer operating system version from filesystem context. Setting inferred distro to 'unknown'.\n";
+	    $distro="unknown";
+        }
+
+	# Figure out what kind of system we're on.
+	if ($release ne "") {
+	    if ($release =~ /^Darwin\s+(\d+)\.(\d+)/) {
+	        if ($1 == 6 ) {
+		    $distro = "OSX10.2";
 		}
-	        elsif ( $release =~ /(^HP-UX)\s*B\.(\d+\.\d+)/ ) {
-		   $distro="$1$2";
+		elsif ($1 == 7) {
+		    $distro = "OSX10.3";
 		}
+                elsif ($1 == 8) {
+                    $distro = "OSX10.3";
+                }
 		else {
-		   print STDERR "$err Could not determine operating system version!\n";
-	           $distro="unknown";
+                    print STDERR "$err Could not infer operating system version from filesystem context. Setting inferred distro to 'unknown'.\n";
+		    $distro = "unknown";
 		}
 	    }
+	    elsif ( $release =~ /(^HP-UX)\s*B\.(\d+\.\d+)/ ) {
+	        $distro="$1$2";
+	    }
+	    else {
+                print STDERR "$err Could not infer operating system version from filesystem context. Setting inferred distro to 'unknown'.\n";
+	        $distro="unknown";
+	    }
 	}
-
-	$GLOBAL_OS=$distro;
-    } elsif (not (defined $GLOBAL_OS)) {
-        print "ERROR: GLOBAL OS Scoping Issue\n";
-    } else {
-        $distro = $GLOBAL_OS;
     }
-
     return $distro;
 }
 
 ###################################################################################
-#   &getActualDistro;                                                             #
+#   &getInferredDistro;                                                             #
 #                                                                                 #
 #    This subroutine returns the actual os version in which is running on.  This  #
 #    os version is independent of the --os switch feed to bastille.               #
 #                                                                                 #
 ###################################################################################
-sub getActualDistro {
-    # set local variable to $GLOBAL_OS
+sub getInferredDistro {
+    if ($GLOBAL_INFERRED_OS eq "None") {
+        $GLOBAL_INFERRED_OS = &InferDistro;
+    }
+    return $GLOBAL_INFERRED_OS;
+}
 
-    if ($GLOBAL_ACTUAL_OS eq "None") {
-        my $os = $GLOBAL_OS;
-        # undef GLOBAL_OS so that the GetDistro routine will return
-        # the actualDistro, it might otherwise return the distro set
-        # by the --os switch.
-        $GLOBAL_OS = "None";
-        $GLOBAL_ACTUAL_OS = &GetDistro;
-        # reset the GLOBAL_OS variable
-        $GLOBAL_OS = $os;
+sub GetDistro {
+    if ($GLOBAL_OS eq "None") {
+        return &getInferredDistro;
     }
-    return $GLOBAL_ACTUAL_OS;
+    return $GLOBAL_OS;
 }
+
 # These are helper routines which used to be included inside GetDistro
 sub is_OS_supported($) {
    my $os=$_[0];
@@ -556,7 +545,8 @@
 			      "SE7.2","SE7.3", "SE8.0","SE8.1","SE9.0","SE9.1",
 			      "SE9.2","SE9.3","SE10.0","SE10.1","SE10.2","SE10.3",
 			      "SESLES8","SESLES9","SESLES10",
-			      "TB7.0"
+			      "TB7.0",
+                              "Yocto"
 			      ],
 
 		  "HP-UX" => [
@@ -882,23 +872,19 @@
 ###########################################################################
 sub ConfigureForDistro {
 
-    my $retval=1;
-
-    # checking to see if the os version given is in fact supported
     my $distro = &GetDistro;
 
-    # checking to see if the actual os version is in fact supported
-    my $actualDistro = &getActualDistro;
+    my $inferredDistro = &getInferredDistro;
+
+    if (! ($inferredDistro eq $distro) ) {
+        print STDERR "WARNING: Inferred distro $inferredDistro is not the same as specified distro $distro. Using specified distro.\n";
+    }
+
     $ENV{'LOCALE'}=''; # So that test cases checking for english results work ok.
-    if ((! &is_OS_supported($distro)) or (! &is_OS_supported($actualDistro))  ) {
-	# if either is not supported then print out a list of supported versions
-	if (! &is_OS_supported($distro)) {
-	    print STDERR "$err '$distro' is not a supported operating system.\n";
-	}
-	else {
-	    print STDERR "$err Bastille is unable to operate correctly on this\n";
-	    print STDERR "$spc $distro operating system.\n";
-	}
+
+    if (! &is_OS_supported($distro)) {
+	print STDERR "$err '$distro' is not a supported operating system.\n";
+
 	my %supportedOSHash = &getSupportedOSHash;
 	print STDERR "$spc Valid operating system versions are as follows:\n";
 
@@ -930,7 +916,7 @@
     # intend via setting the Perl umask
     umask(077);
 
-    &getFileAndServiceInfo($distro,$actualDistro);
+    &getFileAndServiceInfo($distro,$distro);
 
 #    &dumpFileInfo;  # great for debuging file location issues
 #    &dumpServiceInfo; # great for debuging service information issues
@@ -942,7 +928,7 @@
 	    "$spc You must use Bastille\'s -n flag (for example:\n" .
 	    "$spc bastille -f -n) or \'touch $nodisclaim_file \'\n";
 
-    return $retval;
+    return 1;
 }
 
 
Index: Bastille/Bastille/LogAPI.pm
===================================================================
--- Bastille.orig/Bastille/LogAPI.pm	2013-08-22 04:32:38.269968002 -0400
+++ Bastille/Bastille/LogAPI.pm	2013-08-22 04:32:47.509968002 -0400
@@ -111,7 +111,7 @@
    # do this here to prevent bootstrapping problem, where we need to
    # write an error that the errorlog location isn't defined.
    my $logdir="/var/log/Bastille";
-   if(&getActualDistro =~ "^HP-UX"){
+   if(&getInferredDistro =~ "^HP-UX"){
        $logdir = "/var/opt/sec_mgmt/bastille/log/";
    }