Use the new CLIENT NAME option to identify pwmc.
[libpwmd.git] / libpwmd.3.in
blob103240ad60109e895896b93e644aacaeaba5b4e0
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 "26 Nov 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_save(pwm_t *" pwm ");"
35 .BI "int pwmd_save_nb(pwm_t *" pwm ", gpg_error_t *" error ");"
36 .BI "gpg_error_t pwmd_save_nb_finalize(pwm_t *" pwm ", pwmd_nb_status_t *" status ");"
37 .BI "gpg_error_t pwmd_terminate_pinentry(pwm_t *" pwm ");"
38 .BI "void pwmd_close(pwm_t *" pwm ");"
39 .BI "const char *pwmd_strerror(gpg_error_t " error ");"
41 .BI "typedef int (*" pwmd_status_fn ")(void *" data ", const char *" line ");"
42 .BI "typedef char *(*" pwmd_password_fn ")(pwm_t *" pwm ", void *" data ");"
43 .BI "typedef gpg_error_t (*" pwmd_inquire_fn ")(void *" data ", const char *" keyword ", gpg_error_t " rc ", char **" result ", size_t *" len ");"
44 .fi
45 .SH DESCRIPTION
46 .B libpwmd
47 is an library making it easy for applications to use
48 .BR pwmd (1).
50 .TP
51 .BI "gpg_error_t pwmd_init(void);"
52 Initializes \fBlibpwmd\fP, \fBlibassuan\fP, \fBlibgpg-error\fP and
53 internationalization. Be sure to call this before using the other functions.
54 If your application uses
55 .BR gettext(3)
56 be sure to call
57 .BR setlocale(3)
58 and
59 .BR textdomain(3)
60 before calling this function.
62 .TP
63 .BI "pwm_t *pwmd_connect(const char *" socket ", gpg_error_t *" error ");"
64 Connects to the specified \fIsocket\fP. If \fIsocket\fP is NULL then a default
65 of \fI~/.pwmd/socket\fP will be used. If there is an error while connecting
66 \fIerror\fP is set to the error code of the failed function and NULL is
67 returned. When successful a handle is returned for use with the other library
68 functions.
70 .TP
71 .BI "gpg_error_t pwmd_setopt(pwm_t *" pwm ", pwmd_option_t " opt ", ...);"
72 Set the library option \fIopt\fP to the value of the next argument. Returns 0
73 on success or an error code. \fIopt\fP is one of the following:
74 .RS
75 .TP
76 .B PWMD_OPTION_PASSWORD_FUNC
77 Specifies a function to use to get a password. The next argument should be of
78 type \fIpwmd_password_fn\fP. The function should return a \fIchar
79 *\fP string which is the password or NULL if there is an
80 error.
81 .TP
82 .B PWMD_OPTION_PASSWORD_DATA
83 A user data pointer passed to the password function.
84 .TP
85 .B PWMD_OPTION_PINENTRY
86 Whether to use 
87 .BR pinentry (1)
88 to obtain the password when opening and saving a file on the server. The
89 following argument is an \fIint\fP and is \fI1\fP to enable
90 .BR pinentry (1)
91 use, and \fI0\fP to use the password which is set with
92 \fBPWMD_OPTION_PASSWORD\fP or \fBPWMD_OPTION_PASSWORD_FUNC\fP.
93 .TP
94 .B PWMD_OPTION_PINENTRY_TRIES
95 The next argument if type \fIint\fP specifies the number of invalid password
96 tries before
97 .BR pinentry (1)
98 gives up. Only \fBpwmd_open\fP() and \fBpwmd_open_nb\fP() will use this
99 option. \fBpwmd_save\fP() and \fBpwmd_save_nb\fP() will continue to confirm a
100 password until either a match is entered or Cancel is selected.
102 .B PWMD_OPTION_PINENTRY_TTY
104 .B PWMD_OPTION_PINENTRY_TERM
106 .B PWMD_OPTION_PINENTRY_DISPLAY
107 Sets the
108 .BR pinentry (1)
109 command line options. The next argument should be of type \fIchar *\fP. If not
110 set, then the current DISPLAY, if set, or tty will be used.
113 If the file \fI~/.pwmd/env\fP exists then values for the above settings will
114 read from this file. The format of the file is one NAME=VALUE per line where
115 NAME is one of TTY, TERM or DISPLAY. The value for an existing setting will be
116 updated to the value contained in the file.
119 .B PWMD_OPTION_PINENTRY_TITLE
121 .B PWMD_OPTION_PINENTRY_DESC
123 .B PWMD_OPTION_PINENTRY_PROMPT
124 Sets the strings used in the 
125 .BR pinentry (1)
126 program.
127 The next argument is of type \fIchar *\fP. If not defined then a default will
128 be used.
130 .B PWMD_OPTION_PASSWORD
131 Sets the password to use for opening and saving a file when
132 \fBPWMD_OPTION_PINENTRY\fP is \fI0\fP. The following argument is the password
133 and is of type \fIchar *\fP.
135 .B PWMD_OPTION_STATUS_FUNC
137 .B PWMD_OPTION_STATUS_DATA
138 The callback of type \fBpwmd_status_fn\fP to be called when 
139 .BR pwmd (1)
140 sends a status message. This function should return \fB0\fP on success or a
141 \fBgpg_error_t\fP on failure. The data passed to the function can be set with
142 \fBPWMD_OPTION_STATUS_DATA\fP. Status message lines are prefixed with a
143 keyword followed by a space then the message. Read the \fBlibassuan\fP
144 documentation for more information. 
146 .B PWMD_OPTION_INQUIRE_FUNC
147 A callback of type \fBpwmd_inquire_fn\fP. When a command that utilizes a
148 server INQUIRE response is sent, this callback function is required so the
149 data can be sent. \fIdata\fP is user data and set with
150 \fBPWMD_OPTION_INQUIRE_DATA\fP. \fIkeyword\fP is the command which the INQUIRE
151 is related (i.e., "STORE"). \fIrc\fP is the return code from
152 assuan_send_data() and is initially \fB0\fP on the first call to the set
153 callback. This gives the client a chance to cleanup and should probably return
154 the same error code, if set, after doing so.
156 \fIresult\fP should be set to the data that is to be sent which is of
157 \fIlen\fP bytes. The data is not modified.
159 The function should return \fBGPG_ERR_EOF\fP when no more data needs to be
160 sent, \fB0\fP when there is more data pending or an error code which will
161 end the INQUIRE command and be returned from \fBpwmd_command()\fP.
163 .B PWMD_OPTION_INQUIRE_DATA
164 Data passed to \fBpwmd_inquire_fn\fP.
169 .BI "gpg_error_t pwmd_open(pwm_t *" pwm ", const char *" filename ");"
170 Opens the specified \fIfilename\fP on the server. The password for the file is
171 gotten from one of the methods specified with \fBpwmd_setopt\fP().
172 An error code is returned on error or \fB0\fP on success.
175 .BI "int pwmd_open_nb(pwm_t *" pwm ", gpg_error_t *" error ", const char *" filename ", int " timeout ");"
176 This is a nonblocking way of obtaining the password from
177 .BR pinentry (1)
178 when opening a file on the server. When successful, it returns a file
179 descriptor that
180 .BR select (2)
181 can use. When ready,
182 .BR read (2)
183 should read a \fIpwmd_nb_status_t\fP and then call
184 \fBpwmd_open_nb_finalize\fP() to update the handle. If there is an error,
185 \fB-1\fP is returned and \fIerror\fP is set. If \fIfilename\fP is already
186 cached on the server or doesn't exist on the filesystem and the open
187 succeeded, \fB-2\fP is returned. The \fItimeout\fP argument is the number of
188 seconds until the pinentry process will terminate. If \fB0\fP, the default, no
189 timeout will be used. Note that \fBPWMD_OPTION_PINENTRY\fP must be set and
190 that if a timeout is specified then the child process will modify it's
191 \fBSIGALRM\fP handler.
194 .BI "gpg_error_t pwmd_open_nb_finalize(pwm_t *" pwm ", pwmd_nb_status_t *" status ");"
195 For use with \fBpwmd_open_nb\fP(); it updates the handle \fIpwm\fP and closes
196 the file descriptor. This should be called right after the successful
197 .BR read (2)
198 of \fIstatus\fP from the file descriptor returned by \fBpwmd_open_nb\fP(). If
199 there was a protocol or
200 .BR pinentry (1)
201 error, an error code is returned. Otherwise \fB0\fP is returned.
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 set
212 \fBPWMD_OPTION_INQUIRE_FUNC\fP with the remaining data after the command
213 \fIcmd\fP discarded.
216 .BI "void pwmd_free_result(void *" result ");"
217 Deallocates the memory of \fBpwmd_command\fP() result. It is important to use
218 this function because
219 .B libpwmd
220 not only keeps track of all allocated memory used by other
221 .B libpwmd
222 functions, but also clears the memory contents for better security. Don't use
223 this to free your own allocated memory though.
226 .BI "gpg_error_t pwmd_save(pwm_t *" pwm ");"
227 Saves the changes to the file associated with the handle \fIpwm\fP. If not
228 called before \fBpwmd_close\fP() then any changes will be lost. If an error
229 occurs then an error code is returned. Otherwise \fB0\fP is returned.
232 .BI "int pwmd_save_nb(pwm_t *" pwm ", gpg_error_t *" error ");"
233 This is a nonblocking way of obtaining the password from
234 .BR pinentry (1)
235 when saving an opened file. When successful, a file descriptor is returned
236 that
237 .BR select (2)
238 can use. When ready
239 .BR read (2)
240 should read a \fIpwmd_nb_status_t\fP and then call
241 \fBpwmd_save_nb_finalize\fP() to update the handle. If there was an error,
242 \fB-1\fP is returned and \fIerror\fP is set. If the file is cached on the
243 server and the save succeeded, \fB-2\fP is returned. Note that
244 \fBPWMD_OPTION_PINENTRY\fP must be set.
247 .BI "gpg_error_t pwmd_save_nb_finalize(pwm_t *" pwm ", pwmd_nb_status_t *" status ");"
248 For use with \fBpwmd_save_nb\fP(); it updates the handle \fIpwm\fP and closes
249 the file descriptor. This should be called right after the successful
250 .BR read (2)
251 of \fIstatus\fP from the file descriptor returned by \fBpwmd_save_nb\fP(). If
252 there was a protocol or
253 .BR pinentry (1)
254 error, an error code is returned. Otherwise \fB0\fP is returned.
257 .BI "gpg_error_t pwmd_terminate_pinentry(pwm_t *" pwm ");"
258 Terminates a
259 .BR pinentry (1)
260 process associated with the handle \fIpwm\fP. This may be useful if your
261 application wants to use a timeout for password entry but doesn't use
262 \fBpwmd_open_nb\fP(). Returns \fB0\fP on success or an error code on failure.
265 .BI "void pwmd_close(pwm_t *" pwm ");"
266 Closes the server connection and free's resources used by the handle
267 \fIpwm\fP.
270 .BI "const char *pwmd_strerror(gpg_error_t " error ");"
271 Returns a string describing the error code \fIerror\fP which was set from one
272 of the above functions.
274 .SH FILES
276 .B ~/.pwmd/socket
277 Default connecting socket.
279 .B ~/.pwmd/env
280 Optional file containing pinentry settings.
282 .B @prefix@/lib/pkgconfig/libpwmd.pc
284 .BR pkg-config (1)
285 metadata file.
287 .B @prefix@/include/libpwmd.h
288 Installed location of header file.
290 .B @pinentry_path@
291 Default location of the
292 .BR pinentry (1)
293 binary.
295 .SH AUTHOR
296 Ben Kibbey <bjk@luxsci.net>
298 .URL "http://bjk.sourceforge.net/pwmd/" "PWMD Homepage" .
300 .SH "SEE ALSO"
301 .BR pwmd (1),
302 .BR pinentry (1),
303 .BR pkg-config (1)
305 And the \fBlibassuan\fP
306 .BR info (1)
307 documentation.