Version 5.0.0.
[libpwmd.git] / libpwmd.3.in
blob6eef84a49466fcd13b6e3d3b0b6761dd40a8bc46
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 "22 Dec 2007" "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_command(pwm_t *" pwm ", char **" result ", const char *" cmd ", " ... ");"
33 .BI "void pwmd_free_result(void *" result ");"
34 .BI "gpg_error_t pwmd_inquire(pwm_t *" pwm ", const char *" cmd ", pwmd_inquire_fn " func ", void *" data ");"
35 .BI "gpg_error_t pwmd_save(pwm_t *" pwm ");"
36 .BI "int pwmd_save_nb(pwm_t *" pwm ", gpg_error_t *" error ");"
37 .BI "gpg_error_t pwmd_save_nb_finalize(pwm_t *" pwm ", pwmd_nb_status_t *" status ");"
38 .BI "gpg_error_t pwmd_terminate_pinentry(pwm_t *" pwm ");"
39 .BI "void pwmd_close(pwm_t *" pwm ");"
40 .BI "const char *pwmd_strerror(gpg_error_t " error ");"
42 .BI "typedef int (*" pwmd_status_fn ")(void *" data ", const char *" line ");"
43 .BI "typedef char *(*" pwmd_password_fn ")(pwm_t *" pwm ", void *" data ");"
44 .BI "typedef gpg_error_t (*" pwmd_inquire_fn ")(void *" data ", const char *" keyword ", gpg_error_t " rc ", char **" result ", size_t *" len ");"
45 .fi
46 .SH DESCRIPTION
47 .B libpwmd
48 is an library making it easy for applications to use
49 .BR pwmd (1).
51 .TP
52 .BI "gpg_error_t pwmd_init(void);"
53 Initializes \fBlibpwmd\fP, \fBlibassuan\fP, \fBlibgpg-error\fP and
54 internationalization. Be sure to call this before using the other functions.
55 If your application uses
56 .BR gettext(3)
57 be sure to call
58 .BR setlocale(3)
59 and
60 .BR textdomain(3)
61 before calling this function.
63 .TP
64 .BI "pwm_t *pwmd_connect(const char *" socket ", gpg_error_t *" error ");"
65 Connects to the specified \fIsocket\fP. If \fIsocket\fP is NULL then a default
66 of \fI~/.pwmd/socket\fP will be used. If there is an error while connecting
67 \fIerror\fP is set to the error code of the failed function and NULL is
68 returned. When successful a handle is returned for use with the other library
69 functions.
71 .TP
72 .BI "gpg_error_t pwmd_setopt(pwm_t *" pwm ", pwmd_option_t " opt ", ...);"
73 Set the library option \fIopt\fP to the value of the next argument. Returns 0
74 on success or an error code. \fIopt\fP is one of the following:
75 .RS
76 .TP
77 .B PWMD_OPTION_PASSWORD_FUNC
78 Specifies a function to use to get a password. The next argument should be of
79 type \fIpwmd_password_fn\fP. The function should return a \fIchar
80 *\fP string which is the password or NULL if there is an
81 error.
82 .TP
83 .B PWMD_OPTION_PASSWORD_DATA
84 A user data pointer passed to the password function.
85 .TP
86 .B PWMD_OPTION_PINENTRY
87 Whether to use 
88 .BR pinentry (1)
89 to obtain the password when opening and saving a file on the server. The
90 following argument is an \fIint\fP and is \fI1\fP to enable
91 .BR pinentry (1)
92 use, and \fI0\fP to use the password which is set with
93 \fBPWMD_OPTION_PASSWORD\fP or \fBPWMD_OPTION_PASSWORD_FUNC\fP. When \fI1\fP,
94 .BR pwmd (1)
95 won't use pinentry but return an error instead.
96 .TP
97 .B PWMD_OPTION_PINENTRY_TRIES
98 The next argument if type \fIint\fP specifies the number of invalid password
99 tries before
100 .BR pinentry (1)
101 gives up. Only \fBpwmd_open\fP() and \fBpwmd_open_nb\fP() will use this
102 option. \fBpwmd_save\fP() and \fBpwmd_save_nb\fP() will continue to confirm a
103 password until either a match is entered or Cancel is selected.
105 .B PWMD_OPTION_PINENTRY_TTY
107 .B PWMD_OPTION_PINENTRY_TERM
109 .B PWMD_OPTION_PINENTRY_DISPLAY
111 .B PWMD_OPTION_PINENTRY_PATH
112 Sets the
113 .BR pinentry (1)
114 command line options. The next argument should be of type \fIchar *\fP. If not
115 set, then the current DISPLAY, if set, or tty will be used.
118 If the file \fI~/.pwmd/pinentry.conf\fP exists then values for the above settings will
119 be read from this file. The format of the file is one NAME=VALUE per line where
120 NAME is one of TTYNAME, TTYTYPE, DISPLAY or PATH. The value for an existing
121 setting will be updated to the value contained in the file. Note that the
122 server can also use this file for its
123 .BR pinentry (1)
124 settings.
127 .B PWMD_OPTION_PINENTRY_TITLE
129 .B PWMD_OPTION_PINENTRY_DESC
131 .B PWMD_OPTION_PINENTRY_PROMPT
132 Sets the strings used in the 
133 .BR pinentry (1)
134 program.
135 The next argument is of type \fIchar *\fP. If not defined then a default will
136 be used.
138 .B PWMD_OPTION_PASSWORD
139 Sets the password to use for opening and saving a file when
140 \fBPWMD_OPTION_PINENTRY\fP is \fI0\fP. The following argument is the password
141 and is of type \fIchar *\fP.
143 .B PWMD_OPTION_STATUS_FUNC
145 .B PWMD_OPTION_STATUS_DATA
146 The callback of type \fBpwmd_status_fn\fP to be called when 
147 .BR pwmd (1)
148 sends a status message. This function should return \fB0\fP on success or a
149 \fBgpg_error_t\fP on failure. The data passed to the function can be set with
150 \fBPWMD_OPTION_STATUS_DATA\fP. Status message lines are prefixed with a
151 keyword followed by a space then the message. Read the \fBlibassuan\fP
152 documentation for more information. 
156 .BI "gpg_error_t pwmd_open(pwm_t *" pwm ", const char *" filename ");"
157 Opens the specified \fIfilename\fP on the server. The password for the file is
158 gotten from one of the methods specified with \fBpwmd_setopt\fP().
159 An error code is returned on error or \fB0\fP on success.
162 .BI "int pwmd_open_nb(pwm_t *" pwm ", gpg_error_t *" error ", const char *" filename ", int " timeout ");"
163 This is a nonblocking way of obtaining the password from
164 .BR pinentry (1)
165 when opening a file on the server. When successful, it returns a file
166 descriptor that
167 .BR select (2)
168 can use. When ready,
169 .BR read (2)
170 should read a \fIpwmd_nb_status_t\fP and then call
171 \fBpwmd_open_nb_finalize\fP() to update the handle. If there is an error,
172 \fB-1\fP is returned and \fIerror\fP is set. If \fIfilename\fP is already
173 cached on the server or doesn't exist on the filesystem and the open
174 succeeded, \fB-2\fP is returned. The \fItimeout\fP argument is the number of
175 seconds until the pinentry process will terminate. If \fB0\fP, the default, no
176 timeout will be used. Note that \fBPWMD_OPTION_PINENTRY\fP must be set and
177 that if a timeout is specified then the child process will modify it's
178 \fBSIGALRM\fP handler.
181 .BI "gpg_error_t pwmd_open_nb_finalize(pwm_t *" pwm ", pwmd_nb_status_t *" status ");"
182 For use with \fBpwmd_open_nb\fP(); it updates the handle \fIpwm\fP and closes
183 the file descriptor. This should be called right after the successful
184 .BR read (2)
185 of \fIstatus\fP from the file descriptor returned by \fBpwmd_open_nb\fP(). If
186 there was a protocol or
187 .BR pinentry (1)
188 error, an error code is returned. Otherwise \fB0\fP is returned.
191 .BI "gpg_error_t pwmd_command(pwm_t *" pwm ", char **" result ", const char *" cmd ", " ... ");"
192 Sends a protocol command to the server. The function returns \fB0\fP
193 when successful and stores the result of the command format string \fIcmd\fP
194 to \fIresult\fP. The result should be free'd with \fBpwmd_free_result\fP().
195 Protocol commands that don't have a result will set \fIresult\fP to NULL. If
196 an error occurs then an error code is returned. Note: the BYE protocol
197 command should not be sent here. Use \fBpwmd_close\fP() instead. For commands
198 that utilize a server INQUIRE response (i.e., "STORE"), you must use
199 \fBpwmd_inquire\fP() and not this function.
202 .BI "void pwmd_free_result(void *" result ");"
203 Deallocates the memory of \fBpwmd_command\fP() result. It is important to use
204 this function because
205 .B libpwmd
206 not only keeps track of all allocated memory used by other
207 .B libpwmd
208 functions, but also clears the memory contents for better security. Don't use
209 this to free your own allocated memory though.
212 .BI "gpg_error_t pwmd_inquire(pwm_t *" pwm ", const char *" cmd ", pwmd_inquire_fn " func ", void *" data ");"
213 Commands which use an INQUIRE to send data (i.e., STORE) should use this
214 function and not \fBpwmd_command\fP(). \fIcmd\fP is the command to send and is
215 also the \fIkeyword\fP argument to the specified callback function \fIfunc\fP.
216 \fIdata\fP is user data passed to the callback function. Returnes 0 on success
217 or and error code which may have been returned from the callback function.
220 .BI "gpg_error_t pwmd_save(pwm_t *" pwm ");"
221 Saves the changes to the file associated with the handle \fIpwm\fP. If not
222 called before \fBpwmd_close\fP() then any changes will be lost. If an error
223 occurs then an error code is returned. Otherwise \fB0\fP is returned.
226 .BI "int pwmd_save_nb(pwm_t *" pwm ", gpg_error_t *" error ");"
227 This is a nonblocking way of obtaining the password from
228 .BR pinentry (1)
229 when saving an opened file. When successful, a file descriptor is returned
230 that
231 .BR select (2)
232 can use. When ready
233 .BR read (2)
234 should read a \fIpwmd_nb_status_t\fP and then call
235 \fBpwmd_save_nb_finalize\fP() to update the handle. If there was an error,
236 \fB-1\fP is returned and \fIerror\fP is set. If the file is cached on the
237 server and the save succeeded, \fB-2\fP is returned. Note that
238 \fBPWMD_OPTION_PINENTRY\fP must be set.
241 .BI "gpg_error_t pwmd_save_nb_finalize(pwm_t *" pwm ", pwmd_nb_status_t *" status ");"
242 For use with \fBpwmd_save_nb\fP(); it updates the handle \fIpwm\fP and closes
243 the file descriptor. This should be called right after the successful
244 .BR read (2)
245 of \fIstatus\fP from the file descriptor returned by \fBpwmd_save_nb\fP(). If
246 there was a protocol or
247 .BR pinentry (1)
248 error, an error code is returned. Otherwise \fB0\fP is returned.
251 .BI "gpg_error_t pwmd_terminate_pinentry(pwm_t *" pwm ");"
252 Terminates a
253 .BR pinentry (1)
254 process associated with the handle \fIpwm\fP. This may be useful if your
255 application wants to use a timeout for password entry but doesn't use
256 \fBpwmd_open_nb\fP(). Returns \fB0\fP on success or an error code on failure.
259 .BI "void pwmd_close(pwm_t *" pwm ");"
260 Closes the server connection and free's resources used by the handle
261 \fIpwm\fP.
264 .BI "const char *pwmd_strerror(gpg_error_t " error ");"
265 Returns a string describing the error code \fIerror\fP which was set from one
266 of the above functions.
268 .SH FILES
270 .B ~/.pwmd/socket
271 Default connecting socket.
273 .B ~/.pwmd/pinentry.conf
274 Optional file containing pinentry settings.
276 .B @prefix@/lib/pkgconfig/libpwmd.pc
278 .BR pkg-config (1)
279 metadata file.
281 .B @prefix@/include/libpwmd.h
282 Installed location of header file.
284 .B @pinentry@
285 Default location of the
286 .BR pinentry (1)
287 binary.
289 .SH AUTHOR
290 Ben Kibbey <bjk@luxsci.net>
292 .URL "http://bjk.sourceforge.net/pwmd/" "PWMD Homepage" .
294 .SH "SEE ALSO"
295 .BR pwmd (1),
296 .BR pinentry (1),
297 .BR pkg-config (1)
299 And the \fBlibassuan\fP
300 .BR info (1)
301 documentation.