Fixed checking for setrlimit() and mlockall() which was removed during
[pwmd.git] / COMMANDS
blob4e946e63f384fe51d11f24bb338972fbd89a3f83
1 The server uses a protocol provided by libassuan to communicate with a client.
2 An OK response is returned when a command succeeds or ERR along with an error
3 code and description, if not. When a command requests data for retrieval
4 (e.g., GET) the output is prefixed with D then a single SPACE then the actual
5 data followed by an OK response. Read the libassuan docs for more info about
6 the protocol.
9 PROTOCOL COMMANDS
10 -----------------
12 OPEN <filename> [<key>]
13     Opens <filename> using <key>. If file is not found on the file-system, then
14     a new document will be created. If the file is found, it is looked for in
15     the file cache for an existing key. When found, the existing key will be
16     used for decryption. You can also open another file using the same
17     connection.
20 SAVE [<key>]
21     Writes the XML document to disk. The file written to is the file that was
22     opened using the OPEN command. If <key> is not specified then the
23     currently cached key will be used. If the file is a new file or the file
24     isn't found in the file cache, <key> is required.
27 ISCACHED <filename>
28     An OK response is returned if the specified file is in the file cache.
31 CLEARCACHE [<filename>]
32     Clears a file cache entry. This will forget the timeout and key for all or
33     the specified file.
36 CACHETIMEOUT <seconds> <filename>
37     Specify the number of seconds the specified file will be cached. -1 will
38     keep the cache entry forever, 0 will require the key each time the OPEN or
39     SAVE commands are used. Also see the "cache_timeout" configuration option.
42 LIST [[!]element[<TAB>[!]element[...]]]
43     If no element path is given then a list of root elements is returned with
44     the data response code. If given, then all reachable elements for the
45     specified element path are returned. Each element in the path is prefixed
46     with the literal '!' character when the element contains no "target"
47     attribute (See THE TARGET ATTRIBUTE below).
49     If only a single element is specified and without the literal '!' prefix,
50     both the literal element tree and the element target (if any) tree will be
51     shown.
54 REALPATH [!]element[<TAB>[!]element[...]]
55     Resolves all "target" attributes of the specified element path and returns
56     the result with a data response.
59 STORE [!]element[[<TAB>[!]element[...]]<TAB>[content]]
60     Creates a new element tree or modifies the content of an existing element
61     path. If only a single element is specified, a new root element is
62     created. Otherwise, elements are TAB delimited and the content will be set
63     to the last TAB delimited argument. If no content is specified after the
64     last TAB then the content for the last specified element will be removed
65     or the content will be empty when creating a new element.
66     
67     The only restriction of element names is that they not begin with a
68     punctuation character (the literal '!' character is an exception) or digit
69     and not contain any whitespace. There is no whitespace between the TAB
70     delimited elements. It is recommended that the value be base 64 encoded to
71     prevent libXML and pwmd parsing errors.
72     
73     PWMD reads the element path from the client via the Assuan INQUIRE
74     protocol response. The STORE command is sent by itself without arguments,
75     then the server responds with INQUIRE. The client then sends the element
76     path prefixed by a "D " data response. When finished, the client
77     sends "END" on an empty line. This is needed so an element path and value
78     can be more than 1000 bytes long, the Assuan protocol line limit.
81 DELETE [!]element[<TAB>[!]element[...]]
82     Removes an element tree from the specified element path.
85 GET [!]element[<TAB>[!]element[...]]
86     Retrieves the content of the specified element path. The data is returned
87     with a data response.
90 ATTR SET|GET|DELETE|LIST [<attribute>] [!]<arg1> [!][arg2]
91     ATTR SET attribute [!]element[<TAB>[!]element[...]] attribute_value
92         Stores or updates an attribute value to an element path.
94     ATTR DELETE attribute [!]element[<TAB>[!]element[...]]
95         Removes an attribute from an element path.
97     ATTR LIST [!]element[<TAB>[!]element[...]]
98         Gets a list of attributes from an element path.
100     ATTR GET attribute [!]element[<TAB>[!]element[...]]
101         Gets the value of an attribute from an element path.
103     The "name" attribute (case sensitive) cannot be removed with ATTR DELETE
104     if the element path is only a root element. Although it can be SET to
105     change the root element name.
107     Also see THE TARGET ATTRIBUTE below.
110 DUMP
111     Shows the in memory XML document with indenting.
114 GETCONFIG <parameter>
115     Returns the value of a pwmd configuration variable with a data response.
116     If no file is open then the default value will be returned. The "key" and
117     "key_file" variables are ignored.
121     Closes the connection. Use the SAVE command before this command as any
122     changes will be lost.
125 If a command fails then the ERR response is returned followed by a protocol
126 error code and description. See src/pwmd_error.h or libpwmd/libpwmd.h for
127 error codes.
130 STATUS MESSAGES
131 ---------------
132 Some commands send a status message to the client when successful or as a
133 progress indicator. Status messages begin with a KEYWORD (see below) followed
134 by the status description. What messages are sent, and how often, depend on
135 configuration settings:
137     COMMAND             KEYWORD
138     --------------------------------
139     OPEN                DECRYPT
140                         DECOMPRESS
141                         CACHE
142                         LOCKED
144     SAVE                COMPRESS
145                         ENCRYPT
146                         CACHE
147                         LOCKED
149     CLEARCACHE          CACHE
150                         LOCKED
152     CACHETIMEOUT        CACHE
153                         LOCKED
155     ISCACHED            LOCKED
158     KEYWORD             OUTPUT FORMAT
159     ---------------------------------
160     CACHE               <slots used> <slots available>
161     ENCRYPT             <iterations so far>
162     DECRYPT             <iterations so far>
163     COMPRESS            <bytes so far> <total bytes>
164     DECOMPRESS          <bytes so far> <total bytes>
165     LOCKED              When another thread owns the file/key cache lock,
166                         this is sent once and the thread blocks until the
167                         lock can be obtained and the command completes.
170 THE TARGET ATTRIBUTE
171 --------------------
172 There is a special attribute "target" (case sensitive) that can be set with
173 ATTR SET. The value of this attribute is an element path somewhere else in the
174 XML document:
176 ATTR SET target [!]element[<TAB>[!]element[..]] [!]element[<TAB>[!]element[..]]
177                    arg1^^^^^^^^^^^^^^^^^^^^^^^^    arg2^^^^^^^^^^^^^^^^^^^^^^^^
179 If the element path of the "target" attribute (arg1) doesn't exist, it is
180 created. This is the only time the ATTR command will create elements.
182 When a protocol command requests <arg1> as the element path, the remaining
183 elements after the element with the "target" attribute will be appended to
184 <arg2>. This is useful if you have elements that share the same data. If the
185 target is modified, the other elements "pointing" to the target will have the
186 same content. To get the real or literal element and ignore any "target"
187 attributes, prefix an element with a '!' character. Here's an example:
189     C> STORE
190     S> INQUIRE STORE
191     C> D host1<TAB>username<TAB>original username
192     C> END
193     S> OK
194     C> STORE
195     S> INQUIRE STORE
196     C> D host2<TAB>smtp<TAB>username<TAB>someuser
197     C> END
198     S> OK
199     C> ATTR SET target host1<TAB>username host2<TAB>smtp<TAB>username
200     S> OK
202 Now host1's "target" attribute will be used:
204     C> GET host1<TAB>username
205     S> D someuser
206     S> OK
208 If you want host1's username, prefix the element of the "target" attribute
209 with a '!':
211     C> GET host1<TAB>!username
212     S> D original username
213     S> OK
215 The target value (arg2) element can also have a "target" attribute:
217     C> ATTR SET target new_account host1
218     S> OK
219     C> GET new_account<TAB>username
220     S> D someuser
221     S> OK
223 The value of the "target" attribute may also be prefixed with a '!' to set the
224 target to the actual element path and not a target of the element path:
226     C> ATTR DELETE target !new_account
227     S> OK
228     C> ATTR SET target new_account<TAB>username host1<TAB>!username
229     S> OK
230     C> GET new_account<TAB>username
231     S> D original username
232     S> OK
234 The "target" attribute is considered for all commands that support an element
235 path. If the target element has been renamed or deleted afterwards, the
236 command will fail.
238 Clients should be careful of creating target loops. See the "recursion_depth"
239 configuration parameter for details.
242 XML DOCUMENT STRUCTURE
243 ----------------------
244 When importing an XML data file with the -I command line option, the document
245 should have the following DTD:
247     <?xml version="1.0"?>
248     <!DOCTYPE accounts [
249     <!ELEMENT accounts (account*)>
250     <!ATTLIST account name CDATA #REQUIRED>
251     ]>
253 "accounts" is the document root element while each root element mentioned in
254 the protocol commands use the "account" element. So if you have a root element
255 "isp" to be shown with the LIST command ("LIST isp"), the document structure
256 looks like this:
258     <accounts>
259         <account name="isp">
260         [...]
261         </account>
262     </accounts>
264 The DUMP command can be useful to show the current document structure.
267 Questions, bugs or feature requests can be sent to Ben Kibbey
268 <bjk@luxsci.net>.