Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

Copyright 2015 by Assured Information Security, Inc. Created by Jennifer Temkin <temkinj@ainfosec.com>. This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/.

Table of Contents

Overview

The power management policy consists of a set of rules, and variables that can be used as arguments in these rules. Policy can currently be loaded from a text file, the DB, or added a rule or variable at a time over DBus. All policy, regardless of origin, is ultimately made persistent by storing it in the DB. 

...

To trigger loading policy from a text file, use the DBus call load_policy_from_file.

Code Block
firstline1
titleSample Policy File

...

linenumberstrue
#begin variables section
ubuntu_uuid(“12345678-1234-1234-1234-123456789012”)
battery_low(20)
battery_critical(7)
=
#begin 

...

rules section
screen_

...

off     | whileLidClosed()

...

 |

...

 runScript(“/home/user/blank_screen.sh”)

...

 |

...

 runScript(“/home/user/unblank_screen.sh”)
low_batt_alert |

...

 whileBattLessThan(0,

...

 $battery_low)

...

 |

...

 logString(“Battery low!”)
pause_

...

ubuntu   | whileBattLessThan(0,

...

 $battery_critical)

...

 |

...

 pauseVmUuid($ubuntu_uuid)

...

 |

...

 resumeVmUuid($ubuntu_uuid)

DBus Interface

XCPMD’s DBus interface allows the user to control and query different aspects of policy. This is the interface that any UI tools would use to modify policy in XCPMD. The following calls are currently available:

...

The dbus-send application provides a convenient way to issue calls on DBus:

...

Code Block
languagebash
# Get a list of available condition types and their prototypes:
dbus-send --system --print-

...

reply --dest=com.citrix.xenclient.

...

xcpmd /

...

 com.citrix.xenclient.xcpmd.get_conditions

...


 
# Add a rule that prints a message when a laptop is unplugged:
dbus-send --system --print-

...

reply --dest=com.citrix.xenclient.

...

xcpmd /

...

 com.citrix.xenclient.xcpmd.add_

...

rule \
    string:’unplug_

...

alert’ \
    string:’whileUsingBatt()

...

’ \
    string:’logString(

...

“Disconnected from AC power!”)

...

’ \
    string:’’
 

...


# Add a variable named battery_critical whose value is 7
dbus-send --system --print-

...

reply --dest=com.citrix.xenclient.

...

xcpmd /

...

 com.citrix.xenclient.xcpmd.add_

...

var \
    string:’battery_

...

critical’ \
    string:’7’
 

...


# Add a variable named critical_message whose value is “battery critical!”
dbus-send --system --print-

...

reply --dest=com.citrix.xenclient.

...

xcpmd /

...

 com.citrix.xenclient.xcpmd.add_

...

var \
    string:’critical_

...

message’ \
    string:

...

’”battery critical!”’
 
# Print out all variables currently loaded--the two we added should be there
dbus-send --system --print-

...

reply --dest=com.citrix.xenclient.

...

xcpmd /

...

 com.citrix.xenclient.xcpmd.get_vars

...


 
# Add a rule using the two variables we added
dbus-send --system --print-

...

reply --dest=com.citrix.xenclient.

...

xcpmd /

...

 com.citrix.xenclient.xcpmd.add_

...

rule \
    string:’warn_

...

critical’ \
    string:’whileBattLessThan(0,

...

 $battery_critical)

...

’ \
    string:’logString($critical_message)

...

’ \
    string:’’

...


 
# Delete the rules we added
dbus-send --system --print-

...

reply --dest=com.citrix.xenclient.

...

xcpmd /

...

 com.citrix.xenclient.xcpmd.remove_

...

rule \
    string:’warn_critical’

...


dbus-

...

send --

...

system --print-

...

reply --dest=com.citrix.xenclient.

...

xcpmd /

...

 com.citrix.xenclient.xcpmd.remove_

...

rule \
    string:’unplug_alert’ 

...


 
# Delete the variables we added 
dbus-

...

send --

...

system --print-

...

reply --dest=com.citrix.xenclient.

...

xcpmd /

...

 com.citrix.xenclient.xcpmd.remove_

...

var \
    string:’battery_critical’
dbus-

...

send --

...

system --print-

...

reply --dest=com.citrix.xenclient.

...

xcpmd /

...

 com.citrix.xenclient.xcpmd.remove_

...

var \
    string:’critical_message’

More information on dbus-send is available at http://dbus.freedesktop.org/doc/dbus-send.1.html.

...

Policy is stored in the following structure:

Code Block
/power-management

...


  vars

...


    var_name1:

...

 “value1”
    var_name2:

...

 “value2”
  rules

...


    rule1

...


      conditions

...


        0

...


          type:

...

 “whileBattLessThan"

...


          is_inverted:

...

 “false”
          args

...


            0:

...

 “0”
            1:

...

 “70”
        1

...


          type:

...

 “whileUsingBatt”
          is_inverted:

...

 “true”
          args:

...

 “”
      actions

...


        0

...


          type:

...

 “logString”
          args

...


            0:

...

 “\“On AC power and battery is less than 70%\””
      undos

...


        0

...


          type:

...

 “logString”
          args

...


            0:

...

 “\“Either on battery power, or battery is greater than or equal to 70%, or both\””

All DB entries are stored and retrieved as key-value pairs, with both key and value being strings. XCPMD parses the strings retrieved from the DB in the same way as other interfaces, so the same rules apply with respect to argument and variable type inference. In particular, ensure that string-type arguments and variables are wrapped in double quotes--using backslash (\) as an escape character may be necessary, depending on your shell.

...