~apparmor-dev/apparmor/2_3

« back to all changes in this revision

Viewing changes to management/yastui/src/agents/ag_subdomain_profiles

  • Committer: jrjohansen
  • Date: 2008-05-19 22:46:34 UTC
  • Revision ID: svn-v4:40609528-9d10-0410-9bd8-e926d5471da9:trunk:1247
move yastui to deprecated as the YaST ui is now being maintained and developed in the YaST svn

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/perl
2
 
 
3
 
# ------------------------------------------------------------------
4
 
#
5
 
#    Copyright (C) 2002-2005 Novell/SUSE
6
 
#
7
 
#    This program is free software; you can redistribute it and/or
8
 
#    modify it under the terms of version 2 of the GNU General Public 
9
 
#    License published by the Free Software Foundation.
10
 
#
11
 
# ------------------------------------------------------------------
12
 
 
13
 
 
14
 
#####################################################################
15
 
#
16
 
# ag_subdomain_profiles - Immunix SCR agent for the 
17
 
#                         management of SubDomain profiles
18
 
#
19
 
#        
20
 
#####################################################################
21
 
 
22
 
use strict;
23
 
use ycp;
24
 
 
25
 
use Immunix::SubDomain;
26
 
 
27
 
################
28
 
# Subroutines
29
 
################
30
 
 
31
 
{
32
 
 
33
 
sub newprofile {
34
 
  my $filename = shift;
35
 
  system("/usr/sbin/autodep $filename > /dev/null 2>&1");
36
 
  system("/usr/sbin/enforce $filename > /dev/null 2>&1");
37
 
  return; 
38
 
}
39
 
 
40
 
# ############################################################################### 
41
 
#
42
 
#    YCP <-> SCR Commands:
43
 
#
44
 
#   Command        Path           Argument           Returns
45
 
#   -------        ----           --------           --------
46
 
#
47
 
#   Read                          all                hash containing all profiles
48
 
#
49
 
#   Read           .new           pathtoprogram      true/false (creates new profile)
50
 
#
51
 
#   Write                         hash {             true/false
52
 
#                                  PROFILE_NAME => 
53
 
#                                  pathtoprogram,
54
 
#                                  PROFILE_HASH => 
55
 
#                                  <hash containing the 
56
 
#                                   profile defs>
57
 
#                                 } 
58
 
#
59
 
#   Write          .delete        pathtoprogram      true/fale  (deletes profile)
60
 
#
61
 
#   Write          .reload        -                  true       (reloads profiles)
62
 
#                                                        
63
 
#
64
 
################################################################################
65
 
 
66
 
 
67
 
while ( <STDIN> ) {
68
 
 
69
 
    my ($command, $path, $argument) = ycp::ParseCommand ($_);
70
 
    $argument = "NONE" if ( ! $argument ); 
71
 
    ycp::y2milestone ("DOM command: $command, path: $path, argument: $argument");
72
 
 
73
 
        my $result = undef;
74
 
        if ( $command && $path && $argument ) {
75
 
                if ( $command eq "Read" and $argument eq "all") {
76
 
                   $UI_Mode = "yast";
77
 
                   Immunix::SubDomain::readprofiles();
78
 
                   ycp::Return( \%sd );
79
 
                } elsif ( $command eq "Read" and $path eq ".new" ) {
80
 
                   my $pfname = getprofilefilename($argument);
81
 
                   if  ( -e $pfname ) {
82
 
                     ycp::Return("false");
83
 
                   } else {   
84
 
                     newprofile( $argument );
85
 
                     ycp::Return( "true" );
86
 
                   }    
87
 
                } elsif ( $command eq "Read" ) {
88
 
                   my $pfname = getprofilefilename($argument);
89
 
                   if ( -e $pfname ) {
90
 
                     $UI_Mode = "yast";
91
 
                     Immunix::SubDomain::readprofiles();
92
 
                     ycp::Return( $sd{$argument} );
93
 
                   } else { 
94
 
                     ycp::Return( "false" );
95
 
                   }
96
 
                } elsif ( $command eq "Read") {
97
 
                    $UI_Mode = "yast";
98
 
                    Immunix::SubDomain::readprofile("$profiledir/$argument",
99
 
                    \&$Immunix::SubDomain::fatal_error, 1);
100
 
                    ycp::Return( \%sd );
101
 
                } elsif ( $command eq "Write" and $path eq ".delete") {
102
 
                  if ( $argument ne "" ) {
103
 
                    my $profilefile = getprofilefilename( $argument );
104
 
                    if ( -e $profilefile ) {
105
 
                      unlink( $profilefile );
106
 
                    }   
107
 
                    ycp::Return( "true" );
108
 
                  } else {
109
 
                    ycp::Return( "false" );
110
 
                  }
111
 
                } elsif ( $command eq "Write" and $path eq ".reload") {
112
 
                     $result = system("/sbin/rcsubdomain reload > /dev/null 2>&1");
113
 
                     ycp::Return( "true" );
114
 
                } elsif ( $command eq "Write") {
115
 
                    if ( (ref($argument) eq "HASH") ) {
116
 
                     my $profilename = "";
117
 
                     $profilename = $$argument{"PROFILE_NAME"};
118
 
                     my $ref = $$argument{"PROFILE_HASH"};
119
 
                     my %profiles = ();
120
 
                     $profiles{$profilename} = $ref;
121
 
                     if ( (ref($ref) eq "HASH") ) {
122
 
                      %sd = %profiles;
123
 
                      $UI_Mode = "yast";
124
 
                      $result = Immunix::SubDomain::writeprofile($profilename);
125
 
                     } else {
126
 
                     ycp::Return( "false" );
127
 
                     }  
128
 
                     ycp::Return( "true" );
129
 
                    }
130
 
                } 
131
 
        } else {
132
 
 
133
 
                my $ycpCmd = ycpGetCommand() || "";
134
 
                my $ycpArg = ycpGetArgType() || "";
135
 
                $result = "Unknown instruction $ycpCmd or argument: $ycpArg\n";
136
 
                ycp::Return( $result );
137
 
        }
138
 
}
139
 
}
140
 
exit 0;
141
 
 
142