Restore the working directory after connecting to the socket.
[pwmd.git] / PROTOCOL
blobfa4d8ef0ba51c4d5e436745c8e92fcafc099679a
1 The data is stored in an AES-256-CBC encrypted XML file. A client connects to
2 the server and issues commands that manipulate the data. Through the use of
3 a file cache and shared memory passwords do not need to be issued for each
4 file each time a client connects.
6 The server uses a simple protocol to communicate with a client. All non-data
7 responses are prefixed by a server response code followed by a space followed
8 by an (optional) description followed by a newline character. There are three
9 non-data related response codes: NFO for informational messages, ERR for error
10 messages and OK if the command succeeded.
12 A data response is prefixed with a BEGIN response code followed by a space
13 then an integer specifying the number of following data bytes then a newline
14 character. After all of the bytes have been sent a newline character then an
15 OK response code then another newline will be sent.
17 Protocol commands:
19 OPEN <filename> [<key>]
20     Opens <filename> using <key>. If file is not found on the filesystem, then
21     a new file is created. If the file is found, it is looked for in the file
22     cache for an existing key. If found, the existing key will be used for
23     decryption. If the cached key fails then the <key>, if specified, will be
24     tried.
27 SAVE [<key>]
28     Encrypts and writes any changes to the file to disk. If <key> is not
29     specified then the currently cached key will be used. If the file is a new
30     file which hasn't yet been saved, <key> is required.
33 CACHE CLEARALL | CLEAR <filename> | ISCACHED <filename> | 
34       TIMEOUT <seconds> <filename>
35     CLEARALL - Remove all files from the cache. This will require a key for
36                the next OPEN or SAVE command for existing files.
38     CLEAR    - Like CLEARALL but only for the specified file.
40     ISCACHED - A response code of OK will be returned if the specified file is
41                in the file cache. If not in the cache or the file doesn't
42                exist on the filesystem or has a size of 0, an ERR response is
43                returned.
44     
45     TIMEOUT  - Specify the number of seconds the specified file will be
46                cached. -1 will keep the cache entry forever, 0 will require
47                the key each time the file is OPEN'ed or SAVE'd.
49     A file doesn't need to be opened to use this command.
52 LIST [element[<TAB>element[...]]]
53     If no element path is given, then a list of accounts is returned with a
54     BEGIN repsonse code. If given, then the element tree for the specified
55     element path is returned. See the ATTR command and the VALUE attribute.
58 STORE account[<TAB>element[<TAB>element[...]]<TAB>value]
59     Stores an element tree into the existing <account>, creates a new
60     <account> tree or modifies the value for an existing element path. If no
61     elements are specifed an empty account is created. Otherwise, elements are
62     TAB deliminated and the value will be the last TAB deliminated argument.
63     The only restriction of element names is that they not contain any
64     whitespace. There is no whitespace between the TAB deliminated element
65     arguments. It is recommended that the value be base 64 encoded to prevent
66     libXML and pwmd parsing errors.
67     
69 DELETE account[<TAB>element[...]]
70     Removes an element tree from <account> or the entire <account> if no
71     elements are given.
74 GET <account><TAB>element[<TAB>element[...]]
75     Retrieves the value for the specified element tree. See the ATTR command
76     and VALUE attribute below. The data is returned with the BEGIN response
77     code.
80 ATTR SET|GET|DELETE|LIST [<attribute>] <arg1> [arg2]
81     ATTR SET attribute account[<TAB>element[...]] attribute_value
82     ATTR DELETE attribute account[<TAB>element[...]]
83     ATTR LIST account[<TAB>element[...]]
84     ATTR GET attribute account[<TAB>element[...]]
86     The NAME attribute cannot be DELETE'd if the element path is only the
87     account name. Although it can be SET to change the account name.
89     There is one other special attribute which is TARGET. This is like a
90     "pointer" that points to another element in the document:
92     ATTR SET TARGET account[<TAB>element[...]] account[<TAB>element[...]]
94     Then the GET and LIST protocol commands for <arg1> would show the value of
95     <arg2>. Note that if <arg1> has both a TARGET attribute and an element
96     value, then only the TARGET attribute will be used in other protocol
97     commands. If the target has been renamed or deleted afterwards then the
98     GET protocol command will fail and the LIST protocol command will silently
99     ignore the target.
102 HELP [<command>]
103     Shows protocol command help for <command> or shows available commands if
104     <command> is not specified. A file doesn't need to be opened to use this
105     comand.
108 DUMP
109     Show the in memory document. Useful for pruning empty elements which
110     aren't shown with the LIST command.
113 QUIT
114     Closes the connection. Use the SAVE command before this command as any
115     changes will be lost.
118 If a command fails then the ERR response is returned followed by a protocol
119 error code and description. See src/pwmd_error.h or libpwmd/libpwmd.h for
120 error codes.
122 Ben Kibbey <bjk@luxsci.net>