Git init
[pkgs/e/elektra.git] / doc / overview.xml
1 <!--
2 $Id$
3 -->
4
5                 <section id="libarchitecture"><title>Library Linkage Architecture</title>
6                         <para>The Elektra library (<filename>libelektra.so</filename>) has 2 layers: public methods and backend access, according to the following architecture (these pictures were taken from the <ulink url="elektra.sxi">Elektra presentation</ulink>):</para>
7                         <para><graphic srccredit="genericarch" fileref="images/genericarch.png" label="generic architecture" align="center"/></para>
8                         <para>When using local backends such as the filesys backend, all key access happens in the actual process space as bellow:</para>
9                         <para><graphic srccredit="localbacks" fileref="images/localbacks.png" label="local backends" align="center"/></para>
10                         <para>A remote daemon backend is also possible as noted bellow:</para>
11                         <para><graphic srccredit="daemonback" fileref="images/daemonback.png" label="daemon backend" align="center"/></para>
12                 </section>
13                 <section id="rgfacts"><title>True Facts About Elektra</title>
14                         <itemizedlist>
15                                 <listitem><para>It is much more an agreement then a piece of software. Relation is 99% to 1%.</para></listitem>
16                                 <listitem><para>It is a simple and consistent API to help software developers programatically store and retrieve global and user-specific configuration parameters.</para></listitem>
17                                 <listitem><para>All key-value pairs are stored in clear-text files, UTF-8 encoded. All old charsets are also supported, with automatic transparent conversion to and from UTF-8.</para></listitem>
18                                 <listitem><para>API supports change notifications and multiple backends.</para></listitem>
19                                 <listitem><para>It provides a unique namespace for all values. Anywhere, anytime, any program can preciselly access keys by their names. Security restrictions may obviously apply.</para></listitem>
20                                 <listitem><para>It is designed to be secure and lightweight, to let even early boot-stage programs like <command>/sbin/init</command> to use it, instead of <filename>/etc/inittab</filename> file.</para></listitem>
21                                 <listitem><para>It is designed to be easy to administrate with regular command line tools like <command>cat</command>, <command>vi</command>, <command>cp</command>, <command>ls</command>, <command>ln</command>. Its storage is 100% open.</para></listitem>
22                                 <listitem><para>It tries to set distribution-independent naming standards to store things like hardware configuration, networking, user's session configuration, system's mime-types, parameters for kernel modules, etc, that are generally stored under <filename>/etc</filename >.</para></listitem>
23                                 <listitem><para>It requires existing software to be changed to use its API. This will substitute hundreds of configuration-text-file parsing code, into clear Elektra's API key-value access methods.</para></listitem>
24                                 <listitem><para>It is POSIX compliant. If it doesn't compile and run easily on some POSIX system, it should be easily modified to do so.</para></listitem>
25                         </itemizedlist>
26                 </section>
27
28                 <section id="rgnot"><title>Elektra Is Not</title>
29                         <itemizedlist>
30                                 <listitem><para>Is NOT something that accesses SQL/relational databases.</para ></listitem>
31                                 <listitem><para>Is NOT an OS service that can become unavailable and make system unusable. It is just a library to access files according to a namespace.</para ></listitem >
32                                 <listitem><para>Is NOT an alternative to network information systems like LDAP or NIS. These are still required for networked environments.</para ></listitem >
33                                 <listitem><para>Is NOT a Webmin-like or other GUI tool to be used by end users.</para ></listitem >
34                                 <listitem><para>Is NOT an additional software layer to edit/generate existing configuration files.</para></listitem>
35                                 <listitem><para>Is NOT a "configuration system", because one can't be created by simply writing some code. A configuration system is an ecosystem, and the Elektra Project tries to help build one.</para></listitem>
36                                 <listitem><para>It doesn't know a thing about the semantics of each data it stores.</para></listitem>
37                         </itemizedlist>
38                 </section>
39
40         
41         <section id="namespace"><title>Namespaces and Key Names</title>
42                 <para>All keys are organized in a hierarchical tree with 2 Namespaces (subtrees) as showed by the picture:</para>
43                 <para><graphic srccredit="roots" fileref="images/roots.png" label="roots" align="center"/></para>
44                 <variablelist>
45                         <varlistentry><term><type>system</type></term>
46                                 <listitem><para>Contains all subsystems and global application keys/configuration. Equivalent to files under <filename>/etc</filename> directory.</para></listitem>
47                         </varlistentry>
48                         <varlistentry><term><type>user</type></term>
49                                 <listitem><para>The current user's keys. Equivalent to the dotfiles in a user's <envar>$HOME</envar> directory. These keys are phisically stored under the owner user home directory. The many <filename>user:</filename><replaceable>username</replaceable> in the picture shows the full name of those trees. Read about user domains bellow for more.</para></listitem>
50                         </varlistentry>
51                 </variablelist>
52                 <section id="userdomains"><title>User Domains</title>
53                         <para>Different from the <filename>system</filename> namespace, the <filename>user</filename> namespace is dynamic. For example, the key <filename>user/env/PATH</filename> may have completely different values for users <replaceable>luciana</replaceable> and <replaceable>valeria</replaceable>. In this example, if <replaceable>valeria</replaceable> wants to access this key at <replaceable>luciana</replaceable>'s space, it should refer to <filename>user:luciana/env/PATH</filename>. Access permissions apply.</para>
54                         <para>User domains were implemented also to address situations when different user names (<envar>$USER</envar>) have same UID. So a user key is stored in his home directory based on the user name, not the UID.</para>
55                 </section>
56                 <section id="inactivekey"><title>Inactive Keys</title>
57                         <para>A great thing about text configuration files is that some configuration items can be there as an example, but inactive or commented. Elektra provides a very simple way to simulate this behavior: if the key name begins with a dot (.), it is considered inactive or commented. In real world applications, the Elektra API will ignore these keys by default, but the keys are still accessible if the developer wants to.</para>
58                         <para>These are some keys that have inactive subtrees:</para>
59                         <itemizedlist>
60                                 <listitem><simpara><filename>system/sw/XFree/InputDevice/.Mouse3/Driver</filename>: All keys under <filename>.Mouse3/*</filename> subtree won't be read by default.</simpara></listitem>
61                                 <listitem><simpara><filename>user:valeria/env/env2/.PATH</filename>: The <envar>$PATH</envar> environment variable <emphasis>won't</emphasis> be set when <replaceable>valeria</replaceable> login.</simpara></listitem>
62                                 <listitem><simpara><filename>system/users/.louis/uid</filename>: The entire <filename>.louis/*</filename> subtree is inactive. This is the same as commenting the user entry from a configuration file.</simpara></listitem>
63                         </itemizedlist>
64                         <para>See bellow more examples of inactive keys.</para>
65                 </section>
66                 <section id="keyexamples"><title>Key Examples</title>
67                         <para>Here are some valid key names, and their values:</para>
68                         <para>The Elektra keys of the combined <filename>/etc/passwd</filename> and <filename>/etc/shadow</filename> entry for user 'nobody' would look like:</para>
69                         <itemizedlist>
70                                 <listitem><simpara><filename>system/users/nobody/uid</filename>: 99</simpara></listitem>
71                                 <listitem><simpara><filename>system/users/nobody/gid</filename>: 99</simpara></listitem>
72                                 <listitem><simpara><filename>system/users/nobody/gecos</filename>: Nobody</simpara></listitem>
73                                 <listitem><simpara><filename>system/users/nobody/home</filename>: /</simpara></listitem>
74                                 <listitem><simpara><filename>system/users/nobody/shell</filename>: /sbin/nologin</simpara></listitem>
75                                 <listitem><simpara><filename>system/users/nobody/password</filename>: *</simpara></listitem>
76                                 <listitem><simpara><filename>system/users/nobody/passwdChangeBefore</filename>: 0</simpara></listitem>
77                                 <listitem><simpara><filename>system/users/nobody/passwdChangeAfter</filename>: 99999</simpara></listitem>
78                                 <listitem><simpara><filename>system/users/nobody/passwdWarnBefore</filename>: 7</simpara></listitem>
79                                 <listitem><simpara><filename>system/users/nobody/passwdDisableAfter</filename>: </simpara></listitem>
80                                 <listitem><simpara><filename>system/users/nobody/passwdDisabledSince</filename>: </simpara></listitem>
81                                 <listitem><simpara><filename>system/users/nobody/passwdReserved</filename>: </simpara></listitem>
82                         </itemizedlist>
83                         <para>The environment variables I want set, when I log in, with their full key name:</para>
84                         <itemizedlist>
85                                 <listitem><simpara><filename>user:aviram/env/env1/JAVA_HOME</filename>: /usr/lib/jvm/java-1.4.1-ibm-1.4.1.0/jre</simpara></listitem>
86                                 <listitem><simpara><filename>user:aviram/env/env2/PATH</filename>: $PATH:~/bin:$JAVA_HOME/bin</simpara></listitem>
87                                 <listitem><simpara><filename>user:aviram/env/env2/PS1</filename>: \h:\w\$ </simpara></listitem>
88                                 <listitem><simpara><filename>user:aviram/env/env3/PILOTRATE</filename>: 57600</simpara></listitem>
89                         </itemizedlist>
90                         <para>The entry in <filename>/etc/inittab</filename> that is responsible for starting X11 would look:</para>
91                         <itemizedlist>
92                                 <listitem><simpara><filename>system/init/x/runlevels</filename>: 5</simpara></listitem>
93                                 <listitem><simpara><filename>system/init/x/action</filename>: respawn</simpara></listitem>
94                                 <listitem><simpara><filename>system/init/x/process</filename>: /etc/X11/prefdm -nodaemon</simpara></listitem>
95                         </itemizedlist>
96                         <para>The users database files and <filename>/etc/inittab</filename> were Elektrified to key-value pairs using the <command>users-convert</command> and <command>inittab-convert</command> scripts included with the distribution.</para>
97                         <para>An example of an elektrified <filename>/etc/X11/xorg.conf</filename> or <filename>/etc/X11/XF86Config</filename>:</para>
98                         <itemizedlist>
99                                 <listitem><simpara><filename>system/sw/xorg/current/Layouts/Default Layout/Inputs/Keyboard0/CoreKeyboard</filename>:</simpara></listitem>
100                                 <listitem><simpara><filename>system/sw/xorg/current/Layouts/Default Layout/Inputs/Mouse0/CorePointer</filename>:</simpara></listitem>
101                                 <listitem><simpara><filename>system/sw/xorg/current/Layouts/Default Layout/Screens/Screen0/Absolute.x</filename>: 0</simpara></listitem>
102                                 <listitem><simpara><filename>system/sw/xorg/current/Layouts/Default Layout/Screens/Screen0/Absolute.y</filename>: 0</simpara></listitem>
103                                 <listitem><simpara><filename>system/sw/xorg/current/Layouts/Default Layout/Screens/Screen0/ScreenNumber</filename>: 0</simpara></listitem>
104                                 
105                                 <listitem><simpara><filename>system/sw/xorg/current/Files/FontPath</filename>: unix/:7100</simpara></listitem>
106                                 <listitem><simpara><filename>system/sw/xorg/current/Files/RgbPath</filename>: /usr/X11R6/lib/X11/rgb</simpara></listitem>
107                                 
108                                 <listitem><simpara><filename>system/sw/xorg/current/Devices/Videocard0/BoardName</filename>: Intel 740 (generic)</simpara></listitem>
109                                 <listitem><simpara><filename>system/sw/xorg/current/Devices/Videocard0/Driver</filename>: i740</simpara></listitem>
110                                 <listitem><simpara><filename>system/sw/xorg/current/Devices/Videocard0/VendorName</filename>: Videocard vendor</simpara></listitem>
111                                 
112                                 <listitem><simpara><filename>system/sw/xorg/current/InputDevices/Keyboard0/Driver</filename>: keyboard</simpara></listitem>
113                                 <listitem><simpara><filename>system/sw/xorg/current/InputDevices/Keyboard0/Options/XkbLayout</filename>: us_intl</simpara></listitem>
114                                 <listitem><simpara><filename>system/sw/xorg/current/InputDevices/Keyboard0/Options/XkbModel</filename>: pc105</simpara></listitem>
115                                 <listitem><simpara><filename>system/sw/xorg/current/InputDevices/Mouse0/Driver</filename>: mouse</simpara></listitem>
116                                 <listitem><simpara><filename>system/sw/xorg/current/InputDevices/Mouse0/Options/Device</filename>: /dev/input/mice</simpara></listitem>
117                                 <listitem><simpara><filename>system/sw/xorg/current/InputDevices/Mouse0/Options/Emulate3Buttons</filename>: yes</simpara></listitem>
118                                 <listitem><simpara><filename>system/sw/xorg/current/InputDevices/Mouse0/Options/Protocol</filename>: IMPS/2</simpara></listitem>
119                                 <listitem><simpara><filename>system/sw/xorg/current/InputDevices/Mouse0/Options/ZAxisMapping</filename>: 4 5</simpara></listitem>
120                                 
121                                 <listitem><simpara><filename>system/sw/xorg/current/Monitors/Monitor0/DisplaySize.height</filename>: 230</simpara></listitem>
122                                 <listitem><simpara><filename>system/sw/xorg/current/Monitors/Monitor0/DisplaySize.width</filename>: 300</simpara></listitem>
123                                 <listitem><simpara><filename>system/sw/xorg/current/Monitors/Monitor0/HorizSync</filename>: 30.0 - 61.0</simpara></listitem>
124                                 <listitem><simpara><filename>system/sw/xorg/current/Monitors/Monitor0/ModelName</filename>: SyncMaster</simpara></listitem>
125                                 <listitem><simpara><filename>system/sw/xorg/current/Monitors/Monitor0/Options/dpms</filename>:</simpara></listitem>
126                                 <listitem><simpara><filename>system/sw/xorg/current/Monitors/Monitor0/VendorName</filename>: Monitor Vendor</simpara></listitem>
127                                 <listitem><simpara><filename>system/sw/xorg/current/Monitors/Monitor0/VertRefresh</filename>: 56.0 - 75.0</simpara></listitem>
128                                 
129                                 <listitem><simpara><filename>system/sw/xorg/current/Monitors/.Monitor1/HorizSync</filename>: 30.0 - 61.0</simpara></listitem>
130                                 <listitem><simpara><filename>system/sw/xorg/current/Monitors/.Monitor1/ModelName</filename>: Impression</simpara></listitem>
131                                 <listitem><simpara><filename>system/sw/xorg/current/Monitors/.Monitor1/Options/dpms</filename>:</simpara></listitem>
132                                 <listitem><simpara><filename>system/sw/xorg/current/Monitors/.Monitor1/VendorName</filename>: Monitor Vendor</simpara></listitem>
133                                 <listitem><simpara><filename>system/sw/xorg/current/Monitors/.Monitor1/VertRefresh</filename>: 56.0 - 75.0</simpara></listitem>
134                                 
135                                 <listitem><simpara><filename>system/sw/xorg/current/Screens/Screen0/DefaultDepth</filename>: 16</simpara></listitem>
136                                 <listitem><simpara><filename>system/sw/xorg/current/Screens/Screen0/Device</filename>: Videocard0</simpara></listitem>
137                                 <listitem><simpara><filename>system/sw/xorg/current/Screens/Screen0/Displays/00/Depth</filename>: 16</simpara></listitem>
138                                 <listitem><simpara><filename>system/sw/xorg/current/Screens/Screen0/Displays/00/Modes</filename>: 1024x768,800x600,640x480</simpara></listitem>
139                                 <listitem><simpara><filename>system/sw/xorg/current/Screens/Screen0/Displays/00/Viewport.x</filename>:  0</simpara></listitem>
140                                 <listitem><simpara><filename>system/sw/xorg/current/Screens/Screen0/Displays/00/Viewport.y</filename>:  0</simpara></listitem>
141                                 <listitem><simpara><filename>system/sw/xorg/current/Screens/Screen0/Monitor</filename>:  Monitor0</simpara></listitem>
142                                 
143                                 <listitem><simpara><filename>system/sw/xorg/current/Modules/dbe</filename>: </simpara></listitem>
144                                 <listitem><simpara><filename>system/sw/xorg/current/Modules/dri</filename>: </simpara></listitem>
145                                 <listitem><simpara><filename>system/sw/xorg/current/Modules/extmod</filename>: </simpara></listitem>
146                                 <listitem><simpara><filename>system/sw/xorg/current/Modules/fbdevhw</filename>: </simpara></listitem>
147                                 <listitem><simpara><filename>system/sw/xorg/current/Modules/freetype</filename>: </simpara></listitem>
148                                 <listitem><simpara><filename>system/sw/xorg/current/Modules/glx</filename>: </simpara></listitem>
149                                 <listitem><simpara><filename>system/sw/xorg/current/Modules/record</filename>: </simpara></listitem>
150                                 <listitem><simpara><filename>system/sw/xorg/current/Modules/type1</filename>:</simpara></listitem>
151                                 
152                                 <listitem><simpara><filename>system/sw/xorg/current/DRI/Group</filename>: 0</simpara></listitem>
153                                 <listitem><simpara><filename>system/sw/xorg/current/DRI/Mode</filename>: 0666</simpara></listitem>
154                         </itemizedlist>
155                         <para>Pay attention that the keys bellow <filename>system/sw/XFree/current/Monitor/.Monitor1</filename> are inactive because we have <filename>.Monitor1</filename> as their parent. So unless special options are used when calling the API, these keys will not be retrieved from the database.</para>
156                         <para>Throughout this text you will see other examples of key names.</para>
157                 </section>
158         </section>
159
160         
161         <section id="datatypes"><title>Key Data Types</title>
162                 <para>There are only two types of data that can be stored:</para>
163                 <variablelist>
164                         <varlistentry><term><type>Text</type></term>
165                                 <listitem><para>Handled as pure text. Regardeless of the charset being used, these values are always stored as UTF-8. This ensures very strong internationalization and migration capabilities, while keeping simplicity. If you don't want the Elektra framework to convert your non-ASCII text to UTF-8 (not recomended), you should use the Binary data format.</para></listitem>
166                         </varlistentry>
167                         <varlistentry><term><type>Binary</type></term>
168                                 <listitem><para>A stream of bytes, not necessarily text. It is recommended that you avoid using binary values because UNIX system administrators tend to consider them as unmanageable blackboxes. Anyway, the value will be encoded into pure text format based on hexadecimal digits, for openness and ease of administration. This data type should also be avoided because it is less efficient.</para></listitem>
169                         </varlistentry>
170                 </variablelist>
171                 <para>There are very good reasons why types like <type>Integer</type>, <type>Time</type>, <type>Font</type>, <type>List</type>, etc were not implemented: Elektra was designed to be usefull for any type of program, so having more specific data types implicates in the definition of value limits, separators in the storage format, etc, that may be good for some application and bad for other. So the semantics of the data is handled by the application. A program or framework may define its own special data handling methods using these essential basic types. See the <function>keyGetType()</function> and <function>keySetType()</function> methods documentation in the  <citerefentry><refentrytitle>kdb</refentrytitle><manvolnum>3</manvolnum></citerefentry> man page to understand how to set keys with your own data types.</para>
172                 <para>There are more two types of keys:</para>
173                 <variablelist>
174                         <varlistentry><term><type>Directory</type></term>
175                                 <listitem><para>It can't store a value, but, as a directory in a filesystem, it serves as a way to group correlated keys.</para></listitem>
176                         </varlistentry>
177                         <varlistentry><term><type>Link</type></term>
178                                 <listitem><para>It is a link to another key. They work as symbolic links in the filesystem: when trying to access them, you will actually access the key they point to. The API also provides ways to access these special keys without dereferencing them.</para></listitem>
179                         </varlistentry>
180                 </variablelist>
181         </section>
182
183         <section id="metadata"><title>Key Meta Data</title>
184                 <para>Besides the key name and the value, each key has other attributes:</para>
185                 <variablelist>
186                         <varlistentry><term><type>Owner's User and Group</type></term>
187                                 <listitem><para>This is a system's UID and GID equal to the ones found in regular files' attributes.</para></listitem>
188                         </varlistentry>
189                         <varlistentry><term><type>Access Permissions</type></term>
190                                 <listitem><para>Filesystem-like access permissions for user, group and others.</para></listitem>
191                         </varlistentry>
192                         <varlistentry><term><type>Modification, Access and Stat Times</type></term>
193                                 <listitem><para>Last time a key was modified, readed and stated (listed), respectively.</para></listitem>
194                         </varlistentry>
195                         <varlistentry><term><type>Key Comment</type></term >
196                                 <listitem><para>Pretty much as a configuration file comment. Not intended to be used in GUI applications, because it isn't internationalizable.</para></listitem>
197                         </varlistentry>
198                 </variablelist>
199                 <section id="securityexample"><title>Fine Grained Security Example</title>
200                         <para>To show this metadata in action, this screen shows the <command>kdb</command> command listing keys and their attributes related to user <varname>nobody</varname>.</para>
201                         <screen><prompt>bash$</prompt> <command>kdb ls -Rlv system/users/nobody</command>
202 -rw-r--r--   root  root    17 Mar 31 09:07 system/users/nobody/uid=99
203 -rw-r--r--   root  root    17 Mar 31 09:07 system/users/nobody/gid=99
204 -rw-r--r--   root  root    21 Mar 31 09:07 system/users/nobody/gecos=Nobody
205 -rw-r--r--   root  root    16 Mar 31 09:07 system/users/nobody/home=/
206 -rw-r--r--   root  root    28 Mar 31 09:07 system/users/nobody/shell=/sbin/nologin
207 -rw-------   root  root    16 Mar 31 09:07 system/users/nobody/password
208 -rw-------   root  root    16 Mar 31 09:07 system/users/nobody/passwdChangeBefore
209 -rw-------   root  root    20 Mar 31 09:07 system/users/nobody/passwdChangeAfter
210 -rw-------   root  root    16 Mar 31 09:07 system/users/nobody/passwdWarnBefore
211 -rw-------   root  root    15 Mar 31 09:07 system/users/nobody/passwdDisableAfter
212 -rw-------   root  root    15 Mar 31 09:07 system/users/nobody/passwdDisabledSince
213 -rw-------   root  root    15 Mar 31 09:07 system/users/nobody/passwdReserved
214                         </screen>
215                         <para>We ran the <command>kdb</command> command without super-user credentials, asking for long (<option>-l</option>), recursive (<option>-R</option>) listing, and to show each key value (<option>-v</option>). But (since we are) regular user, we don't have permission to see the values of the <filename>system/users/nobody/passwd*</filename> fields.</para>
216                         <para>The users database files were elektrified to key-value pairs using the <command>users-convert</command> script included with the distribution.</para>
217                 </section>
218         </section>
219