Updated the documentation.
[pwmd.git] / doc / COMMANDS
blob108e30917ba4c6f3693722f8549273d529de8c2e
1 The server uses a protocol provided by libassuan to communicate with the
2 client. An OK response is returned when a command succeeds or ERR along with
3 an error code and description, if not. When a command requests data for
4 retrieval (e.g., GET) the output is prefixed with D then a single SPACE then
5 the actual data followed by a response. Read the libassuan docs for more info
6 about the protocol.
9 PROTOCOL COMMANDS
10 -----------------
11 OPEN <filename> [<key>]
12     Opens <filename> using <key>. If the filename is not found on the
13     file-system, then a new document will be created. If the file is found, it
14     is looked for in the file cache for an existing key. When found and no key
15     was specified, the cached key will be used for decryption (if encrypted).
16     When not found, pinentry(1) will be used to retrieve the key (see OPTIONS
17     below). You can also open a different file using the same connection. When
18     using an empty or NULL key and you want to avoid the pinentry dialog, set
19     ENABLE_PINENTRY to 0 (see OPTIONS below).
22 SAVE [<key>]
23     Writes the XML document to disk. The file written to is the file that was
24     opened using the OPEN command. If <key> is not specified then the
25     currently cached key will be used. If the file is a new file or the file
26     isn't found in the file cache, <key> will be used. If <key> is not
27     specified then pinentry(1) will be used to retrieve the key (see OPTIONS
28     below). If you want to use and empty key and want to avoid the pinentry
29     dialog, set ENABLE_PINENTRY to 0 (see OPTIONS below).
32 ISCACHED <filename>
33     An OK response is returned if the specified file is found in the file
34     cache. If not found in the cache but exists on the filesystem,
35     GPG_ERR_NOT_FOUND is returned. Otherwise a filesystem error is returned.
38 CLEARCACHE [<filename>]
39     Clears a file cache entry. This will forget the timeout and key for all or
40     the specified file. Always returns an OK response.
43 CACHETIMEOUT <filename> <seconds>
44     Specify the number of seconds the specified file will be cached. -1 will
45     keep the cache entry forever, 0 will require the key each time the OPEN or
46     SAVE commands are used. Also see the "cache_timeout" configuration
47     parameter. Returns ERR if the filename isn't cached or if the timeout is
48     invalid. OK otherwise.
51 LIST [[!]element[<TAB>[!]element[...]]]
52     If no element path is given then a list of root elements is returned with
53     the data response. If given, then all reachable elements for the
54     specified element path are returned. Each element in the path is prefixed
55     with the literal '!' character when the element contains no "target"
56     attribute (See THE TARGET ATTRIBUTE below).
59 REALPATH [!]element[<TAB>[!]element[...]]
60     Resolves all "target" attributes of the specified element path and returns
61     the result with a data response.
64 STORE [!]element[[<TAB>[!]element[...]]<TAB>[content]]
65     Creates a new element tree or modifies the content of an existing element
66     path. If only a single element is specified, a new root element is
67     created. Otherwise, elements are TAB delimited and the content will be set
68     to the last TAB delimited argument. If no content is specified after the
69     last TAB then the content for the last specified element will be removed
70     or empty if creating a new element.
71     
72     The only restriction of element names is that they not begin with a
73     punctuation character (the literal '!' character is an exception) or digit
74     and not contain any whitespace. There is no whitespace between the TAB
75     delimited elements. It is recommended that the value be base 64 encoded to
76     prevent XML and pwmd parsing errors.
77     
78     PWMD reads the element path from the client via the Assuan INQUIRE
79     protocol response. The STORE command is sent by itself without arguments,
80     then the server responds with INQUIRE. The client then sends the element
81     path prefixed with a "D " data response. The element path may extend
82     multiple lines but each must be prefixed with the data "D " response. When
83     finished, the client sends "END" on an empty line. This is needed so an
84     element path and value can be more than 1000 bytes long, the Assuan
85     protocol line limit.
88 DELETE [!]element[<TAB>[!]element[...]]
89     Removes an element tree from the specified element path.
92 GET [!]element[<TAB>[!]element[...]]
93     Retrieves the content or text node of the specified element path. The data
94     is returned with a data response.
97 ATTR SET|GET|DELETE|LIST [<attribute>] [!]<arg1> [!][arg2]
98     ATTR SET attribute [!]element[<TAB>[!]element[...]] attribute_value
99         Stores or updates an attribute value of an element path.
101     ATTR DELETE attribute [!]element[<TAB>[!]element[...]]
102         Removes an attribute from an element path.
104     ATTR LIST [!]element[<TAB>[!]element[...]]
105         Gets a list of attributes from an element path.
107     ATTR GET attribute [!]element[<TAB>[!]element[...]]
108         Gets the value of an attribute from an element path.
110     The "name" attribute (case sensitive) cannot be removed with ATTR DELETE
111     if the element path is the root element. Although it can be SET to change
112     the root element name.
114     Also see THE TARGET ATTRIBUTE below.
117 XPATH <expression>[<TAB>[value]]
118     Evaluates an XPath expression. If no value argument is specified, it is
119     assumed the expression is a request to return a result. Otherwise, the
120     result is set to the value argument and the document is updated. If there
121     is no value after the <TAB> character, the value is assumed to be empty
122     and the document is updated.
125 IMPORT [!]element[<TAB>[!]element[...]] <content>
126     Like the STORE command (an INQUIRE), but the content argument is raw XML
127     data. The content is created as a child of the specified element path. If
128     an element of the element path does not exist, it is created.
130     Note that the new content must begin with an element node. Also note that
131     an existing child node of the same element name as the root node of the
132     imported content will be overwritten.
135 DUMP
136     Shows the in memory XML document with indenting. To dump a specific
137     element tree, use the XPATH command.
140 LOCK
141     Locks the mutex associated with the opened file. This prevents other
142     clients from sending commands to the same opened file until the client
143     that sent this command either disconnects or sends the UNLOCK command.
146 UNLOCK
147     Unlocks the mutex which was locked with the LOCK command.
150 GETPID
151     Retrieves the process id of the server.
154 GETCONFIG [filename] <parameter>
155     Returns the value of a pwmd configuration variable with a data response.
156     If no file has been opened then the value for the specified file or the
157     default from the "global" section will be returned. If a file has been
158     opened and no filename is specified, the value previously set with the SET
159     command, if any, will be returned.
161     If there is no such parameter defined, GPG_ERR_NO_VALUE is returned.
164 VERSION
165     Returns the server version number with a data response.
168 SET <NAME>=<VALUE>
169     Sets an option NAME to VALUE. See OPTIONS below for available options.
172 UNSET <NAME>
173     Resets option NAME to the value specified in the server configuration
174     file. Some options have no default and will be reset to NULL or 0
175     depending on the type.
179     Closes the connection disconnecting the client. Unless the SAVE command
180     had been sent, any changes to the document will be lost.
183 OPTIONS
184 -------
185 Commands that require a key that is neither cached nor specified will use
186 pinentry(1) to retrieve the key. Pinentry options can be set with the SET
187 command followed by the option name and value. Below are the available pwmd
188 options:
190     NAME             |VALUE     |Description
191     -----------------|----------|----------------------------------------------
192     ENABLE_PINENTRY   0|1        When 0, disable use of pinentry. The default
193                                  is 1.
194     PINENTRY_TIMEOUT  <integer>  The number of seconds before the pinentry
195                                  process will terminate while waiting for a
196                                  passphrase. The default is 20, 0 disables.
197     PINENTRTY_PATH    <string>   Full path to the pinentry binary. The default
198                                  is specified at compile time.
199     TTYNAME           <string>   Same as the --ttyname option to pinentry(1).
200     TTYTYPE           <string>   Same as the --ttytype option to pinentry(1).
201     DISPLAY           <string>   Same as the --display option to pinentry(1).
202     TITLE             <string>   Sets the title string of the pinentry dialog.
203     PROMPT            <string>   Sets the prompt string of the pinentry dialog.
204     DESC              <string>   Sets the error or description string of the
205                                  pinentry dialog.
206     LC_CTYPE          <string>   Same as the --lc-ctype option to pinentry(1).
207     LC_MESSAGES       <string>   Same as the --lc-messages option to
208                                  pinentry(1).
209     ITERATIONS        <integer>  The number of encryption iterations to do
210                                  when the SAVE command is sent. An opened file
211                                  is needed when setting this option. The
212                                  CONFIG status message is sent after receiving
213                                  this command.
214     NAME              <string>   Associates the thread ID of the connection
215                                  with the specified textual representation.
216                                  Useful for debugging log messages.
218 When pinentry is used with the SAVE command the passphrase will be asked for
219 confirmation. If the confirmation fails, the process is started over again
220 until either the passphrases match or until Cancel is selected. The OPEN
221 command will only ask for the passphrase once without retrying on failure. It
222 is up to the client to retry the OPEN command. Empty keys are allowed. To
223 prevent pinentry asking for an (empty) passphrase, use SET ENABLE_PINENTRY=0.
225 To reset an option value string to its default, use the UNSET command.
228 STATUS MESSAGES
229 ---------------
230 Some commands send a status message to the client when successful or as a
231 progress indicator. Status messages begin with a KEYWORD (see below) followed
232 by the status description. What messages are sent, when, and how often, depend
233 on configuration settings:
235     COMMAND      | KEYWORD
236     -------------|-------------
237     <ALL>         LOCKED
239     OPEN          DECRYPT
240                   DECOMPRESS
241                   CACHE
243     SAVE          COMPRESS
244                   ENCRYPT
245                   CACHE
247     GET           XFER
249     LIST          XFER
251     DUMP          XFER
253     XPATH         XFER
255     CLEARCACHE    CACHE
257     CACHETIMEOUT  CACHE
260     KEYWORD    |OUTPUT FORMAT
261     -----------|--------------------
262     CACHE       <slots used>
263                 Sent to each client after the file cache changes.
264     ENCRYPT     <iterations so far> <total iterations>
265     DECRYPT     <iterations so far> <total iterations>
266     COMPRESS    <bytes so far> <total bytes>
267     DECOMPRESS  <bytes so far> <total bytes>
268     XFER        <bytes so far> <total bytes>
269     LOCKED      When another thread owns a mutex lock that the current thread
270                 needs, this is status message is sent and the thread will
271                 block until the lock can be obtained.
272     KEEPALIVE   Sent to each client after every configured amount of
273                 seconds. It is important that this status message be sent to
274                 test for client connectivity.
275     CONFIG      Sent to each client after the configuration file has
276                 been reloaded or has had a value changed that may affect other
277                 connected clients.
278     CLIENTS     Sent to each client after a client connects or disconnects.
281 THE TARGET ATTRIBUTE
282 --------------------
283 There is a special attribute "target" (case sensitive) that can be set with
284 ATTR SET. The value of this attribute is an element path that is located
285 somewhere else in the XML document and are alot like how XPath treats
286 entities, but is needed do to how pwmd commands are implemented. The syntax
287 is as follows:
289 ATTR SET target [!]element[<TAB>[!]element[..]] [!]element[<TAB>[!]element[..]]
290                 arg1^^^^^^^^^^^^^^^^^^^^^^^^^^^ arg2^^^^^^^^^^^^^^^^^^^^^^^^^^^
292 If the element path of the "target" attribute (arg1) doesn't exist, it is
293 created. This is the only time the ATTR command will create elements.
295 When a protocol command requests <arg1> as the element path, the remaining
296 elements after the element with the "target" attribute will be appended to
297 <arg2>. This is useful if you have elements that share the same data. If the
298 target is modified, the other elements "pointing" to the target will have the
299 same content. To get the real or literal element and ignore any "target"
300 attributes, prefix the element with a '!' character. Here's an example:
302     C> STORE
303     S> INQUIRE STORE
304     C> D host1<TAB>username<TAB>original username
305     C> END
306     S> OK
307     C> STORE
308     S> INQUIRE STORE
309     C> D host2<TAB>smtp<TAB>username<TAB>someuser
310     C> END
311     S> OK
312     C> ATTR SET target host1<TAB>username host2<TAB>smtp<TAB>username
313     S> OK
315 Now host1's "target" attribute will be used:
317     C> GET host1<TAB>username
318     S> D someuser
319     S> OK
321 If you want host1's username, prefix the element of the "target" attribute
322 with a '!':
324     C> GET host1<TAB>!username
325     S> D original username
326     S> OK
328 The target value (arg2) element can also have a "target" attribute:
330     C> ATTR SET target new_account host1
331     S> OK
332     C> GET new_account<TAB>username
333     S> D someuser
334     S> OK
336 The value of the "target" attribute may also be prefixed with a '!' to set the
337 target to the actual element path and not a target of the element path:
339     C> ATTR DELETE target !new_account
340     S> OK
341     C> ATTR SET target new_account<TAB>username host1<TAB>!username
342     S> OK
343     C> GET new_account<TAB>username
344     S> D original username
345     S> OK
347 The "target" attribute is considered for all commands that support an element
348 path. If the target element has been renamed or deleted afterwards, the
349 command will fail.
351 Clients should be careful of creating target loops. See the "recursion_depth"
352 configuration parameter for details.
355 XML DOCUMENT STRUCTURE
356 ----------------------
357 When importing an XML data file with the -I command line option, the document
358 should have the following DTD:
360     <?xml version="1.0"?>
361     <!DOCTYPE pwmd [
362     <!ELEMENT pwmd (root*)>
363     <!ATTLIST root name CDATA #REQUIRED>
364     ]>
366 The "pwmd" element is the document root node while the first element of an
367 element path specified in protocol commands use the "root" element. So if you
368 specify the command "LIST isp", "isp" is really a "root" element that has a
369 "name" attribute with the value "isp". Any following elements are children of
370 the "root" element:
372     <pwmd>
373         <root name="isp">
374         [...]
375         </root>
376     </pwmd>
378 The remaining <TAB> delimited elements (e.g., "LIST isp<TAB>SMTP") are regular
379 elements and are not treated specially in the XML document.
381 The DUMP command might be useful to show the document structure.
383 Ben Kibbey <bjk@luxsci.net>
384 http://bjk.sourceforge.net/pwmd/