Description
Use the readonly statement to make a variable read-only. This means that its current value is frozen, so that no configuration file statement can change it. The purpose of this statement is to allow a system administrator to freeze the value of certain variables before calling out to another configuration file using the include statement. By safely freezing certain variable values, control over the other configuration file can safely be given to other, less-trusted personnel, knowing that they will not be able to abuse their privilege and gain unauthorized access to parts of the system that they should not be tampering with.
Examples
runuser = "jamie";
readonly {"runuser","runhost","runcommand"};
runuser = robyn;
print(runuser);
This policy will cause an execution error. Running pmcheck displays a message similar to this:
**Policy execution error in /etc/opt/quest/qpm4u/policy/pm.conf, line 3 Cannot assign value to readonly identifier runuser
Syntax
readonlyexcept list
Description
The readonlyexcept statement is related to the readonly statement. The readonlyexcept statement makes all variables read-only, except those listed in the statement. The readonlyexcept statement has the same syntax as the readonly statement.
Examples
runhost = "myhost";
runuser = "jamie";
readonlyexcept {"runuser"};
runhost = "newhost"; // fails, runhost still equals "myhost"
runuser = "corey"; // runuser now equals "corey"
This policy will cause an execution error. Running pmcheck displays a message similar to this:
**Policy execution error in /etc/opt/quest/qpm4u/policy/pm.conf, line 3 Cannot assign value to readonly identifier runuser
Syntax
return [expression];
Description
return exits the current procedure/function and returns the value of expression.
Examples
function square (n){
n2 = n * n;
return n2;
}
print(square(10)); // prints "100"
Syntax
switch (string)
{
case expression1:
statement1a; [statement1b; …] [break;]
case expression2:
statement2a; [statement2b; …] [break;]
default: statement3a; [statement3b; …] [break;]
}
Description
The switch statement tests whether an expression matches one of several values (each of which is specified in a case statement) and branches accordingly. If a case matches the value, execution will begin at that case falling through to subsequent cases until a break statement occurs. The break statement forces an immediate exit from the switch statement; it is optional.
The default statement runs if none of the cases match the value. This statement is optional. If there is no default and none of the cases match the value, nothing happens. Case statements can be in any order, but the default statement, if present, must occur after all of the case statements.
Examples
switch (user) {
case "leslie":
runuser="sys";
break;
case "adrian":
accept;
case "cory":
case "jamie":
runuser = "root";
accept;
default:
reject;
}
switch (gidnum){
case 0: runuser="root"; break;
default: break;
}
See Example 9: Switch and case statements for additional usage examples.