1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
5 >Libpwmd Tutorial
</TITLE
8 CONTENT=
"Modular DocBook HTML Stylesheet Version 1.79"></HEAD
37 >This is a tutorial showing the basic usage of libpwmd
<A
50 >is a library making it easy to access pwmd
<A
61 >Password Manager Daemon
</I
78 >Password Manager Daemon
</I
80 > is a universal data server. It began as a way to keep track of my passwords for accounts like email and websites but can be used to store anything you want.
</P
82 >There are other password management tools but pwmd has a couple of distinguishing features:
</P
88 >It does not depend on a desktop environment but has the ability for applications to connect to it like a desktop solution provides.
</P
92 >Some portion of a stored data can be shared with another portion in the same data file. This feature behaves a lot like a symbolic link on a file system, XML entities, or HTML targets if you're familiar with those, but implemented in a different way.
</P
105 >The document is saved as an XML file and is manipulated by commands sent from a client. Commands that access data take what is called an
<SPAN
111 > as an argument. An element path is a character string containing XML element names representing branches of an element tree. The branches are separated with a TAB (ASCII
0x09) character. Why a TAB? So other characters can be used in the element name. If for example a '/' were used as the separator, then a URL (i.e., http://sf.net/) could not be used as an element name.
</P
113 >For the rest of this tutorial, when you see
<TAB
>, replace it with a real TAB character. For example, the element path
"a<TAB>child<TAB>last" has the following element tree:
</P
125 Content or XML CDATA of the
"last" element.
133 >I should say that the XML structure that pwmd uses is a little more complicated. It really looks like the following internally, but we will use the above format in this tutorial for simplicity:
</P
142 ><element
_name=
"a">
143 <element
_name=
"child">
144 <element
_name=
"last">Content or CDATA of the
"last" element.
147 </element
></PRE
152 >Every element created has an element named
<SPAN
158 > with an attribute
<SPAN
164 > associated with it. The value of the
<SPAN
170 > attribute is what an element in an element path refers to. It is done this way so that a wider range of characters can be used in an element name while maintaining valid XML. In fact, the only restriction of an element name is that it not contain whitespace characters and not begin with an exclamation point (ASCII
0x21 or !). See
<SPAN
175 HREF=
"#SEC.LINKING-ELEMENTS-1"
176 >the Section called
<I
181 >for an exception.
</P
183 >There is one other difference from your normal XML document in that only the first match of an element is considered for the current element tree depth. When an element of the current depth of an element tree is found, the next element in the element path is searched for beginning at the child node of the found element. From the example above:
</P
194 <last
>Content or XML CDATA of the
"last" element.
197 <child
>This element will never be reached.
204 >The second
"child" element is never reached, although an element of a different name may be accessed.
</P
215 >You will need a client to send commands to the pwmd server. If you are making your own application or need a simple client to connect to the server then
<SPAN
221 > may be used. It has few dependencies and - as mentioned - includes a client named
<SPAN
227 >. The rest of this tutorial will use pwmc. It is command-line based and there are not any fancy graphics, but it is good for understanding how commands are processed.
</P
229 >If you want a more user friendly client that looks like a file manager and has a point and click interface, try pwmdEdit
<A
236 > which uses the Qt4 toolkit.
</P
247 >We are using the
<SPAN
253 > client included in libpwmd. pwmc has two modes that commands are read from: interactive and stdin. The interactive mode uses the readline library and has command history while reading from standard input (stdin) makes shell scripting and automation easy. For the examples, we will be connecting to the default local unix domain socket that pwmd waits for connections on. Remote connections are possible over an SSH channel but that is not covered here. Read the pwmc(
1) manual page for how to do that.
</P
255 >The example filename we will use is
"datafile". It is initially a non-existent file but it will be created once we have saved to it. Now let us connect to the server in interactive mode and open the data file:
</P
264 >$ pwmc --interactive datafile
271 >The
"pwm>" prompt is a readline prompt that has command history and can do filename completion. It also is annoying because, as mentioned, elements in element paths are TAB delimited, but command completion in readline uses the TAB character, too. To insert a real TAB character in interactive mode rather than do readline completion, you will need to first press CTRL-V and then press TAB.
</P
282 >To store some data in an element path, you will need to know what element path to create. It is up to you how you want your data organized. If for example you will be storing account information it may be a good idea to categorize what the account is for: email, instant messaging, blogging, etc.
</P
284 >In the following example we will setup mail server element paths which can be used for other applications requiring a mail server configuration. First, lets create the hostname element path:
</P
298 >The STORE command is a pwmd protocol command. This command and some other commands use what is called a
<SPAN
304 > to retrieve data from the client, while other commands may retrieve required data only from the command arguments. The server inquire will wait for the client to finish sending its data before completing the command. When responding to a server inquire in pwmc, pwmc will show a message telling you that it is waiting for data to be sent. Enter the element path and its content, then press
<CTRL-D
> twice to finish sending the data and let pwmd complete the command:
</P
314 email
<TAB
>isp
<TAB
>IMAP
<TAB
>hostname
<TAB
>imap.server.com
<CTRL-D
><CTRL-D
></PRE
319 >Remember that you should replace
<TAB
> in the examples with a real TAB character. I should mention that when sending data via a server inquire there is no need to press CTRL-V to insert the TAB character. That is only needed from the readline command prompt and when not doing a server inquire.
</P
321 >After pressing the first CTRL-D, the line that was entered is sent to pwmd and the inquire continues. To terminate the inquire and finish sending data for the command, press CTRL-D a second time.
</P
323 >If you were to have pressed RETURN before any CTRL-D then the inquired line would have been sent in full including a newline character. Since in this example a newline character in a hostname is not a valid hostname, this is not what we want.
</P
325 >We have just created an element path whose XML structure looks like the following:
</P
337 <hostname
>imap.server.com
</hostname
>
340 </email
></PRE
345 >When an application needs to retrieve the content for the element path we have just created, it will send the GET command (libpwmd does this part) to the pwmd server. You can retrieve the content of an element path by using the GET command in pwmc, too:
</P
354 >pwm
> GET email
<TAB
>isp
<TAB
>IMAP
<TAB
>hostname
362 >Remember that in interactive mode and when not doing a server inquire, you will need to press CTRL-V before pressing TAB.
</P
364 >The XFER lines are status messages. They show the current and total length of the data transfered in bytes. The last line is the value of the element path we just created.
</P
366 >Let us create the rest of the needed elements:
</P
375 >pwm
> STORE email
<TAB
>isp
<TAB
>IMAP
<TAB
>port
<TAB
>993<CTRL-D
><CTRL-D
>
377 email
<TAB
>isp
<TAB
>IMAP
<TAB
>ssl
<TAB
>1<CTRL-D
><CTRL-D
>
379 email
<TAB
>isp
<TAB
>username
<TAB
>myusername
<CTRL-D
><CTRL-D
>
381 email
<TAB
>isp
<TAB
>password
<TAB
>mypassword
<CTRL-D
><CTRL-D
></PRE
386 >Now the element structure for the root
"email" element looks like this:
</P
398 <hostname
>imap.server.com
</hostname
>
399 <port
>993</port
>
400 <ssl
>1</ssl
>
402 <username
>myusername
</username
>
403 <password
>mypassword
</password
>
405 </email
></PRE
410 >If you wanted to change your password (after changing it on the mail server, of course) just do as you did when initially creating the password element path. The new content will overwrite the existing content:
</P
420 email
<TAB
>isp
<TAB
>password
<TAB
>newpassword
<CTRL-D
><CTRL-D
></PRE
425 >An application using libpwmd that needs to know mail server information now has all the information it needs. The only thing left to do now is to save the changes:
</P
434 >pwm
> <CTRL-D
></PRE
439 >After pressing
<CTRL-D
> a prompt will be shown asking what to do. Press
“s
” to save what we have created.
</P
441 >Since this is a new file, you will be prompted for a passphrase to use for encryption. Once done, the data file is encrypted and written to disk and the passphrase is cached in pwmd so you do not need to enter it the next time your data file is opened or saved. There are a few pwmd configuration parameters that affect how this operates. See the pwmd documentation for details.
</P
443 >Various applications using libpwmd may have different element path requirements. Refer to the documentation of each application that supports pwmd for the required elements.
</P
450 NAME=
"SEC.LINKING-ELEMENTS-1"
454 >One distinguishing feature of pwmd is the ability to share data of an element path with another. For example, if your ISP lets you host a blog on their server and you use a blogging client that supports pwmd to edit your posts, you can share authentication information with the email example above when the account details are the same. When element linking is used, this avoids the need to change the content for both the blogging and email password elements.
</P
456 >This is done by setting a special
“target
” attribute for an element. It behaves similarly to the HTML
“target
” attribute or XML entities or a symbolic link on a filesystem.
</P
458 >Let's create an example blogging element path:
</P
468 blog
<TAB
>isp
<TAB
>hostname
<TAB
>blog.myisp.com
<CTRL-D
><CTRL-D
>
470 pwm
> ATTR SET target blog
<TAB
>isp
<TAB
>username email
<TAB
>isp
<TAB
>username
471 pwm
> ATTR SET target blog
<TAB
>isp
<TAB
>password email
<TAB
>isp
<TAB
>password
</PRE
476 >Now each access of the
"blog/isp/username" and
"blog/isp/password" element paths, which were created if they did not already exist, will point to
"email/isp/username" and
"email/isp/password" respectively. To get the value or content of an element that contains a
"target" attribute without following any
“target
” attribute, prefix the element with a '!' when specifying it in an element path. For example:
</P
485 >pwm
> GET blog
<TAB
>isp
<TAB
>!password
486 ERR
536870938: No value
</PRE
491 >An error is returned because we have not assigned a value to the literal element. A literal element is an element that either contains no
"target" attribute or ignores it by prefixing the element with the mentioned literal element character '!'. Let us try storing an example password to the literal element to show usage:
</P
501 blog
<TAB
>isp
<TAB
>!password
<TAB
>newpassword
<CTRL-D
><CTRL-D
></PRE
506 >Now when we redo the previous GET command:
</P
515 >pwm
> GET blog
<TAB
>isp
<TAB
>!password
523 >This is the value of the literal password element of the element path. To follow the element path stored in the
"target" attribute, omit the '!' in the password element. This will return the
“email/isp/password
” element content:
</P
532 >pwm
> GET blog
<TAB
>isp
<TAB
>password
540 >A
"target" attribute may also refer to another element with a
"target" attribute. Every
"target" attribute will be followed until there are no others to resolve. To get the real element path and resolve all
"target" attributes, use the REALPATH command:
</P
549 >pwm
> REALPATH blog
<TAB
>isp
<TAB
>password
552 !email
<TAB
>!isp
<TAB
>!password
</PRE
557 >As you can see each element is prefixed with the literal '!' character meaning that no
"target" attribute exists in any element of the resulting element path.
</P
559 >Using the LIST command is useful to show the element structure of a document. The XFER status messages have been omitted:
</P
573 !email
<TAB
>!isp
574 !email
<TAB
>!isp
<TAB
>!username
575 !email
<TAB
>!isp
<TAB
>!password
576 !email
<TAB
>!isp
<TAB
>!IMAP
<TAB
>!hostname
577 !email
<TAB
>!isp
<TAB
>!IMAP
<TAB
>!port
578 !email
<TAB
>!isp
<TAB
>!IMAP
<TAB
>!ssl
581 !blog
<TAB
>!isp
582 !blog
<TAB
>!isp
<TAB
>!username
583 !blog
<TAB
>!isp
<TAB
>username
584 !blog
<TAB
>!isp
<TAB
>!password
585 !blog
<TAB
>!isp
<TAB
>password
</PRE
590 >Notice that there are two username and password elements in the
“blog
” element path: each with and without the literal element character prefix. This shows that both the username and password elements contain a
"target" attribute.
</P
592 >For the final example, we will remove the
“target
” attribute of the blogging password element:
</P
601 >pwm
> ATTR DELETE target blog
<TAB
>isp
<TAB
>!password
</PRE
606 >If we were to have omitted the '!' from the password element then pwmd would try to remove the
"target" attribute from the
"email/isp/password" element path. That would return an error because no
“target
” attribute had been set for that element.
</P
608 >Note that the
"blog" and
"isp" elements have no literal element character prepended to them in the example. It is not needed because they have no
“target
” attribute themselves.
</P
610 >Using
“target
” attributes can be confusing. The best way to get the hang of linking elements is to experiment and use the LIST and DUMP commands to show the document structure. Remember to use the literal element prefix '!' when you do not want to follow any
"target" attributes.
</P
639 >bjk@luxsci.net
</FONT
661 >http://libpwmd.sourceforge.net/
</FONT
683 >http://pwmd.sourceforge.net/
</FONT
705 >http://qpwmc.sourceforge.net/
</FONT