Fixed showing the wrong function when an error occurred in pwmc.
[libpwmd.git] / libpwmd.3.in
blob250bed886a0a43e962619002c6f5056a5f2df3f1
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  02110-1301  USA
14 .de URL
15 \\$2 \(laURL: \\$1 \(ra\\$3
17 .if \n[.g] .mso www.tmac
18 .TH LIBPWMD 3 "21 Jun 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_assuan_ctx(pwm_t *" pwm ", assuan_context_t *" ctx ", int *" fd ");
29 .BI "gpg_error_t pwmd_pending_line(pwm_t *" pwm ", char **" line ", size_t *" len ");
30 .BI "gpg_error_t pwmd_setopt(pwm_t *" pwm ", pwmd_option_t " opt ", ...);"
31 .BI "gpg_error_t pwmd_open(pwm_t *" pwm ", const char *" filename ");"
32 .BI "int pwmd_open_nb(pwm_t *" pwm ", gpg_error_t *" error ", const char *" filename ", int " timeout ");"
33 .BI "gpg_error_t pwmd_open_nb_finalize(pwm_t *" pwm ", pwmd_nb_status_t *" status ");"
34 .BI "gpg_error_t pwmd_open_async(pwm_t *" pwm ", const char *" filename ");"
35 .BI "int pwmd_open_nb(pwm_t *" pwm ", gpg_error_t *" error ", const char *" filename ", int " timeout ");"
36 .BI "gpg_error_t pwmd_command(pwm_t *" pwm ", char **" result ", const char *" cmd ", " ... ");"
37 .BI "void pwmd_free_result(void *" result ");"
38 .BI "gpg_error_t pwmd_inquire(pwm_t *" pwm ", const char *" cmd ", pwmd_inquire_fn " func ", void *" data ");"
39 .BI "gpg_error_t pwmd_save(pwm_t *" pwm ");"
40 .BI "int pwmd_save_nb(pwm_t *" pwm ", gpg_error_t *" error ");"
41 .BI "gpg_error_t pwmd_save_nb_finalize(pwm_t *" pwm ", pwmd_nb_status_t *" status ");"
42 .BI "gpg_error_t pwmd_save_async(pwm_t *" pwm ");"
43 .BI "pwmd_async_t pwmd_process(pwm_t *" pwm ", gpg_error_t *" error ");"
44 .BI "gpg_error_t pwmd_finalize(pwm_t *" pwm ");"
45 .BI "gpg_error_t pwmd_terminate_pinentry(pwm_t *" pwm ");"
46 .BI "void pwmd_close(pwm_t *" pwm ");"
47 .BI "const char *pwmd_strerror(gpg_error_t " error ");"
49 .BI "typedef int (*" pwmd_status_fn ")(void *" data ", const char *" line ");"
50 .BI "typedef char *(*" pwmd_password_fn ")(pwm_t *" pwm ", void *" data ");"
51 .BI "typedef gpg_error_t (*" pwmd_inquire_fn ")(void *" data ", const char *" keyword ", gpg_error_t " rc ", char **" result ", size_t *" len ");"
52 .fi
53 .SH DESCRIPTION
54 .B libpwmd
55 is an library making it easy for applications to use
56 .BR pwmd (1).
58 .TP
59 .BI "gpg_error_t pwmd_init(void);"
60 Initializes \fBlibpwmd\fP, \fBlibassuan\fP, \fBlibgpg-error\fP and
61 internationalization. Be sure to call this before using the other functions.
62 If your application uses
63 .BR gettext(3)
64 be sure to call
65 .BR setlocale(3)
66 and
67 .BR textdomain(3)
68 before calling this function.
70 .TP
71 .BI "pwm_t *pwmd_connect(const char *" socket ", gpg_error_t *" error ");"
72 Connects to the specified \fIsocket\fP. If \fIsocket\fP is NULL then a default
73 of \fI~/.pwmd/socket\fP will be used. If there is an error while connecting
74 \fIerror\fP is set to the error code of the failed function and NULL is
75 returned. When successful a handle is returned for use with the other library
76 functions.
78 .TP
79 .BI "gpg_error_t pwmd_assuan_ctx(pwm_t *" pwm ", assuan_context_t *" ctx ", int *" fd ");
80 Sets \fIctx\fP to the assuan context associated with the handle \fIpwm\fP and
81 \fIfd\fP to the socket file descriptor. Returns \fB0\fP on success or an error
82 code.
84 .TP
85 .BI "gpg_error_t pwmd_pending_line(pwm_t *" pwm ", char **" line ", size_t *" len ");
86 This is a wrapper around \fBassuan_pending_line\fP() and
87 \fBassuan_read_line\fP(). Returns \fB0\fP and sets \fIline\fP to the content
88 and \fIlen\fP to the content length if there was a pending line. Or returns
89 \fBGPG_ERR_NO_DATA\fP if there was none or any error from
90 \fBassuan_read_line\fP().
92 .TP
93 .BI "gpg_error_t pwmd_setopt(pwm_t *" pwm ", pwmd_option_t " opt ", ...);"
94 Set the library option \fIopt\fP to the value of the next argument. Returns 0
95 on success or an error code. \fIopt\fP is one of the following:
96 .RS
97 .TP
98 .B PWMD_OPTION_PASSWORD_FUNC
99 Specifies a function to use to get a password. The next argument should be of
100 type \fIpwmd_password_fn\fP. The function should return a \fIchar
101 *\fP string which is the password or NULL if there is an
102 error.
104 .B PWMD_OPTION_PASSWORD_DATA
105 A user data pointer passed to the password function.
107 .B PWMD_OPTION_PINENTRY_TRIES
108 The next argument if type \fIint\fP specifies the number of invalid password
109 tries before
110 .BR pinentry (1)
111 gives up. Only \fBpwmd_open\fP() and \fBpwmd_open_nb\fP() will use this
112 option. \fBpwmd_save\fP() and \fBpwmd_save_nb\fP() will continue to confirm a
113 password until either a match is entered or Cancel is selected.
115 .B PWMD_OPTION_PINENTRY_TTY
117 .B PWMD_OPTION_PINENTRY_TERM
119 .B PWMD_OPTION_PINENTRY_DISPLAY
121 .B PWMD_OPTION_PINENTRY_PATH
122 Sets the
123 .BR pinentry (1)
124 command line options. The next argument should be of type \fIchar *\fP. If not
125 set, then the current DISPLAY, if set, or tty will be used.
127 .B PWMD_OPTION_PINENTRY
128 Whether to use 
129 .BR pinentry (1)
130 to obtain the password when opening and saving a file on the server. The
131 following argument is an \fIint\fP and is \fI1\fP to enable
132 .BR pinentry (1)
133 use, and \fI0\fP to use the password which is set with
134 \fBPWMD_OPTION_PASSWORD\fP or \fBPWMD_OPTION_PASSWORD_FUNC\fP. When \fI1\fP,
135 .BR pwmd (1)
136 won't use pinentry but return an error instead. This option should not be set
137 when using \fBpwmd_open_async\fP() or \fBpwmd_save_async\fP().
140 If the file \fI~/.pwmd/pinentry.conf\fP exists then values for the above settings will
141 be read from this file. The format of the file is one NAME=VALUE per line where
142 NAME is one of TTYNAME, TTYTYPE, DISPLAY or PATH. The value for an existing
143 setting will be updated to the value contained in the file. Note that the
144 server can also use this file for its
145 .BR pinentry (1)
146 settings.
149 .B PWMD_OPTION_PINENTRY_TITLE
151 .B PWMD_OPTION_PINENTRY_DESC
153 .B PWMD_OPTION_PINENTRY_PROMPT
154 Sets the strings used in the 
155 .BR pinentry (1)
156 program.
157 The next argument is of type \fIchar *\fP. If not defined then a default will
158 be used.
160 .B PWMD_OPTION_PASSWORD
161 Sets the password to use for opening and saving a file when
162 \fBPWMD_OPTION_PINENTRY\fP is \fI0\fP. The following argument is the password
163 and is of type \fIchar *\fP.
165 .B PWMD_OPTION_STATUS_FUNC
167 .B PWMD_OPTION_STATUS_DATA
168 The callback of type \fBpwmd_status_fn\fP to be called when 
169 .BR pwmd (1)
170 sends a status message. This function should return \fB0\fP on success or a
171 \fBgpg_error_t\fP on failure. The data passed to the function can be set with
172 \fBPWMD_OPTION_STATUS_DATA\fP. Status message lines are prefixed with a
173 keyword followed by a space then the message. Read the \fBlibassuan\fP
174 documentation for more information. 
178 .BI "gpg_error_t pwmd_open(pwm_t *" pwm ", const char *" filename ");"
179 Opens the specified \fIfilename\fP on the server. The password for the file is
180 gotten from one of the methods specified with \fBpwmd_setopt\fP().
181 An error code is returned on error or \fB0\fP on success.
184 .BI "int pwmd_open_nb(pwm_t *" pwm ", gpg_error_t *" error ", const char *" filename ", int " timeout ");"
185 This is a nonblocking way of obtaining the password from
186 .BR pinentry (1)
187 when opening a file on the server. When successful, it returns a file
188 descriptor that
189 .BR select (2)
190 can use. When ready,
191 .BR read (2)
192 should read a \fIpwmd_nb_status_t\fP and then call
193 \fBpwmd_open_nb_finalize\fP() to update the handle. If there is an error,
194 \fB-1\fP is returned and \fIerror\fP is set. If \fIfilename\fP is already
195 cached on the server or doesn't exist on the filesystem and the open
196 succeeded, \fB-2\fP is returned. The \fItimeout\fP argument is the number of
197 seconds until the pinentry process will terminate. If \fB0\fP, the default, no
198 timeout will be used. Note that \fBPWMD_OPTION_PINENTRY\fP must be set and
199 that if a timeout is specified then the child process will modify it's
200 \fBSIGALRM\fP handler.
203 .BI "gpg_error_t pwmd_open_nb_finalize(pwm_t *" pwm ", pwmd_nb_status_t *" status ");"
204 For use with \fBpwmd_open_nb\fP(); it updates the handle \fIpwm\fP and closes
205 the file descriptor. This should be called right after the successful
206 .BR read (2)
207 of \fIstatus\fP from the file descriptor returned by \fBpwmd_open_nb\fP(). If
208 there was a protocol or
209 .BR pinentry (1)
210 error, an error code is returned. Otherwise \fB0\fP is returned.
213 .BI "gpg_error_t pwmd_open_async(pwm_t *" pwm ", const char *" filename ");"
214 This is the preferred method of opening a file in a non-blocking way. Instead
215 of \fBlibpwmd\fP forking and executing \fBpinentry\fP,
216 .BR pwmd (1)
217 will use its \fBpinentry\fP method. When successful \fB0\fP is returned and
218 \fBpwmd_process()\fP should be called until the command completes. Note that
219 this method doesn't support \fBPWMD_OPTION_PINENTRY_TRIES\fP so you should
220 implement this yourself.
223 .BI "gpg_error_t pwmd_command(pwm_t *" pwm ", char **" result ", const char *" cmd ", " ... ");"
224 Sends a protocol command to the server. The function returns \fB0\fP
225 when successful and stores the result of the command format string \fIcmd\fP
226 to \fIresult\fP. The result should be free'd with \fBpwmd_free_result\fP().
227 Protocol commands that don't have a result will set \fIresult\fP to NULL. If
228 an error occurs then an error code is returned. Note: the BYE protocol
229 command should not be sent here. Use \fBpwmd_close\fP() instead. For commands
230 that utilize a server INQUIRE response (i.e., "STORE"), you must use
231 \fBpwmd_inquire\fP() and not this function.
234 .BI "void pwmd_free_result(void *" result ");"
235 Deallocates the memory of \fBpwmd_command\fP() result. It is important to use
236 this function because
237 .B libpwmd
238 not only keeps track of all allocated memory used by other
239 .B libpwmd
240 functions, but also clears the memory contents for better security. Don't use
241 this to free your own allocated memory though.
244 .BI "gpg_error_t pwmd_inquire(pwm_t *" pwm ", const char *" cmd ", pwmd_inquire_fn " func ", void *" data ");"
245 Commands which use an INQUIRE to send data (i.e., STORE) should use this
246 function and not \fBpwmd_command\fP(). \fIcmd\fP is the command to send and is
247 also the \fIkeyword\fP argument to the specified callback function \fIfunc\fP.
248 \fIdata\fP is user data passed to the callback function. Returns 0 on success
249 or an error code which may have been returned from the callback function.
252 The callback function should return \fBGPG_ERR_EOF\fP when there is no more
253 data to be sent or to finish sending \fIresult\fP, if not NULL, and end the
254 INQUIRE. Or return \fB0\fP if there is more data to be sent, or an error code
255 to terminate the INQUIRE.
259 .BI "gpg_error_t pwmd_save(pwm_t *" pwm ");"
260 Saves the changes to the file associated with the handle \fIpwm\fP. If not
261 called before \fBpwmd_close\fP() then any changes will be lost. If an error
262 occurs then an error code is returned. Otherwise \fB0\fP is returned.
265 .BI "int pwmd_save_nb(pwm_t *" pwm ", gpg_error_t *" error ");"
266 This is a nonblocking way of obtaining the password from
267 .BR pinentry (1)
268 when saving an opened file. When successful, a file descriptor is returned
269 that
270 .BR select (2)
271 can use. When ready
272 .BR read (2)
273 should read a \fIpwmd_nb_status_t\fP and then call
274 \fBpwmd_save_nb_finalize\fP() to update the handle. If there was an error,
275 \fB-1\fP is returned and \fIerror\fP is set. If the file is cached on the
276 server and the save succeeded, \fB-2\fP is returned. Note that
277 \fBPWMD_OPTION_PINENTRY\fP must be set.
280 .BI "gpg_error_t pwmd_save_nb_finalize(pwm_t *" pwm ", pwmd_nb_status_t *" status ");"
281 For use with \fBpwmd_save_nb\fP(); it updates the handle \fIpwm\fP and closes
282 the file descriptor. This should be called right after the successful
283 .BR read (2)
284 of \fIstatus\fP from the file descriptor returned by \fBpwmd_save_nb\fP(). If
285 there was a protocol or
286 .BR pinentry (1)
287 error, an error code is returned. Otherwise \fB0\fP is returned.
290 .BI "gpg_error_t pwmd_save_async(pwm_t *" pwm ");"
291 This is the preferred method of saving a file in a non-blocking way. Instead
292 of \fBlibpwmd\fP executing \fBpinentry\fP after a fork(),
293 .BR pwmd (1)
294 will use its \fBpinentry\fP method. When successful \fB0\fP is returned and
295 \fBpwmd_process()\fP should be called until the command finishes.
298 .BI "pwmd_async_t pwmd_process(pwm_t *" pwm ", gpg_error_t *" error ");"
299 For use with the asynchronous functions \fBpwmd_open_async()\fP and
300 \fBpwmd_save_async\fP(). This function returns \fBASYNC_PROCESS\fP when the
301 command is still running and should be called again until \fBASYNC_DONE\fP is
302 returned. When \fBASYNC_DONE\fP is returned, \fIerror\fP should be tested and
303 \fBpwmd_finalize()\fP should be called.
306 .BI "gpg_error_t pwmd_finalize(pwm_t *" pwm ");"
307 After \fBpwmd_process()\fP returns \fBASYNC_DONE\fP, this function should be
308 called even if an error occured to reset the \fIpwm\fP handle for the next
309 asynchronous command.
312 .BI "gpg_error_t pwmd_terminate_pinentry(pwm_t *" pwm ");"
313 Terminates a
314 .BR pinentry (1)
315 process associated with the handle \fIpwm\fP. This may be useful if your
316 application wants to use a timeout for password entry but doesn't use
317 \fBpwmd_open_nb\fP(). Returns \fB0\fP on success or an error code on failure.
320 .BI "void pwmd_close(pwm_t *" pwm ");"
321 Closes the server connection and free's resources used by the handle
322 \fIpwm\fP.
325 .BI "const char *pwmd_strerror(gpg_error_t " error ");"
326 Returns a string describing the error code \fIerror\fP which was set from one
327 of the above functions.
329 .SH FILES
331 .B ~/.pwmd/socket
332 Default connecting socket.
334 .B ~/.pwmd/pinentry.conf
335 Optional file containing pinentry settings.
337 .B @prefix@/lib/pkgconfig/libpwmd.pc
339 .BR pkg-config (1)
340 metadata file.
342 .B @prefix@/include/libpwmd.h
343 Installed location of header file.
345 .B @pinentry@
346 Default location of the
347 .BR pinentry (1)
348 binary.
350 .SH AUTHOR
351 Ben Kibbey <bjk@luxsci.net>
353 .URL "http://bjk.sourceforge.net/pwmd/" "PWMD Homepage" .
355 .SH "SEE ALSO"
356 .BR pwmd (1),
357 .BR pinentry (1),
358 .BR pkg-config (1)
360 And the \fBlibassuan\fP
361 .BR info (1)
362 documentation.