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.
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.
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
15 \\$2 \(laURL: \\$1 \(ra\\$3
17 .if \n[.g] .mso www.tmac
18 .TH LIBPWMD 3 "27 Sep 2008" "Password Manager Daemon Library" "Password Manager Daemon Library"
21 libpwmd \- pwmd client interface library
24 .B #include <libpwmd.h>
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 "gpg_error_t pwmd_command(pwm_t *" pwm ", char **" result ", const char *" cmd ", " ... ");"
36 .BI "void pwmd_free_result(void *" result ");"
37 .BI "gpg_error_t pwmd_inquire(pwm_t *" pwm ", const char *" cmd ", pwmd_inquire_fn " func ", void *" data ");"
38 .BI "gpg_error_t pwmd_save(pwm_t *" pwm ");"
39 .BI "int pwmd_save_nb(pwm_t *" pwm ", gpg_error_t *" error ");"
40 .BI "gpg_error_t pwmd_save_nb_finalize(pwm_t *" pwm ", pwmd_nb_status_t *" status ");"
41 .BI "gpg_error_t pwmd_save_async(pwm_t *" pwm ");"
42 .BI "pwmd_async_t pwmd_process(pwm_t *" pwm ", gpg_error_t *" error ");"
43 .BI "gpg_error_t pwmd_finalize(pwm_t *" pwm ");"
44 .BI "gpg_error_t pwmd_terminate_pinentry(pwm_t *" pwm ");"
45 .BI "void pwmd_close(pwm_t *" pwm ");"
46 .BI "const char *pwmd_strerror(gpg_error_t " error ");"
48 .BI "typedef int (*" pwmd_status_fn ")(void *" data ", const char *" line ");"
49 .BI "typedef char *(*" pwmd_password_fn ")(pwm_t *" pwm ", void *" data ");"
50 .BI "typedef gpg_error_t (*" pwmd_inquire_fn ")(void *" data ", const char *" keyword ", gpg_error_t " rc ", char **" result ", size_t *" len ");"
54 is an library making it easy for applications to use
58 .BI "gpg_error_t pwmd_init(void);"
59 Initializes \fBlibpwmd\fP, \fBlibassuan\fP, \fBlibgpg-error\fP and
60 internationalization. Be sure to call this before using the other functions.
61 If your application uses
67 before calling this function.
70 .BI "pwm_t *pwmd_connect(const char *" socket ", gpg_error_t *" error ");"
71 Connects to the specified \fIsocket\fP. If \fIsocket\fP is NULL then a default
72 of \fI~/.pwmd/socket\fP will be used. If there is an error while connecting
73 then \fIerror\fP will be set to the error code of the failed function and NULL
74 will be returned. When successful a handle is returned for use with the other
78 .BI "gpg_error_t pwmd_assuan_ctx(pwm_t *" pwm ", assuan_context_t *" ctx ", int *" fd ");
79 Sets \fIctx\fP to the assuan context associated with the handle \fIpwm\fP and
80 \fIfd\fP to the socket file descriptor. Returns \fB0\fP on success or an error
84 .BI "gpg_error_t pwmd_pending_line(pwm_t *" pwm ", char **" line ", size_t *" len ");
85 This is a wrapper around \fBassuan_pending_line\fP() and
86 \fBassuan_read_line\fP(). Returns \fB0\fP and sets \fIline\fP to the content
87 and \fIlen\fP to the content length if there was a pending line or returns
88 \fBGPG_ERR_NO_DATA\fP if there was none. Or any error from
89 \fBassuan_read_line\fP().
92 .BI "gpg_error_t pwmd_setopt(pwm_t *" pwm ", pwmd_option_t " opt ", ...);"
93 Set the library option \fIopt\fP to the value of the next argument. Returns 0
94 on success or an error code. \fIopt\fP is one of the following:
97 .B PWMD_OPTION_PASSWORD_FUNC
98 Specifies a function to use to get a password. The next argument should be of
99 type \fIpwmd_password_fn\fP. The function should return a \fIchar
100 *\fP string which is the password or NULL if there was an error.
102 .B PWMD_OPTION_PASSWORD_DATA
103 A user data pointer passed to the password function.
105 .B PWMD_OPTION_PINENTRY_TRIES
106 The next argument if type \fIint\fP specifies the number of invalid password
109 gives up. Only \fBpwmd_open\fP(), \fBpwmd_open_async\fP() and
110 \fBpwmd_open_nb\fP() will use this option. \fBpwmd_save\fP(),
111 \fBpwmd_save_async\fP() and \fBpwmd_save_nb\fP() will continue to confirm a
112 password until either a match is entered or Cancel is selected.
114 .B PWMD_OPTION_PINENTRY_TTY
115 Sets the tty that pinentry will use to prompt for the passphrase. Note that
116 \fBPWMD_OPTION_PINENTRY_DISPLAY\fP has precedence if the \fBDISPLAY\fP
117 environment variable is set. The next argument should be of type \fIchar *\fP.
119 .B PWMD_OPTION_PINENTRY_TERM
120 The terminal type when \fBPWMD_OPTION_PINENTRY_TTY\fP is set. Be sure to set
121 this because ncurses will segfault if not. The next argument should be of type
124 .B PWMD_OPTION_PINENTRY_DISPLAY
125 An X11 hostname and display for pinentry to connect to. This will be the same
126 as the \fBDISPLAY\fP environment variable by default. The next argument should
127 be of type \fIchar *\fP.
129 .B PWMD_OPTION_PINENTRY_PATH
130 The full path to the pinentry binary. Only useful when \fBpwmd_open_nb\fP() or
131 \fBpwmd_save_nb\fP() are used. The next argument should be of type
132 \fIchar *\fP. The default is \fI@pinentry@\fP.
134 .B PWMD_OPTION_PINENTRY
137 to obtain the password when opening and saving a file on the server. The
138 following argument is an \fIint\fP and is \fI1\fP to enable
140 use, and \fI0\fP to use the password which is set with
141 \fBPWMD_OPTION_PASSWORD\fP or \fBPWMD_OPTION_PASSWORD_FUNC\fP. When \fI1\fP,
143 won't use pinentry but return an error instead. This option should not be set
144 when using \fBpwmd_open_async\fP() or \fBpwmd_save_async\fP().
147 If the file \fI~/.pwmd/pinentry.conf\fP exists then values for the above
148 settings will be read from this file. The format of the file is one NAME=VALUE
149 per line where NAME is one of TTYNAME, TTYTYPE, DISPLAY or PATH. The value for
150 an existing setting will be updated to the value contained in the file. Note
153 server can also use this file for its
158 .B PWMD_OPTION_PINENTRY_TITLE
160 .B PWMD_OPTION_PINENTRY_DESC
162 .B PWMD_OPTION_PINENTRY_PROMPT
163 Sets the strings used in the
166 The next argument is of type \fIchar *\fP. If not defined then a default will
169 .B PWMD_OPTION_PASSWORD
170 Sets the password to use for opening and saving a file when
171 \fBPWMD_OPTION_PINENTRY\fP is \fI0\fP. The following argument is the password
172 and is of type \fIchar *\fP.
174 .B PWMD_OPTION_STATUS_FUNC
176 .B PWMD_OPTION_STATUS_DATA
177 The callback of type \fBpwmd_status_fn\fP to be called when
179 sends a status message. This function should return \fB0\fP on success or a
180 \fBgpg_error_t\fP on failure. The data passed to the function can be set with
181 \fBPWMD_OPTION_STATUS_DATA\fP. Status message lines are prefixed with a
182 keyword followed by a space then the message. Read the \fBlibassuan\fP
183 documentation for more information.
187 .BI "gpg_error_t pwmd_open(pwm_t *" pwm ", const char *" filename ");"
188 Opens the specified \fIfilename\fP on the server. The password for the file is
189 gotten from one of the methods specified with \fBpwmd_setopt\fP().
190 An error code is returned on error or \fB0\fP on success.
193 .BI "int pwmd_open_nb(pwm_t *" pwm ", gpg_error_t *" error ", const char *" filename ", int " timeout ");"
194 This is a nonblocking way of obtaining the password from
196 when opening a file on the server. When successful, it returns a file
201 should read a \fIpwmd_nb_status_t\fP and then call
202 \fBpwmd_open_nb_finalize\fP() to update the handle. If there is an error,
203 \fB-1\fP is returned and \fIerror\fP is set. If \fIfilename\fP is already
204 cached on the server or doesn't exist on the filesystem and the open
205 succeeded, \fB-2\fP is returned. The \fItimeout\fP argument is the number of
206 seconds until the pinentry process will terminate. If \fB0\fP, the default, no
207 timeout will be used. Note that \fBPWMD_OPTION_PINENTRY\fP must be set and
208 that if a timeout is specified then the child process will modify it's
209 \fBSIGALRM\fP handler.
212 .BI "gpg_error_t pwmd_open_nb_finalize(pwm_t *" pwm ", pwmd_nb_status_t *" status ");"
213 For use with \fBpwmd_open_nb\fP(); it updates the handle \fIpwm\fP and closes
214 the file descriptor. This should be called right after the successful
216 of \fIstatus\fP from the file descriptor returned by \fBpwmd_open_nb\fP(). If
217 there was a protocol or
219 error, an error code is returned. Otherwise \fB0\fP is returned.
222 .BI "gpg_error_t pwmd_open_async(pwm_t *" pwm ", const char *" filename ");"
223 This is the preferred method of opening a file in a non-blocking way. Instead
224 of \fBlibpwmd\fP forking and executing \fBpinentry\fP,
226 will use its \fBpinentry\fP method. When successful \fB0\fP is returned and
227 \fBpwmd_process()\fP should be called until the command completes.
230 .BI "gpg_error_t pwmd_command(pwm_t *" pwm ", char **" result ", const char *" cmd ", " ... ");"
231 Sends a protocol command to the server. The function returns \fB0\fP
232 when successful and stores the result of the command format string \fIcmd\fP
233 to \fIresult\fP. The result should be free'd with \fBpwmd_free_result\fP().
234 Protocol commands that don't have a result will set \fIresult\fP to NULL. If
235 an error occurs then an error code is returned. Note: the BYE protocol
236 command should not be sent here. Use \fBpwmd_close\fP() instead. For commands
237 that utilize a server INQUIRE response (i.e., "STORE"), you must use
238 \fBpwmd_inquire\fP() and not this function.
241 .BI "void pwmd_free_result(void *" result ");"
242 Deallocates the memory of \fBpwmd_command\fP() result. It is important to use
243 this function because
245 not only keeps track of all allocated memory used by other
247 functions, but also clears the memory contents for better security. Don't use
248 this to free your own allocated memory though.
251 .BI "gpg_error_t pwmd_inquire(pwm_t *" pwm ", const char *" cmd ", pwmd_inquire_fn " func ", void *" data ");"
252 Commands which use an INQUIRE to send data (i.e., STORE) should use this
253 function and not \fBpwmd_command\fP(). \fIcmd\fP is the command to send and is
254 also the \fIkeyword\fP argument to the specified callback function \fIfunc\fP.
255 \fIdata\fP is user data passed to the callback function. Returns 0 on success
256 or an error code which may have been returned from the callback function.
259 The callback function should return \fBGPG_ERR_EOF\fP when there is no more
260 data to be sent or to finish sending \fIresult\fP, if not NULL, and end the
261 INQUIRE. Or return \fB0\fP if there is more data to be sent, or an error code
262 to terminate the INQUIRE.
266 .BI "gpg_error_t pwmd_save(pwm_t *" pwm ");"
267 Saves the changes to the file associated with the handle \fIpwm\fP. If not
268 called before \fBpwmd_close\fP() then any changes will be lost. If an error
269 occurs then an error code is returned. Otherwise \fB0\fP is returned.
272 .BI "int pwmd_save_nb(pwm_t *" pwm ", gpg_error_t *" error ");"
273 This is a nonblocking way of obtaining the password from
275 when saving an opened file. When successful, a file descriptor is returned
280 should read a \fIpwmd_nb_status_t\fP and then call
281 \fBpwmd_save_nb_finalize\fP() to update the handle. If there was an error,
282 \fB-1\fP is returned and \fIerror\fP is set. If the file is cached on the
283 server and the save succeeded, \fB-2\fP is returned. Note that
284 \fBPWMD_OPTION_PINENTRY\fP must be set.
287 .BI "gpg_error_t pwmd_save_nb_finalize(pwm_t *" pwm ", pwmd_nb_status_t *" status ");"
288 For use with \fBpwmd_save_nb\fP(); it updates the handle \fIpwm\fP and closes
289 the file descriptor. This should be called right after the successful
291 of \fIstatus\fP from the file descriptor returned by \fBpwmd_save_nb\fP(). If
292 there was a protocol or
294 error, an error code is returned. Otherwise \fB0\fP is returned.
297 .BI "gpg_error_t pwmd_save_async(pwm_t *" pwm ");"
298 This is the preferred method of saving a file in a non-blocking way. Instead
299 of \fBlibpwmd\fP executing \fBpinentry\fP after a fork(),
301 will use its \fBpinentry\fP method. When successful \fB0\fP is returned and
302 \fBpwmd_process()\fP should be called until the command finishes.
305 .BI "pwmd_async_t pwmd_process(pwm_t *" pwm ", gpg_error_t *" error ");"
306 For use with the asynchronous functions \fBpwmd_open_async()\fP and
307 \fBpwmd_save_async\fP(). This function returns \fBASYNC_PROCESS\fP when the
308 command is still running and should be called again until \fBASYNC_DONE\fP is
309 returned. When \fBASYNC_DONE\fP is returned, \fIerror\fP should be tested and
310 \fBpwmd_finalize()\fP should be called whether the command succeeded or not.
313 .BI "gpg_error_t pwmd_finalize(pwm_t *" pwm ");"
314 After \fBpwmd_process()\fP returns \fBASYNC_DONE\fP, this function should be
315 called even if an error occurred to reset the \fIpwm\fP handle for use with
316 the next asynchronous command.
319 .BI "gpg_error_t pwmd_terminate_pinentry(pwm_t *" pwm ");"
322 process associated with the handle \fIpwm\fP. This may be useful if your
323 application wants to use a timeout for password entry but doesn't use
324 \fBpwmd_open_nb\fP() or \fBpwmd_open_async\fP(). Returns \fB0\fP on success or
325 an error code on failure.
328 .BI "void pwmd_close(pwm_t *" pwm ");"
329 Closes the server connection and free's resources used by the handle
333 .BI "const char *pwmd_strerror(gpg_error_t " error ");"
334 Returns a string describing the error code \fIerror\fP which was set from one
335 of the above functions.
340 Default connecting socket.
342 .B ~/.pwmd/pinentry.conf
343 Optional file containing pinentry settings.
345 .B @prefix@/lib/pkgconfig/libpwmd.pc
350 .B @prefix@/include/libpwmd.h
351 Installed location of header file.
354 Default location of the
359 Ben Kibbey <bjk@luxsci.net>
361 .URL "http://bjk.sourceforge.net/pwmd/" "PWMD Homepage" .
368 And the \fBlibassuan\fP