summaryrefslogtreecommitdiffstats
path: root/perl-install/security/msec.pm
blob: da134217d361738a1cbf1c603384097ab1a15c90 (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
package security::msec;

use common;
use log;

sub get_user_list {
   my @user_list = ();

   open(PASSWD, "/etc/passwd");
   while(<PASSWD>) {
      my ($login_name, undef, $uid) = split(/:/,$_);
      if($uid >= 500) { push(@user_list, $login_name); }
   }
   @user_list;
}

sub add_config {
   my ($prefix, $config_option, @values) = @_;
   my $tmp_file = "$prefix/etc/security/msec/level.local.tmp";
   my $result = "";

   $result = $config_option.'(';
   foreach $value (@values) {
      $result .= $value.',';
   }
   chop $result;
   $result .= ')';

   print "result is $result";
   open(TMP_CONFIG, '>>'.$tmp_file);
   print TMP_CONFIG "$result\n";
   close TMP_CONFIG;
}

sub commit_changes {
   my ($prefix) = $_;
   my $tmp_file = "$prefix/etc/security/msec/level.local.tmp";
   my $config_file = "$prefix/etc/security/msec/level.local";
   my %config_data;
   my $config_option = "";

   open (TMP_CONFIG, $tmp_file);

   if (!(-x $config_file)) {
      open(CONFIG_FILE, '>'.$config_file);
      print CONFIG_FILE "from mseclib import *\n\n";
      while(<TMP_CONFIG>) { print CONFIG_FILE $_; }
   }
   else {
      open(CONFIG_FILE, $config_file);
      while(<CONFIG_FILE>) {
         if($_ =~ /\(/) {
            ($config_option, undef) = split(/\(/, $_);
            (undef, $config_data{$config_option}) = split(/\(/, $_);
	 }
      }
      close CONFIG_FILE;
      
      while(<TMP_CONFIG>) {
	 ($config_option, undef) = split(/\(/, $_);
	 (undef, $config_data{$config_option}) = split(/\(/, $_);
      }

      open(CONFIG_FILE, '>'.$config_file);
      print CONFIG_FILE "from mseclib import *\n\n";
      foreach $config_option (keys %config_data) {
         print CONFIG_FILE $config_option.'('.$config_data{$config_option}.'\n';
      }   
   }

   close CONFIG_FILE;
   close TMP_CONFIG;

   standalone::rm_rf($tmp_file);
} 
1;