Updated manual page.
[libpwmd.git] / libpwmd.3.in
blob65cdc467aa170b053ec007eb1f1c09bc7ced1cba
1 .\" This program is free software; you can redistribute it and/or modify
2 .\" it under the terms of the GNU General Public License as published by
3 .\" the Free Software Foundation; either version 2 of the License, or
4 .\" (at your option) any later version.
5 .\" 
6 .\" This program is distributed in the hope that it will be useful,
7 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
8 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9 .\" GNU General Public License for more details.
10 .\" 
11 .\" You should have received a copy of the GNU General Public License
12 .\" along with this program; if not, write to the Free Software
13 .\" Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
14 .de URL
15 \\$2 \(laURL: \\$1 \(ra\\$3
17 .if \n[.g] .mso www.tmac
18 .TH LIBPWMD 3 "27 Jan 2008" "Password Manager Daemon Library" "Password Manager Daemon Library"
19 .SH NAME
21 libpwmd \- pwmd client interface library
22 .SH SYNOPSIS
23 .nf
24 .B #include <libpwmd.h>
25 .sp
26 .BI "gpg_error_t pwmd_init(void);"
27 .BI "pwm_t *pwmd_connect(const char *" socket ", gpg_error_t *" error ");"
28 .BI "gpg_error_t pwmd_setopt(pwm_t *" pwm ", pwmd_option_t " opt ", ...);"
29 .BI "gpg_error_t pwmd_open(pwm_t *" pwm ", const char *" filename ");"
30 .BI "int pwmd_open_nb(pwm_t *" pwm ", gpg_error_t *" error ", const char *" filename ", int " timeout ");"
31 .BI "gpg_error_t pwmd_open_nb_finalize(pwm_t *" pwm ", pwmd_nb_status_t *" status ");"
32 .BI "gpg_error_t pwmd_open_async(pwm_t *" pwm ", const char *" filename ");"
33 .BI "int pwmd_open_nb(pwm_t *" pwm ", gpg_error_t *" error ", const char *" filename ", int " timeout ");"
34 .BI "gpg_error_t pwmd_command(pwm_t *" pwm ", char **" result ", const char *" cmd ", " ... ");"
35 .BI "void pwmd_free_result(void *" result ");"
36 .BI "gpg_error_t pwmd_inquire(pwm_t *" pwm ", const char *" cmd ", pwmd_inquire_fn " func ", void *" data ");"
37 .BI "gpg_error_t pwmd_save(pwm_t *" pwm ");"
38 .BI "int pwmd_save_nb(pwm_t *" pwm ", gpg_error_t *" error ");"
39 .BI "gpg_error_t pwmd_save_nb_finalize(pwm_t *" pwm ", pwmd_nb_status_t *" status ");"
40 .BI "gpg_error_t pwmd_save_async(pwm_t *" pwm ");"
41 .BI "pwmd_async_t pwmd_process(pwm_t *" pwm ", gpg_error_t *" error ");"
42 .BI "gpg_error_t pwmd_finalize(pwm_t *" pwm ");"
43 .BI "gpg_error_t pwmd_terminate_pinentry(pwm_t *" pwm ");"
44 .BI "void pwmd_close(pwm_t *" pwm ");"
45 .BI "const char *pwmd_strerror(gpg_error_t " error ");"
47 .BI "typedef int (*" pwmd_status_fn ")(void *" data ", const char *" line ");"
48 .BI "typedef char *(*" pwmd_password_fn ")(pwm_t *" pwm ", void *" data ");"
49 .BI "typedef gpg_error_t (*" pwmd_inquire_fn ")(void *" data ", const char *" keyword ", gpg_error_t " rc ", char **" result ", size_t *" len ");"
50 .fi
51 .SH DESCRIPTION
52 .B libpwmd
53 is an library making it easy for applications to use
54 .BR pwmd (1).
56 .TP
57 .BI "gpg_error_t pwmd_init(void);"
58 Initializes \fBlibpwmd\fP, \fBlibassuan\fP, \fBlibgpg-error\fP and
59 internationalization. Be sure to call this before using the other functions.
60 If your application uses
61 .BR gettext(3)
62 be sure to call
63 .BR setlocale(3)
64 and
65 .BR textdomain(3)
66 before calling this function.
68 .TP
69 .BI "pwm_t *pwmd_connect(const char *" socket ", gpg_error_t *" error ");"
70 Connects to the specified \fIsocket\fP. If \fIsocket\fP is NULL then a default
71 of \fI~/.pwmd/socket\fP will be used. If there is an error while connecting
72 \fIerror\fP is set to the error code of the failed function and NULL is
73 returned. When successful a handle is returned for use with the other library
74 functions.
76 .TP
77 .BI "gpg_error_t pwmd_setopt(pwm_t *" pwm ", pwmd_option_t " opt ", ...);"
78 Set the library option \fIopt\fP to the value of the next argument. Returns 0
79 on success or an error code. \fIopt\fP is one of the following:
80 .RS
81 .TP
82 .B PWMD_OPTION_PASSWORD_FUNC
83 Specifies a function to use to get a password. The next argument should be of
84 type \fIpwmd_password_fn\fP. The function should return a \fIchar
85 *\fP string which is the password or NULL if there is an
86 error.
87 .TP
88 .B PWMD_OPTION_PASSWORD_DATA
89 A user data pointer passed to the password function.
90 .TP
91 .B PWMD_OPTION_PINENTRY
92 Whether to use 
93 .BR pinentry (1)
94 to obtain the password when opening and saving a file on the server. The
95 following argument is an \fIint\fP and is \fI1\fP to enable
96 .BR pinentry (1)
97 use, and \fI0\fP to use the password which is set with
98 \fBPWMD_OPTION_PASSWORD\fP or \fBPWMD_OPTION_PASSWORD_FUNC\fP. When \fI1\fP,
99 .BR pwmd (1)
100 won't use pinentry but return an error instead.
102 .B PWMD_OPTION_PINENTRY_TRIES
103 The next argument if type \fIint\fP specifies the number of invalid password
104 tries before
105 .BR pinentry (1)
106 gives up. Only \fBpwmd_open\fP() and \fBpwmd_open_nb\fP() will use this
107 option. \fBpwmd_save\fP() and \fBpwmd_save_nb\fP() will continue to confirm a
108 password until either a match is entered or Cancel is selected.
110 .B PWMD_OPTION_PINENTRY_TTY
112 .B PWMD_OPTION_PINENTRY_TERM
114 .B PWMD_OPTION_PINENTRY_DISPLAY
116 .B PWMD_OPTION_PINENTRY_PATH
117 Sets the
118 .BR pinentry (1)
119 command line options. The next argument should be of type \fIchar *\fP. If not
120 set, then the current DISPLAY, if set, or tty will be used.
123 If the file \fI~/.pwmd/pinentry.conf\fP exists then values for the above settings will
124 be read from this file. The format of the file is one NAME=VALUE per line where
125 NAME is one of TTYNAME, TTYTYPE, DISPLAY or PATH. The value for an existing
126 setting will be updated to the value contained in the file. Note that the
127 server can also use this file for its
128 .BR pinentry (1)
129 settings.
132 .B PWMD_OPTION_PINENTRY_TITLE
134 .B PWMD_OPTION_PINENTRY_DESC
136 .B PWMD_OPTION_PINENTRY_PROMPT
137 Sets the strings used in the 
138 .BR pinentry (1)
139 program.
140 The next argument is of type \fIchar *\fP. If not defined then a default will
141 be used.
143 .B PWMD_OPTION_PASSWORD
144 Sets the password to use for opening and saving a file when
145 \fBPWMD_OPTION_PINENTRY\fP is \fI0\fP. The following argument is the password
146 and is of type \fIchar *\fP.
148 .B PWMD_OPTION_STATUS_FUNC
150 .B PWMD_OPTION_STATUS_DATA
151 The callback of type \fBpwmd_status_fn\fP to be called when 
152 .BR pwmd (1)
153 sends a status message. This function should return \fB0\fP on success or a
154 \fBgpg_error_t\fP on failure. The data passed to the function can be set with
155 \fBPWMD_OPTION_STATUS_DATA\fP. Status message lines are prefixed with a
156 keyword followed by a space then the message. Read the \fBlibassuan\fP
157 documentation for more information. 
161 .BI "gpg_error_t pwmd_open(pwm_t *" pwm ", const char *" filename ");"
162 Opens the specified \fIfilename\fP on the server. The password for the file is
163 gotten from one of the methods specified with \fBpwmd_setopt\fP().
164 An error code is returned on error or \fB0\fP on success.
167 .BI "int pwmd_open_nb(pwm_t *" pwm ", gpg_error_t *" error ", const char *" filename ", int " timeout ");"
168 This is a nonblocking way of obtaining the password from
169 .BR pinentry (1)
170 when opening a file on the server. When successful, it returns a file
171 descriptor that
172 .BR select (2)
173 can use. When ready,
174 .BR read (2)
175 should read a \fIpwmd_nb_status_t\fP and then call
176 \fBpwmd_open_nb_finalize\fP() to update the handle. If there is an error,
177 \fB-1\fP is returned and \fIerror\fP is set. If \fIfilename\fP is already
178 cached on the server or doesn't exist on the filesystem and the open
179 succeeded, \fB-2\fP is returned. The \fItimeout\fP argument is the number of
180 seconds until the pinentry process will terminate. If \fB0\fP, the default, no
181 timeout will be used. Note that \fBPWMD_OPTION_PINENTRY\fP must be set and
182 that if a timeout is specified then the child process will modify it's
183 \fBSIGALRM\fP handler.
186 .BI "gpg_error_t pwmd_open_nb_finalize(pwm_t *" pwm ", pwmd_nb_status_t *" status ");"
187 For use with \fBpwmd_open_nb\fP(); it updates the handle \fIpwm\fP and closes
188 the file descriptor. This should be called right after the successful
189 .BR read (2)
190 of \fIstatus\fP from the file descriptor returned by \fBpwmd_open_nb\fP(). If
191 there was a protocol or
192 .BR pinentry (1)
193 error, an error code is returned. Otherwise \fB0\fP is returned.
196 .BI "gpg_error_t pwmd_open_async(pwm_t *" pwm ", const char *" filename ");"
197 This is another method of opening a file in a non-blocking way. Instead of
198 \fBlibpwmd\fP executing \fBpinentry\fP after a fork(),
199 .BR pwmd (1)
200 will use its \fBpinentry\fP method. When successful \fB0\fP is returned and
201 \fBpwmd_process()\fP should be called until the command finishes.
204 .BI "gpg_error_t pwmd_command(pwm_t *" pwm ", char **" result ", const char *" cmd ", " ... ");"
205 Sends a protocol command to the server. The function returns \fB0\fP
206 when successful and stores the result of the command format string \fIcmd\fP
207 to \fIresult\fP. The result should be free'd with \fBpwmd_free_result\fP().
208 Protocol commands that don't have a result will set \fIresult\fP to NULL. If
209 an error occurs then an error code is returned. Note: the BYE protocol
210 command should not be sent here. Use \fBpwmd_close\fP() instead. For commands
211 that utilize a server INQUIRE response (i.e., "STORE"), you must use
212 \fBpwmd_inquire\fP() and not this function.
215 .BI "void pwmd_free_result(void *" result ");"
216 Deallocates the memory of \fBpwmd_command\fP() result. It is important to use
217 this function because
218 .B libpwmd
219 not only keeps track of all allocated memory used by other
220 .B libpwmd
221 functions, but also clears the memory contents for better security. Don't use
222 this to free your own allocated memory though.
225 .BI "gpg_error_t pwmd_inquire(pwm_t *" pwm ", const char *" cmd ", pwmd_inquire_fn " func ", void *" data ");"
226 Commands which use an INQUIRE to send data (i.e., STORE) should use this
227 function and not \fBpwmd_command\fP(). \fIcmd\fP is the command to send and is
228 also the \fIkeyword\fP argument to the specified callback function \fIfunc\fP.
229 \fIdata\fP is user data passed to the callback function. Returns 0 on success
230 or an error code which may have been returned from the callback function.
233 The callback function should return \fBGPG_ERR_EOF\fP when there is no more
234 data to be sent or to finish sending \fIresult\fP, if not NULL, and end the
235 INQUIRE. Or return \fB0\fP if there is more data to be sent, or an error code
236 to terminate the INQUIRE.
240 .BI "gpg_error_t pwmd_save(pwm_t *" pwm ");"
241 Saves the changes to the file associated with the handle \fIpwm\fP. If not
242 called before \fBpwmd_close\fP() then any changes will be lost. If an error
243 occurs then an error code is returned. Otherwise \fB0\fP is returned.
246 .BI "int pwmd_save_nb(pwm_t *" pwm ", gpg_error_t *" error ");"
247 This is a nonblocking way of obtaining the password from
248 .BR pinentry (1)
249 when saving an opened file. When successful, a file descriptor is returned
250 that
251 .BR select (2)
252 can use. When ready
253 .BR read (2)
254 should read a \fIpwmd_nb_status_t\fP and then call
255 \fBpwmd_save_nb_finalize\fP() to update the handle. If there was an error,
256 \fB-1\fP is returned and \fIerror\fP is set. If the file is cached on the
257 server and the save succeeded, \fB-2\fP is returned. Note that
258 \fBPWMD_OPTION_PINENTRY\fP must be set.
261 .BI "gpg_error_t pwmd_save_nb_finalize(pwm_t *" pwm ", pwmd_nb_status_t *" status ");"
262 For use with \fBpwmd_save_nb\fP(); it updates the handle \fIpwm\fP and closes
263 the file descriptor. This should be called right after the successful
264 .BR read (2)
265 of \fIstatus\fP from the file descriptor returned by \fBpwmd_save_nb\fP(). If
266 there was a protocol or
267 .BR pinentry (1)
268 error, an error code is returned. Otherwise \fB0\fP is returned.
271 .BI "gpg_error_t pwmd_save_async(pwm_t *" pwm ");"
272 This is another method of saving a file in a non-blocking way. Instead of
273 \fBlibpwmd\fP executing \fBpinentry\fP after a fork(),
274 .BR pwmd (1)
275 will use its \fBpinentry\fP method. When successful \fB0\fP is returned and
276 \fBpwmd_process()\fP should be called until the command finishes.
279 .BI "pwmd_async_t pwmd_process(pwm_t *" pwm ", gpg_error_t *" error ");"
280 For use with the asynchronous functions \fBpwmd_open_async()\fP and
281 \fBpwmd_save_async\fP(). This function returns \fBASYNC_PROCESS\fP when the
282 command is still running and should be called again until \fBASYNC_DONE\fP is
283 returned. When \fBASYNC_DONE\fP is returned, \fIerror\fP should be tested and
284 \fBpwmd_finalize()\fP should be called.
287 .BI "gpg_error_t pwmd_finalize(pwm_t *" pwm ");"
288 After \fBpwmd_process()\fP returns \fBASYNC_DONE\fP, this function should be
289 called even if an error occured to reset the \fIpwm\fP handle for the next
290 asynchronous command.
293 .BI "gpg_error_t pwmd_terminate_pinentry(pwm_t *" pwm ");"
294 Terminates a
295 .BR pinentry (1)
296 process associated with the handle \fIpwm\fP. This may be useful if your
297 application wants to use a timeout for password entry but doesn't use
298 \fBpwmd_open_nb\fP(). Returns \fB0\fP on success or an error code on failure.
301 .BI "void pwmd_close(pwm_t *" pwm ");"
302 Closes the server connection and free's resources used by the handle
303 \fIpwm\fP.
306 .BI "const char *pwmd_strerror(gpg_error_t " error ");"
307 Returns a string describing the error code \fIerror\fP which was set from one
308 of the above functions.
310 .SH FILES
312 .B ~/.pwmd/socket
313 Default connecting socket.
315 .B ~/.pwmd/pinentry.conf
316 Optional file containing pinentry settings.
318 .B @prefix@/lib/pkgconfig/libpwmd.pc
320 .BR pkg-config (1)
321 metadata file.
323 .B @prefix@/include/libpwmd.h
324 Installed location of header file.
326 .B @pinentry@
327 Default location of the
328 .BR pinentry (1)
329 binary.
331 .SH AUTHOR
332 Ben Kibbey <bjk@luxsci.net>
334 .URL "http://bjk.sourceforge.net/pwmd/" "PWMD Homepage" .
336 .SH "SEE ALSO"
337 .BR pwmd (1),
338 .BR pinentry (1),
339 .BR pkg-config (1)
341 And the \fBlibassuan\fP
342 .BR info (1)
343 documentation.