Kaydet (Commit) 383f176b authored tarafından Bahadır Kandemir's avatar Bahadır Kandemir

3.0 branch

üst b46171dd
# Project name
PROJECT (comar)
# CMake 2.6 required
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
# Application name
SET (APP_NAME "comar")
SET (APP_SUFFIX "3")
# Uncomment this for production releases.
SET (VERSION_SUFFIX "")
SET (FLAGS "-g -O0 -Werror -Wcast-align -Wno-uninitialized -Wall -fstrict-aliasing")
# Uncomment this for gprof profiling
# SET (FLAGS "-g -O0 -Werror -Wcast-align -Wno-uninitialized -Wall -fstrict-aliasing -fprofile-arcs -ftest-coverage")
SET (CMAKE_C_FLAGS "${FLAGS}")
# Uncomment this for sparse building
# SET (CMAKE_C_COMPILER cgcc)
# Append name suffix, if specified
IF (APP_SUFFIX)
SET (APP_NAME "${APP_NAME}${APP_SUFFIX}")
ENDIF (APP_SUFFIX)
# Define version, config dir, data dir and log file.
ADD_DEFINITIONS (
-D'PID_FILE="/var/run/${APP_NAME}.pid"'
-D'DATA_DIR="/var/lib/${APP_NAME}"'
-D'LOG_DIR="/var/log/${APP_NAME}"')
# Set standard sources
SET (SOURCES src/main.c
src/bus.c
src/config.c
src/db.c
src/iksemel.c
src/log.c
src/loop.c
src/process.c
src/policy.c
src/pydbus.c
src/script.c
src/utils.c)
# Set standard libraries
SET (LIBS python2.6
dbus-1
polkit-dbus)
# Include standard headers
INCLUDE_DIRECTORIES (include/
/usr/include/python2.6
/usr/include/dbus-1.0
/usr/lib/dbus-1.0/include
/usr/include/PolicyKit)
# Compile comar from specified sources
ADD_EXECUTABLE (comar ${SOURCES})
# Link comar to specified libraries
TARGET_LINK_LIBRARIES(comar ${LIBS} )
# Install comar to /usr/sbin/<app-name>
INSTALL (PROGRAMS comar
DESTINATION /usr/sbin)
# Install Models
INSTALL (DIRECTORY
models
DESTINATION /var/db/${APP_NAME}
PATTERN ".svn" EXCLUDE)
# Install Modules
INSTALL (DIRECTORY
modules
DESTINATION /var/db/${APP_NAME}
PATTERN ".svn" EXCLUDE)
# Install service activation config under /usr/share/dbus-1/system-services/
INSTALL (FILES
config/tr.org.pardus.comar.service
config/tr.org.pardus.comar2.service
DESTINATION /usr/share/dbus-1/system-services/)
# Install policies
# Install PK policies
INSTALL (DIRECTORY
policy
DESTINATION /usr/share/PolicyKit
PATTERN ".svn" EXCLUDE)
# Install system bus policy under /etc/dbus-1/system.d/
INSTALL (FILES
config/tr.org.pardus.comar.conf
DESTINATION /etc/dbus-1/system.d)
# Install hav to /usr/bin/hav
INSTALL (PROGRAMS tools/hav.py
DESTINATION /usr/bin
RENAME hav)
# Install hav to /usr/bin/comar2to3
INSTALL (PROGRAMS tools/comar2to3.py
DESTINATION /usr/bin
RENAME comar2to3)
Requirements
============
Python 2.5
DBus
PolicyKit
Installination
==============
Build:
$ cmake .
$ make
Install:
# make install DESTDIR=/
Import Comar 2.0 scripts (optional):
# comar2to3
- CSL methods
- log_*()
- model_apps()
- Move core methods into script.c
- Execute onRegister/onRemove methods after registering/removing script
/ Logging to file
? Logging errors and traceback to seperate file
- Policy files
- Models use COMAR 2.0 policy action IDs, fix them
+ Script for importing COMAR 2.0 scripts
/ Get signature from introspection.xml
+ Variant type support
- Numeric type tests
- Raise an exception on conversion error
- Make hav.py use COMAR API
? Switch to PolicyKit 0.90
----------------------------------------------------------------------
Legend:
? Not sure
/ Incomplete
- Missing
+ Done
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<policy user="root">
<allow own="tr.org.pardus.comar"/>
<allow own="tr.org.pardus.comar2"/>
<allow own="tr.org.pardus.comar.updated"/>
</policy>
<policy context="default">
<allow send_destination="tr.org.pardus.comar"/>
<allow send_destination="tr.org.pardus.comar2"/>
<allow send_destination="tr.org.pardus.comar.updated"/>
</policy>
</busconfig>
[D-BUS Service]
Name=tr.org.pardus.comar
Exec=/usr/sbin/comar
User=root
[D-BUS Service]
Name=tr.org.pardus.comar2
Exec=/usr/sbin/comar -i -b tr.org.pardus.comar2
User=root
Service Scripts
===============
Service scripts are Python scripts used by COMAR to manage system services and comes with PiSi packages. Any System.Service call made to Comar (start, stop, info, ...) will be handled by service scripts.
Service script, is a Python file like below. There are three methods. Two for starting and stopping service, one for giving status of service. Implementation of these three scripts is up to package maintainer. However, COMAR API package provides Service API, which contains useful methods for writing service scripts.
serviceType = "server"
serviceDesc = _({"en": "Server",
"tr": "Sunucu"})
from comar.service import *
@synchronized
def start():
startService(command="/usr/bin/myserver",
args="start",
pidfile="/var/run/sunucu.pid",
donotify=True)
@synchronized
def stop():
stopService(command="/usr/bin/myserver",
args="stop",
donotify=True)
def status():
return isServiceRunning("/var/run/myserver.pid")
serviceType
-----------
Possible values:
local: Local services
server: Servers
script: Scripts
This value is used to group services only.
serviceDesc
-----------
serviceDesc = _({"en": "My Server",
"tr": "Sunucum"})
This value is used by System.Service GUIs. _() is used for localization.
@synchronized Decorator
-----------------------
In boot sequence, service scripts can start other services. To prevent any race condition, @synchronized decorator should be used.
Service API
-----------
startService():
Arguments:
command : Application to execute [str]
args : Arguments (optional) [str]
pidfile : PID file for application. (optional) [str]
(Application won't be started if it's already running.)
makepid : If application doesn't create any PID file, API creates one. Generally used with ''detach'' argument (optional) [True/False]
nice : Niceness of process (optional) [int]
chuid : Owner of the process. Format: user:group (optional) [str:str]
detach : Fork process (optional) [True/False]
donotify : Emit a System.Service.changed signal and notify all GUIs (optional) [True/False]
(This should be used. It's optional because some service scripts start more than one process.)
stopService():
Arguments:
pidfile : PID file of the running process (optional) [str]
command : Application to stop (optional) [str]
(Scans /proc and kills all running applications having that /path/to/name)
args : Arguments (To stop application by calling it with an argument) (optional) [str]
(/proc won't be scanned, <command args> will be executed)
chuid : Owner of the process. Format: user:group (optional) [str:str]
user : Username associated with process. (optional) [str]
signalno : Signal to be sent to running process (optional) [int]
donotify : Emit a System.Service.changed signal and notify all GUIs (optional) [True/False]
(This should be used. It's optional because some service scripts stop more than one process.)
Disk.Manager
============
getDevices():
Returns a list of disks.
Function should return something like that:
01 [
02 "/dev/sda",
03 "/dev/sdb",
04 ]
getDeviceParts(device):
Returns list of partitions of specified device.
Function should return something like that:
01 [
02 "/dev/sda1",
03 "/dev/sda2",
04 "/dev/sda3",
05 ]
getMounted():
Returns a list of mounted partitions.
Function should return something like that:
01 [
02 "/dev/sda1",
03 "/dev/sda3",
04 ]
getDeviceByLabel(label):
Returns device name that has specified label.
Function should return something like that:
01 "/dev/sda1"
mount(device, path):
Mounts device to the specified path.
umount(device):
Unmounts device.
listEntries():
Returns a list of entries in fstab
Function should return something like that:
01 [
02 "/dev/sda1",
03 "LABEL=PARDUS_ROOT",
04 "/dev/sda3",
05 ]
addEntry(device, path, fsType, options):
Adds an entry to fstab. First argument is device path, second argument
is mount point, third argument is filesystem type, fourth argument is
dictionary of options.
getEntry(device):
Returns mount point, filesystem type and options of an entry.
Function should return something like that:
01 (
02 "/mnt/sda1",
03 "ext3",
04 {"noatime": "", "defaults": ""},
05 (
removeEntry(device):
Removes an entry from fstab.
Signals:
changed: Fired when an entry is updated in fstab.
Net.Filter Model
================
*** DRAFT ***
Unlike other models, Net.Link is application-dependent and it's used
to manage IPTables. IPTables is a powerfull firewall for Linux and
it's nearly impossible to design a simple model that supports all
important features of it.
setRule() passes arguments to IPTables directly, so all interfaces
that uses Net.Filter model also should be IPTables dependent and
have the ability to parse/generate IPTables rules.
<method name="setRule" action_id="tr.org.pardus.comar.net.filter.set">
<arg name="rule" type="s" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="getRules" action_id="">
<arg name="rules" type="as" direction="out"/>
</method>
<method name="setProfile" action_id="tr.org.pardus.comar.net.filter.set">
<arg name="profile" type="s" direction="in"/>
<arg name="save_filter" type="s" direction="in"/>
<arg name="save_mangle" type="s" direction="in"/>
<arg name="save_nat" type="s" direction="in"/>
<arg name="save_raw" type="s" direction="in"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="getProfile" action_id="">
<arg name="profile" type="s" direction="out"/>
<arg name="save_filter" type="s" direction="out"/>
<arg name="save_mangle" type="s" direction="out"/>
<arg name="save_nat" type="s" direction="out"/>
<arg name="save_raw" type="s" direction="out"/>
</method>
<signal name="ProfileChanged">
<arg name="profile" type="s"/>
<arg name="filter" type="s"/>
<arg name="mangle" type="s"/>
<arg name="nat" type="s"/>
<arg name="raw" type="s"/>
</signal>
Net.Link is obsolete, use Network.Link instead. We keep it for backward compatibilty.
Net.Stack is obsolete, use Network.Stack instead. We keep it for backward compatibilty.
Network.Firewall Model
======================
listModules():
Lists usable firewall modules.
Function should return something like that:
O1 [
02 "internet-sharing",
03 "content-serving",
04 ]
moduleInfo(module):
Returns module title, description and icon.
Function should return something like that:
O1 (
02 i18n("Internet Sharing"),
03 i18n("Description..."),
04 "network-workgroup"
05 )
moduleParameters(module):
Returns parameters required by module.
Function should return something like that:
O1 [
02 (
03 "device-input",
03 i18n("Gateway to Internet"),
03 "combo",
03 {"option1": "...", "option2": "..."},
03 ),
05 ]
First argument is parameter keyword.
Second argument is parameter label.
Third argument is the name of widget set to be used.
Fourth argument is options for third argument.
def useModule(module, values):
Activates specified module with given parameters. Values is a
dictionary.
Network.Link Model
==================
linkInfo():
Provides information that application requires to create or manage network connection.
Sample Function Definition:
01 def linkInfo():
02 return {
03 "type": "wifi",
04 "name": "Wireless connection",
05 "modes": "device,device_mode,remote,remote_scan,net,auto,auth",
06 }
- type: Connection type that application provides
(wifi, net, dialup, ...)
- name: Description of connection type. Can be localized.
- modes: Features or methods can be used while creating connection.
device : A device should be selected to make connection.
device_mode : Device supports more than one state (e.g. wireless cards have
managed, adhoc, ... modes).
remote : A remote address/name should be defined to make a connection
(phone number for dialup, essid for wireless, ...)
remote_scan : Scanning for remote points is supported.
net : Ip can be defined by user.
auto : DHCP can be used to get IP.
auth : User can authenticate to make a connection.
def authMethods():
If "auth" is supported, this function will return a list of supported authentication methods.
Sample Function Definition:
01 def authMethods():
02 return [
03 ("wep", "WEP"),
04 ("wpa", "WPA"),
05 ("802.1x", "Dynamic WEP (802.1x)"),
06 ]
First element of tuple is method name, second is method description. Definition can be localized.
def authParameters(method):
If "auth" mode is supported, this function will return required parameters for selected authentication "method".
Sample Function Definition:
01 def authParameters(method):
02 if method == "wep":
03 return [
04 ("password", "Password", "pass"),
05 ]
06 elif method == "wpa":
07 return [
08 ("password", "Password", "pass"),
09 ]
10 elif method == "802.1x":
11 return [
12 ("username", "Username", "text"),
13 ("password", "Password", "pass"),
14 ("cert_cli", "Client Certificate", "file"),
15 ("cert_ca", "CA Certificate", "file"),
16 ("keyfile", "Private Key", "file"),
17 ]
18
19 return modes
First element of tuple is parameter name, second is description, third is type. Description can be localized.
Types:
text : Text input
pass : Password input
file : File input
setAuthMethod(profile, method):
If "auth" mode is supported, this function is used to specify authentication method for that profile.
setAuthParameters(profile, auth_key, auth_value):
If "auth" mode is supported, this function is used to specify required fields to make connecition.
getAuthMethod(profile):
If "auth" mode is supported, this function should return authentication method for that profile.
Function should return something like that:
01 "802.1x"
getAuthParameters(profile):
If "auth" mode is supported, this function should return authentication settings for that profile.
Function should return something like that:
01 {
02 "login": "bahadir",
03 "parola": "password",
04 "cert_cli": "/home/bahadir/.cert/cli.cert",
05 "cert_ca": "/home/bahadir/.cert/ca.cert",
06 "keyfile": "/home/bahadir/.cert/mykey",
07 }
deviceList():
If "device" mode is supported, this function should return a list of available devices.
Function should return something like that:
O1 {
02 "pci:1106_3065_eth1": "VT6102 [Rhine-II] - VIA Technologies, Inc. (eth1)",
03 }
def deviceModes():
If "device_mode" mode is supported, this function should return a list of available device modes.
Sample Function Definition:
01 def deviceModes():
02 return [
03 ("managed", "Managed"),
04 ("adhoc", "Ad Hoc"),
05 ]
First element of tuple is mode name, second is description. Description can be localized.
def remoteName():
If "remote" mode is supported, this function should return label for remote point.
Sample Function Definition:
01 def remoteName():
02 return "Phone Number"
Can be localized.
scanRemote(device):
If "remote_scan" is supported, this function should return a list of remote points.
Function should return something like that:
01 [
02 {
03 "remote": "HOME",
04 "encryption": "wep",
05 "mac": "00:00:00:00:00:00",
06 "channel": "11",
07 "mode": "managed",
08 "protocol": "IEEE 802.11g",
09 "quality": "54",
10 },
11 {
12 "remote": "APOINT",
13 "encryption": "wpa",
14 "mac": "11:11:11:11:11:11",
15 "channel": "11",
16 "mode": "managed",
17 "protocol": "IEEE 802.11g",
18 "quality": "12",
19 },
20 ]
NOTE: Since this method is only used by wireless-tools, dictionary keys are OK.
setRemote(profile, remote):
If "remote" mode is supported, this function is used to specify remote point for that profile.
Can be used to sed ESSID for wireless, phone number for PPP, host:port for VPN.
connections():
Returns a list of profile names.
Function should return something like that:
O1 [
02 "Home",
03 "Office",
04 ]
connectionInfo(profile):
Returns profile information.
Function should return something like that:
01 {
02 "name": "Home",
03 "device_id": "pci:1106_3065_eth1",
04 "device_name": "VT6102 [Rhine-II] - VIA Technologies, Inc. (eth1)",
05 "net_mode": "manual",
06 "net_address": "192.168.2.10",
07 "net_mask": "255.255.255.0",
08 "net_gateway": "192.168.2.1",
09 "state": "up",
00 }
NOTE: Fields should be defined.
setDevice(profile, device):
If "device" mode is supported, this function is used to set device for that profile.
setDeviceMode(profile, mode):
If "device_mode" mode is supported, this function is used to set device mode for that profile.
deleteConnection(profile):
Removes profile.
setAddress(profile, mode, address, mask, gateway):
If "net" mode is supported, this function is used to set address:
setAddress("Home", "manual", "192.168.2.2", "255.255.255.0", "192.168.2.1")
If "auto" modu is supported, this function is used to get address automatically:
setAddress("Home", "auth", "", "", "")
NOT: Can be simplified.
setNameService(profile, namemode, nameserver):
NOTE: Needs description
setState(profile, state):
"up" will connect, "down" will disconnect.
getState(profile):
Returns state of profile.
Function should return one of these:
"up <Address>"
"down"
"inaccessible <Error message>"
"unavailable"