Fix pwmd_save() to determine whether to use pinentry.
[libpwmd.git] / doc / libpwmd.3
bloba437c6536b2668b7dd6d779d1d1056dcf4c32929
1 .TH "libpwmd.h" 3 "Sun Feb 24 2013" "Version 7.0.0" "libpwmd" \" -*- nroff -*-
2 .ad l
3 .nh
4 .SH NAME
5 libpwmd.h - an API for accessing pwmd
6 .SH "Description"
7 .PP 
8 libpwmd is a library making it easy for applications to use the pwmd server\&. Pwmd version 3\&.0 or later is required; either locally or remotely\&.
9 .SH "Threads"
10 .PP
11 \fBlibpwmd\fP should be thread-safe on a per handle bases\&. Meaning that only one thread should access a \fBpwm_t\fP handle at a time\&.
12 .SH "Remote Connection Details"
13 .PP
14 There are two methods of connecting to a remote pwmd server: an SSH channel, or over TLS\&. Connections over SSH are less reliable than TLS connections since a proxy program is needed to connect to the pwmd UNIX Domain Socket\&. The kernel that pwmd runs under may buffer the UDS data before it reaches the proxy program and there isn't a portable way to modify kernel buffer settings\&. For larger transfers of data this is noticeable by the hanging of the command that initiated the transfer\&.
15 .PP
16 If you really do need an SSH connection you can do so by using an SSH channel to spawn a shell that executes a proxy server to connect to the pwmd local Unix Domain Socket\&. Authentication is done by using SSH public key (see \fBssh-keygen(1)\fP) authentication and verifying the host key against a local OpenSSH known hosts formatted file\&.
17 .PP
18 An unknown servers public key can be added to a known hosts file after user confirmation by setting the callback function \fBpwmd_knownhost_cb_t\fP before connecting to the unknown host\&.
19 .PP
20 On the server side you'll need a proxy server to connect to the pwmd server\&. Below is an example of an \fBauthorized_keys(5)\fP entry that will do this\&. The \fIpublic_key\fP portion should be the same as the contents of the \fBssh-keygen(1)\fP \fIidentity\&.pub\fP file generated on the client machine\&. The private key should be passed as the \fIidentity\fP parameter to \fBpwmd_connect()\fP:
21 .PP
22 .PP
23 .nf
24 command='socat UNIX-CONNECT:$HOME/\&.pwmd/socket -' <public_key> \&.\&.\&.
25 .fi
26 .PP
27 .PP
28 \fBNote:\fP
29 .RS 4
30 Only an SSH identity without a passphrase is supported\&. For now anyway\&. This is a limitation of libssh2 (version 1\&.2\&.8 as of this writing)\&.
31 .RE
32 .PP
33 \fBVersion:\fP
34 .RS 4
35 6\&.0\&.3 The first version to use the OpenSSH known hosts file format exclusively\&. Earlier versions used only an SHA1 hash of the host key\&.
36 .RE
37 .PP
38 As mentioned, TLS connections are more reliable since there is no proxy program needed to connect to the pwmd server\&. pwmd itself can accept TLS connections and like SSH connections they are created with \fBpwmd_connect()\fP\&. You'll need to generate a client key and X509 certificate then sign it with the same certificate authority (CA) that the pwmd server certificate was signed with\&.
39 .PP
40 Certificates are similar to SSH public and private keys but a little harder to get setup correctly\&. See the \fBcerttool(1)\fP (recommended) and \fBopenssl(1)\fP manual pages for details\&.
41 .SH "Pinentry Details"
42 .PP
43 \fBpinentry(1)\fP is a program that prompts the user for input which is normally a passphrase or a confirmation\&. libpwmd can use this program either locally (X11 forwarding is not yet supported) or have the pwmd server or gpg-agent use it's pinentry to retrieve a passphrase when needed\&.
44 .PP
45 There are a few options that tell pinentry how and where to prompt for a needed passphrase\&. See the \fBpwmd_option_t\fP section for details\&. These options are only sent to pwmd in \fBpwmd_open()\fP and only when pinentry use has not been disabled and when not over an remote connnection\&.
46 .PP
47 Some pinentry options may also be specified in the local configuration file \fI'~/\&.pwmd/pinentry\&.conf'\fP\&. These options are initial values for each pinentry invokation (not retries) and may be changed by setting the appropriate \fBpwmd_option_t\fP\&. Options and values are separated with a '=' on a single line\&. Unrecognized options are ignored\&. Here are the recognized options:
48 .PP
49 \fBParameters:\fP
50 .RS 4
51 \fIPATH\fP The full path to the location of the pinentry binary\&. Only useful for the local pinentry\&. 
52 .br
53 \fIDISPLAY\fP The X11 display to use\&. 
54 .br
55 \fITTYNAME\fP The full path to the tty that pinentry should prompt on\&. 
56 .br
57 \fITTYTYPE\fP The terminal type of the tty which is required if DISPLAY is not set\&. 
58 .br
59 \fILC_MESSAGES\fP Adjust for the current locale\&. 
60 .br
61 \fILC_CTYPE\fP Adjust for the current locale\&.
62 .RE
63 .PP
64 \fBNote:\fP
65 .RS 4
66 When the first character of a filename parameter is a tilde (~), it will be expanded to the home directory of the current user\&.
67 .PP
68 The initial values for the pinentry TTY, TERM and DISPLAY are set during \fBpwmd_new()\fP depending on the current environment\&. They can be reset or changed as needed\&.
69 .PP
70 After establishing a remote connection, pwmd's pinentry is disabled by passing the '&ndash;no-pinentry' option to the OPEN protocol command during \fBpwmd_open()\fP since X11 forwarding has not been implemented\&. A local pinentry will be used in the case of a remote connection\&.
71 .RE
72 .PP
73 \fBSee Also:\fP
74 .RS 4
75 \fBRemote Connection Details\fP
76 .RE
77 .PP
78 .SH "Errors"
79 .PP
80 libpwmd uses libgpg-error for all error codes\&. Error codes can be described by using \fBgpg_strerror()\fP, or the thread-safe \fBgpg_strerror_r()\fP\&.
81 .PP
82 \fBNote:\fP
83 .RS 4
84 libgpg-error returns an error code as a bitmask of an error source and the error code\&. Determining the error source can help you find where the error occured, beit from \fBpinentry(1)\fP, \fBgpg-agent(1)\fP, \fBlibgcrypt\fP, \fBpwmd(1)\fP or \fBlibpwmd(3)\fP\&. pwmd uses the \fBGPG_ERR_SOURCE_USER_1\fP error source and libpwmd uses \fBGPG_ERR_SOURCE_USER_2\fP\&. To find the error source of an error code the \fBgpg-error(1)\fP command line utility may be of use\&. Also see the \fBlibgpg-error\fP documentation for error code manipulation\&. 
85 .RE
86 .PP
88 .SH SYNOPSIS
89 .br
90 .PP
91 .SS "Constants"
93 .in +1c
94 .ti -1c
95 .RI "#define \fBLIBPWMD_API\fP"
96 .br
97 .ti -1c
98 .RI "#define \fBGPG_ERR_SOURCE_DEFAULT\fP   GPG_ERR_SOURCE_USER_2"
99 .br
100 .ti -1c
101 .RI "#define \fBLIBPWMD_VERSION\fP   0x070000"
103 .ti -1c
104 .RI "#define \fBLIBPWMD_VERSION_MAJOR\fP   7"
106 .ti -1c
107 .RI "#define \fBLIBPWMD_VERSION_MINOR\fP   0"
109 .ti -1c
110 .RI "#define \fBLIBPWMD_VERSION_PATCH\fP   0"
112 .ti -1c
113 .RI "#define \fBLIBPWMD_VERSION_STR\fP   '7\&.0\&.0-dev'"
115 .ti -1c
116 .RI "#define \fBPWMD_FEATURE_PINENTRY\fP"
118 .ti -1c
119 .RI "#define \fBPWMD_FEATURE_CRACK\fP"
121 .ti -1c
122 .RI "#define \fBPWMD_FEATURE_SSH\fP"
124 .ti -1c
125 .RI "#define \fBPWMD_FEATURE_GNUTLS\fP"
127 .in -1c
128 .SS "Typedefs"
130 .in +1c
131 .ti -1c
132 .RI "typedef struct pwm_s \fBpwm_t\fP"
134 .ti -1c
135 .RI "typedef gpg_error_t(* \fBpwmd_status_cb_t\fP )(void *user, const char *line)"
137 .ti -1c
138 .RI "typedef gpg_error_t(* \fBpwmd_inquire_cb_t\fP )(void *user, const char *keyword, gpg_error_t rc, char **data, size_t *len)"
140 .ti -1c
141 .RI "typedef gpg_error_t(* \fBpwmd_knownhost_cb_t\fP )(void *user, const char *host, const char *hostkey, size_t len)"
143 .in -1c
144 .SS "Enumerations"
146 .in +1c
147 .ti -1c
148 .RI "enum \fBpwmd_socket_t\fP { \fBPWMD_SOCKET_LOCAL\fP, \fBPWMD_SOCKET_SSH\fP, \fBPWMD_SOCKET_TLS\fP }"
150 .ti -1c
151 .RI "enum \fBpwmd_pinentry_t\fP { \fBPWMD_PINENTRY_OPEN\fP, \fBPWMD_PINENTRY_OPEN_FAILED\fP, \fBPWMD_PINENTRY_SAVE\fP, \fBPWMD_PINENTRY_SAVE_CONFIRM\fP, \fBPWMD_PINENTRY_SAVE_FAILED\fP, \fBPWMD_PINENTRY_CONFIRM\fP, \fBPWMD_PINENTRY_USER\fP, \fBPWMD_PINENTRY_CLOSE\fP }"
153 .ti -1c
154 .RI "enum \fBpwmd_option_t\fP { \fBPWMD_OPTION_PINENTRY_PATH\fP, \fBPWMD_OPTION_PINENTRY_TTY\fP, \fBPWMD_OPTION_PINENTRY_TERM\fP, \fBPWMD_OPTION_PINENTRY_DISPLAY\fP, \fBPWMD_OPTION_PINENTRY_ERROR\fP, \fBPWMD_OPTION_PINENTRY_PROMPT\fP, \fBPWMD_OPTION_PINENTRY_DESC\fP, \fBPWMD_OPTION_PINENTRY_LC_CTYPE\fP, \fBPWMD_OPTION_PINENTRY_LC_MESSAGES\fP, \fBPWMD_OPTION_PINENTRY_TIMEOUT\fP, \fBPWMD_OPTION_PINENTRY_TRIES\fP, \fBPWMD_OPTION_STATUS_CB\fP, \fBPWMD_OPTION_STATUS_DATA\fP, \fBPWMD_OPTION_KNOWNHOST_CB\fP, \fBPWMD_OPTION_KNOWNHOST_DATA\fP, \fBPWMD_OPTION_INQUIRE_TOTAL\fP, \fBPWMD_OPTION_LOCK_ON_OPEN\fP, \fBPWMD_OPTION_SSH_AGENT\fP, \fBPWMD_OPTION_NO_PINENTRY\fP, \fBPWMD_OPTION_LOCAL_PINENTRY\fP, \fBPWMD_OPTION_OVERRIDE_INQUIRE\fP, \fBPWMD_OPTION_SOCKET_TIMEOUT\fP, \fBPWMD_OPTION_TLS_VERIFY\fP }"
156 .in -1c
157 .SS "Functions"
159 .in +1c
160 .ti -1c
161 .RI "LIBPWMD_API const char * \fBpwmd_version\fP ()"
163 .ti -1c
164 .RI "LIBPWMD_API unsigned int \fBpwmd_features\fP ()"
166 .ti -1c
167 .RI "LIBPWMD_API gpg_error_t \fBpwmd_init\fP (void)"
169 .ti -1c
170 .RI "LIBPWMD_API void \fBpwmd_deinit\fP (void)"
172 .ti -1c
173 .RI "LIBPWMD_API gpg_error_t \fBpwmd_new\fP (const char *name, \fBpwm_t\fP **pwm)"
175 .ti -1c
176 .RI "LIBPWMD_API gpg_error_t \fBpwmd_connect\fP (\fBpwm_t\fP *pwm, const char *url,\&.\&.\&.)"
178 .ti -1c
179 .RI "LIBPWMD_API gpg_error_t \fBpwmd_setopt\fP (\fBpwm_t\fP *pwm, \fBpwmd_option_t\fP opt,\&.\&.\&.)"
181 .ti -1c
182 .RI "LIBPWMD_API gpg_error_t \fBpwmd_getpin\fP (\fBpwm_t\fP *pwm, const char *filename, char **result, size_t *len, \fBpwmd_pinentry_t\fP which)"
184 .ti -1c
185 .RI "LIBPWMD_API gpg_error_t \fBpwmd_password\fP (\fBpwm_t\fP *pwm, const char *keyword, char **data, size_t *size)"
187 .ti -1c
188 .RI "LIBPWMD_API gpg_error_t \fBpwmd_open\fP (\fBpwm_t\fP *pwm, const char *filename, \fBpwmd_inquire_cb_t\fP callback, void *data)"
190 .ti -1c
191 .RI "LIBPWMD_API gpg_error_t \fBpwmd_process\fP (\fBpwm_t\fP *pwm)"
193 .ti -1c
194 .RI "LIBPWMD_API gpg_error_t \fBpwmd_save\fP (\fBpwm_t\fP *pwm, const char *args, \fBpwmd_inquire_cb_t\fP callback, void *user)"
196 .ti -1c
197 .RI "LIBPWMD_API gpg_error_t \fBpwmd_command\fP (\fBpwm_t\fP *pwm, char **result, size_t *len, \fBpwmd_inquire_cb_t\fP callback, void *user, const char *cmd,\&.\&.\&.)"
199 .ti -1c
200 .RI "LIBPWMD_API gpg_error_t \fBpwmd_command_ap\fP (\fBpwm_t\fP *pwm, char **result, size_t *len, \fBpwmd_inquire_cb_t\fP callback, void *user, const char *cmd, va_list ap)"
202 .ti -1c
203 .RI "LIBPWMD_API gpg_error_t \fBpwmd_disconnect\fP (\fBpwm_t\fP *pwm)"
205 .ti -1c
206 .RI "LIBPWMD_API void \fBpwmd_close\fP (\fBpwm_t\fP *pwm)"
208 .ti -1c
209 .RI "LIBPWMD_API gpg_error_t \fBpwmd_socket_type\fP (\fBpwm_t\fP *pwm, \fBpwmd_socket_t\fP *type)"
211 .ti -1c
212 .RI "LIBPWMD_API gpg_error_t \fBpwmd_fd\fP (\fBpwm_t\fP *pwm, int *fd)"
214 .ti -1c
215 .RI "LIBPWMD_API void \fBpwmd_free\fP (void *ptr)"
217 .ti -1c
218 .RI "LIBPWMD_API void * \fBpwmd_malloc\fP (size_t size)"
220 .ti -1c
221 .RI "LIBPWMD_API void * \fBpwmd_calloc\fP (size_t nmemb, size_t size)"
223 .ti -1c
224 .RI "LIBPWMD_API void * \fBpwmd_realloc\fP (void *ptr, size_t size)"
226 .ti -1c
227 .RI "LIBPWMD_API char * \fBpwmd_strdup\fP (const char *str)"
229 .ti -1c
230 .RI "LIBPWMD_API char * \fBpwmd_strdup_printf\fP (const char *fmt,\&.\&.\&.)"
232 .ti -1c
233 .RI "void \fBgnutls_global_set_mem_functions\fP (void *(*)(size_t), void *(*)(size_t), int(*)(const void *), void *(*)(void *, size_t), void(*)(void *))"
235 .in -1c
236 .SH "Constant Details"
237 .PP 
238 .SS "#define LIBPWMD_VERSION   0x070000"
241 Version information\&. The version of this library\&. 
242 .SS "#define LIBPWMD_VERSION_MAJOR   7"
245 Version information\&. The major release number of this library\&. 
246 .SS "#define LIBPWMD_VERSION_MINOR   0"
249 Version information\&. The minor release number of this library\&. 
250 .SS "#define LIBPWMD_VERSION_PATCH   0"
253 Version information\&. The patch level of this library\&. 
254 .SS "#define LIBPWMD_VERSION_STR   '7\&.0\&.0-dev'"
257 Version information\&. A string representation of the version of this library\&. 
258 .SS "#define PWMD_FEATURE_CRACK"
261 Password quality checking\&. A password quality meter is shown when the pinentry supports it\&. 
262 .SS "#define PWMD_FEATURE_GNUTLS"
265 Remote connections over TLS\&. \fBSee Also:\fP
266 .RS 4
267 \fBRemote Connection Details\fP 
271 .SS "#define PWMD_FEATURE_PINENTRY"
274 Pinentry support\&. This is for a local or fork()'ed pinentry\&. 
275 .SS "#define PWMD_FEATURE_SSH"
278 Remote connections over an SSH channel\&. \fBSee Also:\fP
279 .RS 4
280 \fBRemote Connection Details\fP 
284 .SH "Typedef Details"
285 .PP 
286 .SS "\fBpwm_t\fP"
289 libpwmd handle\&. When a handle or context is mentioned in this documentation it is a pointer of this type\&. A new handle is created with \fBpwmd_new()\fP\&. 
290 .SS "pwmd_inquire_cb_t"
293 Send data to the pwmd server\&. This is a callback function that is used for sending data to the server for commands that need to reply to an INQUIRE server response\&. The reason for this callback is to let the client send as many bytes as it wants rather than the entire data at once\&. It gets called during an internal \fBassuan_transact()\fP from an internal inquire callback function which in turn calls this function by looping over its return value\&.
295 \fBParameters:\fP
296 .RS 4
297 \fIuser\fP The user data pointer passed to the libpwmd function specifying this callback\&. 
299 \fIkeyword\fP The name of this inquire\&. Could be a command name or some keyword describing what needs to be sent\&. See the pwmd and \fBgpg-agent(1)\fP documentation for details\&. 
301 \fIrc\fP The result of the last internal call to \fBassuan_send_data()\fP which did the sending of the data to the pwmd server\&. On the first call to this callback it's value will always be 0 since no data has been sent yet\&. This should be checked during each call to this function and should return the same error code when set\&. Its purpose is to let the client clean up before letting the command fail\&. 
303 \fIdata\fP The next chunk of data to send or NULL\&. 
305 \fIlen\fP The length of \fIdata\fP or 0\&.
308 \fBReturn values:\fP
309 .RS 4
310 \fI0\fP There is more data to be sent\&. 
312 \fIGPG_ERR_EOF\fP No need to call this function again, the current \fIdata\fP is the last to send\&. 
314 \fIcode\fP Any other error code which will cancel the INQUIRE\&.
317 \fBNote:\fP
318 .RS 4
319 The sent data is processed line-per-line\&. The line is either newline terminated or is buffered until ASSUAN_LINELENGTH bytes have been allocated\&. Any remaining bytes are sent after the INQUIRE has finished\&. 
323 .SS "pwmd_knownhost_cb_t"
326 Verify a remote SSH connection\&. When \fBPWMD_OPTION_KNOWNHOST_CB\fP is set and a the current connections host key was not found in the known hosts file, then this callback function can be used to confirm the addition of the new host key to the known_hosts file\&.
328 \fBParameters:\fP
329 .RS 4
330 \fIuser\fP User data which was set with \fBPWMD_OPTION_KNOWNHOST_DATA\fP\&. 
332 \fIhost\fP The hostname as passed to \fBpwmd_connect()\fP\&. 
334 \fIhostkey\fP The raw binary data of the host key\&. 
336 \fIlen\fP The length of \fIhostkey\fP\&. 
339 \fBReturn values:\fP
340 .RS 4
341 \fI0\fP Add the host key to the known hosts file\&. 
343 \fIGPG_ERR_NOT_CONFIRMED\fP Do not add the host key and abort the connection\&. This is the recommended error code although any other non-zero return value will also abort the connection\&.
346 \fBNote:\fP
347 .RS 4
348 If the known hosts file cannot be modified do to filesystem restrictions when trying to add the new host key, no error is returned\&. Instead, the host key is added to the current connections host key cache and the connection is accepted\&.
351 \fBSee Also:\fP
352 .RS 4
353 \fBRemote Connection Details\fP 
357 .SS "pwmd_status_cb_t"
360 Process status messages\&. The value of the option \fBPWMD_OPTION_STATUS_CB\fP which is set with \fBpwmd_setopt()\fP\&.
362 \fBParameters:\fP
363 .RS 4
364 \fIuser\fP A user data pointer which is set with \fBPWMD_OPTION_STATUS_DATA\fP\&. 
366 \fIline\fP The status message line received from the server\&. 
369 \fBReturns:\fP
370 .RS 4
371 0 on success or an error code which will cause a command to fail\&. 
375 .SH "Enumeration Details"
376 .PP 
377 .SS "enum \fBpwmd_option_t\fP"
380 libpwmd options\&. Options are set with \fBpwmd_setopt()\fP\&. Some options must be set before a connection is made to have any effect\&.
382 \fBNote:\fP
383 .RS 4
384 When the first character of a filename parameter is a tilde (~), it will be expanded to the home directory of the current user\&. 
389 \fBEnumerator: \fP
390 .in +1c
392 \fB\fIPWMD_OPTION_PINENTRY_PATH \fP\fP
393 A string value which specifies the full path of the \fBpinentry(1)\fP binary\&. The default is specified at compile time\&.
395 \fBNote:\fP
396 .RS 4
397 This only affects the local pinentry\&. 
400 \fBSee Also:\fP
401 .RS 4
402 \fBPinentry Details\fP 
407 \fB\fIPWMD_OPTION_PINENTRY_TTY \fP\fP
408 A string value which specifies the full path to the TTY that \fBpinentry(1)\fP will use to prompt on\&. When set and no DISPLAY is available, \fBPWMD_OPTION_PINENTRY_TERM\fP must also be set\&.
410 \fBSee Also:\fP
411 .RS 4
412 \fBPinentry Details\fP 
417 \fB\fIPWMD_OPTION_PINENTRY_TERM \fP\fP
418 A string value which specifies the terminal type (i\&.e\&., vt100) that \fBpinentry(1)\fP will use when no X11 display is available\&.
420 \fBSee Also:\fP
421 .RS 4
422 \fBPinentry Details\fP 
427 \fB\fIPWMD_OPTION_PINENTRY_DISPLAY \fP\fP
428 A string value which specifies the X11 display that \fBpinentry(1)\fP will use\&. \fBpinentry(1)\fP seems to make DISPLAY have a higher priority than \fBPWMD_OPTION_PINENTRY_TTY\fP\&.
430 \fBSee Also:\fP
431 .RS 4
432 \fBPinentry Details\fP 
437 \fB\fIPWMD_OPTION_PINENTRY_ERROR \fP\fP
438 A character string that \fBpinentry(1)\fP will use in it's dialog window\&. 
440 \fB\fIPWMD_OPTION_PINENTRY_PROMPT \fP\fP
441 A character string that \fBpinentry(1)\fP will use in it's dialog window\&.  
443 \fB\fIPWMD_OPTION_PINENTRY_DESC \fP\fP
444 A character string that \fBpinentry(1)\fP will use in it's dialog window\&.  
446 \fB\fIPWMD_OPTION_PINENTRY_LC_CTYPE \fP\fP
447 For \fBpinentry(1)\fP localization\&. 
449 \fB\fIPWMD_OPTION_PINENTRY_LC_MESSAGES \fP\fP
450 For \fBpinentry(1)\fP localization\&.  
452 \fB\fIPWMD_OPTION_PINENTRY_TIMEOUT \fP\fP
453 An integer value that specifies the number of seconds \fBpinentry(1)\fP will wait for input before timing out and aborting the current command\&. If 0, then no timeout will be used\&. The default is 30\&.
455 \fBNote:\fP
456 .RS 4
457 This only affects the local pinentry\&. 
462 \fB\fIPWMD_OPTION_PINENTRY_TRIES \fP\fP
463 An integer value that specifies the number of times to prompt for a passphrase before returning an error\&.
465 \fBNote:\fP
466 .RS 4
467 This only affects the local pinentry\&. 
472 \fB\fIPWMD_OPTION_STATUS_CB \fP\fP
473 A function of type \fBpwmd_status_cb_t\fP that will process status messages received from the pwmd server\&. 
475 \fB\fIPWMD_OPTION_STATUS_DATA \fP\fP
476 A user data pointer which is passed to the status message function \fBPWMD_OPTION_STATUS_CB\fP\&. 
478 \fB\fIPWMD_OPTION_KNOWNHOST_CB \fP\fP
479 A function of type \fBpwmd_knownhost_cb_t\fP that will be used to confirm a host key that was not found in the known hosts file\&.
481 \fBSee Also:\fP
482 .RS 4
483 \fBRemote Connection Details\fP 
488 \fB\fIPWMD_OPTION_KNOWNHOST_DATA \fP\fP
489 User supplied data which is passed to the known host function \fBPWMD_OPTION_KNOWNHOST_CB\fP\&.
491 \fBSee Also:\fP
492 .RS 4
493 \fBRemote Connection Details\fP 
498 \fB\fIPWMD_OPTION_INQUIRE_TOTAL \fP\fP
499 When the total number of bytes to be sent via an INQUIRE is known, this should be set so XFER status messages can be parsed correctly\&. When not known or unset, 0 is used as the total argument to the XFER status message\&. This option should be reset in every function that uses an \fBpwmd_inquire_cb_t\fP\&.
501 \fBNote:\fP
502 .RS 4
503 During the INQUIRE, \fBPWMD_OPTION_STATUS_CB\fP is called, when set, after every iteration of the \fBpwmd_inquire_cb_t\fP\&.
505 This is a libpwmd feature\&. pwmd itself does not send XFER status messages during an INQUIRE\&. Status messages can be parsed only when \fBPWMD_OPTION_STATUS_CB\fP is set\&. 
510 \fB\fIPWMD_OPTION_LOCK_ON_OPEN \fP\fP
511 When set to 1, lock the file mutex after opening a file as if the LOCK command had been sent\&. 
513 \fB\fIPWMD_OPTION_SSH_AGENT \fP\fP
514 Use ssh-agent to retrieve the private key to authenticate when connecting to a remote pwmd server\&. 
516 \fB\fIPWMD_OPTION_NO_PINENTRY \fP\fP
517 When 1, disable pinentry use\&. This will prevent both pwmd and libpwmd from using a pinentry program\&.
519 \fBNote:\fP
520 .RS 4
521 This must be set before calling \fBpwmd_open()\fP\&. 
526 \fB\fIPWMD_OPTION_LOCAL_PINENTRY \fP\fP
527 When 1, libpwmd will disable pwmd's pinentry and use it's own fork(2)'ed pinentry\&.
529 \fBNote:\fP
530 .RS 4
531 This must be set before calling \fBpwmd_open()\fP\&. 
536 \fB\fIPWMD_OPTION_OVERRIDE_INQUIRE \fP\fP
537 When set, override libpwmd's handling of server inquires with the PASSPHRASE and NEW_PASSPHRASE keywords\&. This handling is done automatically when \fBPWMD_OPTION_NO_PINENTRY\fP or \fBPWMD_OPTION_LOCAL_PINENTRY\fP is set or when the connection is a remote one\&.
539 \fBSee Also:\fP
540 .RS 4
541 \fBRemote Connection Details\fP, \fBPWMD_OPTION_LOCAL_PINENTRY\fP, \fBpwmd_password()\fP 
546 \fB\fIPWMD_OPTION_SOCKET_TIMEOUT \fP\fP
547 An int specifying a timeout in seconds before a TCP connection or transfer function will timeout causing a connection or command to fail\&. This option can be specified both before and after a connection has been established\&. When 0, no timeout is used\&. 
549 \fB\fIPWMD_OPTION_TLS_VERIFY \fP\fP
550 An int specifying whether to enable TLS hostname verification on the server certificate chain\&. Default is 0 or disabled\&. 
551 .SS "enum \fBpwmd_pinentry_t\fP"
554 Local pinentry commands and not pwmd pinentry\&. These determine what prompt a local or fork()'ed pinentry uses\&. For use with \fBpwmd_getpin()\fP\&. 
556 \fBEnumerator: \fP
557 .in +1c
559 \fB\fIPWMD_PINENTRY_OPEN \fP\fP
560 When opening a file\&. 
562 \fB\fIPWMD_PINENTRY_OPEN_FAILED \fP\fP
563 When opening a file failed due to a bad passphrase\&. 
565 \fB\fIPWMD_PINENTRY_SAVE \fP\fP
566 When saving a file\&. 
568 \fB\fIPWMD_PINENTRY_SAVE_CONFIRM \fP\fP
569 For passphrase confirmation\&. 
571 \fB\fIPWMD_PINENTRY_SAVE_FAILED \fP\fP
572 When saving a file and passphrase confirmation failed\&. 
574 \fB\fIPWMD_PINENTRY_CONFIRM \fP\fP
575 For confirmation of a user-defined prompt\&. 
577 \fB\fIPWMD_PINENTRY_USER \fP\fP
578 For the default or user defined string set with \fBPWMD_OPTION_PINENTRY_DESC\fP\&. 
580 \fB\fIPWMD_PINENTRY_CLOSE \fP\fP
581 To terminate the pinentry process created with \fBpwmd_getpin()\fP\&. 
582 .SS "enum \fBpwmd_socket_t\fP"
585 The type of socket a handle is connected to\&. For use with \fBpwmd_socket_type()\fP\&. 
587 \fBEnumerator: \fP
588 .in +1c
590 \fB\fIPWMD_SOCKET_LOCAL \fP\fP
591 A local UNIX domain socket\&. 
593 \fB\fIPWMD_SOCKET_SSH \fP\fP
594 An SSH channel over a TCP socket\&. 
596 \fB\fIPWMD_SOCKET_TLS \fP\fP
597 A TLS connection over a TCP socket\&. 
598 .SH "Function Details"
599 .PP 
600 .SS "void gnutls_global_set_mem_functions (void **)(size_t, void **)(size_t, int(*)(const void *), void **)(void *, size_t, void(*)(void *))"
603 Convenience declaration\&. This allows an application wanting both a TLS connection and libpwmd secure memory management in GnuTLS, not needing to have the GnuTLS development files installed\&. This function should be called before \fBpwmd_init()\fP\&.
605 It is not done in \fBpwmd_init()\fP itself since the application may have already initialized GnuTLS by some other means\&. 
606 .SS "LIBPWMD_API void* pwmd_calloc (size_tnmemb, size_tsize)"
609 A wrapper around calloc()\&. Like calloc(), but lets libpwmd keep track of the pointer\&.
611 \fBParameters:\fP
612 .RS 4
613 \fInmemb\fP The number of elements to allocate\&. 
615 \fIsize\fP The number of bytes to allocate\&. 
618 \fBReturns:\fP
619 .RS 4
620 A newly allocated pointer or NULL if there wasn't enough memory\&. 
623 \fBSee Also:\fP
624 .RS 4
625 calloc(3), \fBpwmd_free()\fP 
629 .SS "LIBPWMD_API void pwmd_close (\fBpwm_t\fP *pwm)"
632 Close a handle\&. This will close the connection to a pwmd server and free any resources associated with it\&.
634 \fBParameters:\fP
635 .RS 4
636 \fIpwm\fP A handle\&. 
639 \fBReturns:\fP
640 .RS 4
641 Nothing\&. 
644 \fBSee Also:\fP
645 .RS 4
646 \fBpwmd_disconnect()\fP, \fBpwmd_new()\fP 
650 .SS "LIBPWMD_API gpg_error_t pwmd_command (\fBpwm_t\fP *pwm, char **result, size_t *len, \fBpwmd_inquire_cb_t\fPcallback, void *user, const char *cmd, \&.\&.\&.)"
653 Send a command to the pwmd server\&. You should avoid sending the BYE command here because the assuan context will be freed and bad things will happen\&. Use \fBpwmd_close()\fP instead\&.
655 For pwmd commands that use an INQUIRE to retrieve data from a client, the \fIcallback\fP parameter must be non-NULL and will be used to send the data to pwmd\&.
657 \fBParameters:\fP
658 .RS 4
659 \fIpwm\fP A handle\&. 
661 \fIresult\fP The result of the command when successful which must be freed with \fBpwmd_free()\fP\&. 
663 \fIlen\fP The length of \fIresult\fP\&. 
665 \fIcallback\fP A callback function to invoke when pwmd inquires data from the client\&. 
667 \fIuser\fP User data passed to the \fIcallback\fP function\&. 
669 \fIcmd\fP The command to send and any following arguments\&. 
672 \fBReturns:\fP
673 .RS 4
674 0 on success or an error code\&.
677 \fBNote:\fP
678 .RS 4
679 Not all commands return a \fIresult\fP\&. 
683 .SS "LIBPWMD_API gpg_error_t pwmd_command_ap (\fBpwm_t\fP *pwm, char **result, size_t *len, \fBpwmd_inquire_cb_t\fPcallback, void *user, const char *cmd, va_listap)"
686 Send a command to the pwmd server\&. Like \fBpwmd_command()\fP but uses an argument pointer instead\&.
688 \fBParameters:\fP
689 .RS 4
690 \fIpwm\fP A handle\&. 
692 \fIresult\fP The result of the command when successful which must be freed with \fBpwmd_free()\fP\&. 
694 \fIlen\fP The length of \fIresult\fP\&. 
696 \fIcallback\fP A callback function to invoke when pwmd inquires data from the client\&. 
698 \fIuser\fP User data passed to the \fIcallback\fP function\&. 
700 \fIcmd\fP The command to send\&. 
702 \fIap\fP The arguments to \fIcmd\fP\&. 
705 \fBReturns:\fP
706 .RS 4
707 0 on success or an error code\&.
710 \fBNote:\fP
711 .RS 4
712 Not all commands return a \fIresult\fP\&. 
716 .SS "LIBPWMD_API gpg_error_t pwmd_connect (\fBpwm_t\fP *pwm, const char *url, \&.\&.\&.)"
719 Establish a connection to a pwmd server\&. Connects to the pwmd server specified in \fIurl\fP\&. The format of \fIurl\fP is: 
721 \fB\fP
722 .RS 4
723 file:///path/to/socket, or 
726 \fB\fP
727 .RS 4
728 ssh[46]://[username@]hostname[:port], or 
731 \fB\fP
732 .RS 4
733 tls[46]://hostname[:port]
736 If \fIurl\fP is NULL then the default local pwmd socket \fI~/\fP\&.pwmd/socket will be used\&.
738 The remaining arguments are parameters for the \fIurl\fP\&.
740 For SSH connections, the first of the positional parameters should be the identity file to use and is required to be non-NULL unless \fBPWMD_OPTION_SSH_AGENT\fP is set\&. The final parameter is the known hosts file to use or NULL to use a default of \fI~/\fP\&.ssh/knownhosts\&.
742 For TLS connections, the first positional parameter should be the client certificate filename\&. The second parameter should be the client certificate key filename\&. The third parameter should be the Certificate Authority (CA) file that was used to sign the server certificate\&. The fourth parameter should be a TLS cipher priority string or NULL to use the default of 'SECURE256'\&. The final parameter is an SHA-1 hash of the server fingerprint or NULL\&.
744 For local connections, any remaining parameters are ignored\&.
746 \fBParameters:\fP
747 .RS 4
748 \fIpwm\fP A handle\&. 
750 \fIurl\fP The socket to connect to\&. 
752 \fI\&.\&.\&.\fP Remaining parameters for the \fIurl\fP\&. 
755 \fBReturns:\fP
756 .RS 4
757 0 on success or an error code\&. 
760 \fBNote:\fP
761 .RS 4
762 When the first character of a filename parameter is a tilde (~), it will be expanded to the home directory of the current user\&. 
765 \fBSee Also:\fP
766 .RS 4
767 \fBPWMD_OPTION_SSH_AGENT\fP, \fBPWMD_OPTION_SOCKET_TIMEOUT\fP, \fBpwmd_socket_type()\fP, \fBpwmd_disconnect()\fP, \fBRemote Connection Details\fP 
771 .SS "LIBPWMD_API void pwmd_deinit (void)"
774 Deinitialize the library\&. This function is mainly for cleaning up other libraries that libpwmd links with to prevent leaks showing up a debugger\&. It should be the final libpwmd function call before your app exits\&. 
775 .SS "LIBPWMD_API gpg_error_t pwmd_disconnect (\fBpwm_t\fP *pwm)"
778 Close a connection to the pwmd server\&. This will close the connection but keep any previously set options for the specified handle\&. Calling \fBpwmd_connect()\fP will re-acquire an libassuan context\&.
780 \fBParameters:\fP
781 .RS 4
782 \fIpwm\fP A handle\&. 
785 \fBReturns:\fP
786 .RS 4
787 0 on success or an error code\&. 
790 \fBSee Also:\fP
791 .RS 4
792 \fBpwmd_close()\fP 
796 .SS "LIBPWMD_API gpg_error_t pwmd_fd (\fBpwm_t\fP *pwm, int *fd)"
799 Get the file descriptor associated with a handle\&. May be useful to determine whether a handle is ready for reading or writing by using select(2) or poll(2)\&.
801 \fBParameters:\fP
802 .RS 4
803 \fIpwm\fP A handle\&. 
805 \fIfd\fP Set to the file descriptor associated with \fIpwm\fP\&. 
808 \fBReturns:\fP
809 .RS 4
810 0 on success or an error code\&. 
814 .SS "LIBPWMD_API unsigned int pwmd_features ()"
817 libpwmd compile time features\&. Useful for clients to determine what features are compiled into libpwmd at runtime\&.
819 \fBReturns:\fP
820 .RS 4
821 A bitmask of features\&. 
825 .SS "LIBPWMD_API void pwmd_free (void *ptr)"
828 Free a previously allocated pointer\&. Use this function to free resources allocated by the other libpwmd memory functions\&. Do not use it to free allocations made by other allocators\&.
830 The difference between the standard free() and this function is that this one will zero out the contents of the pointer before freeing it\&.
832 \fBParameters:\fP
833 .RS 4
834 \fIptr\fP The pointer to deallocate\&. 
837 \fBReturns:\fP
838 .RS 4
839 Nothing\&. 
842 \fBSee Also:\fP
843 .RS 4
844 \fBpwmd_malloc()\fP, \fBpwmd_calloc()\fP, \fBpwmd_realloc()\fP, \fBpwmd_strdup()\fP, \fBpwmd_command()\fP 
848 .SS "LIBPWMD_API gpg_error_t pwmd_getpin (\fBpwm_t\fP *pwm, const char *filename, char **result, size_t *len, \fBpwmd_pinentry_t\fPwhich)"
851 Launch a local pinentry\&. Does not send any command to the pwmd server\&. This maybe useful if a passphrase is needed while opening a file over a remote connection and during an \fBpwmd_open()\fP server inquire\&.
853 This function may also be used to display a user confirmation dialog with pinentry when \fIwhich\fP is \fBPWMD_PINENTRY_CONFIRM\fP\&. The text to prompt with is set with \fBPWMD_OPTION_PINENTRY_DESC\fP\&.
855 \fBParameters:\fP
856 .RS 4
857 \fIpwm\fP A handle\&. 
859 \fIfilename\fP The filename to use in the pinentry dialog strings\&. 
861 \fIresult\fP The entered value in the pinentry dialog which should be freed with \fBpwmd_free()\fP\&. 
863 \fIlen\fP The length of \fIresult\fP\&. 
865 \fIwhich\fP Determines the default strings shown in the pinentry dialog\&. \fBpwmd_setopt()\fP may also be used to override the defaults\&. In this case \fBPWMD_PINENTRY_USER\fP should be used\&. \fBPWMD_PINENTRY_CLOSE\fP should be used to terminate the pinentry process when the pinentry is no longer needed\&.
868 \fBReturns:\fP
869 .RS 4
870 0 on success or an error\&.
873 \fBSee Also:\fP
874 .RS 4
875 \fBpwmd_password()\fP 
879 .SS "LIBPWMD_API gpg_error_t pwmd_init (void)"
882 Initialize the library\&. This function must be the first function called in the library before any others\&. It sets up the memory allocators and internationalization among other things\&.
884 \fBReturns:\fP
885 .RS 4
886 0 on success or an error code\&. 
890 .SS "LIBPWMD_API void* pwmd_malloc (size_tsize)"
893 A wrapper around malloc\&. Like malloc(), but lets libpwmd keep track of the pointer\&.
895 \fBParameters:\fP
896 .RS 4
897 \fIsize\fP The number of bytes to allocate\&. 
900 \fBReturns:\fP
901 .RS 4
902 A newly allocated pointer or NULL if there wasn't enough memory\&. 
905 \fBSee Also:\fP
906 .RS 4
907 malloc(3), \fBpwmd_free()\fP 
911 .SS "LIBPWMD_API gpg_error_t pwmd_new (const char *name, \fBpwm_t\fP **pwm)"
914 Creates a new handle\&. Creates a new handle for use with the other functions\&.
916 \fBParameters:\fP
917 .RS 4
918 \fIname\fP If not NULL, the name of the application\&. The application name is sent to the pwmd server after successfully connecting and is used in pwmd logging\&. 
920 \fIpwm\fP A new handle for use with the other functions\&.
923 \fBReturns:\fP
924 .RS 4
925 0 on success or an error code\&. 
929 .SS "LIBPWMD_API gpg_error_t pwmd_open (\fBpwm_t\fP *pwm, const char *filename, \fBpwmd_inquire_cb_t\fPcallback, void *data)"
932 Open a file on the pwmd server\&. This will send the OPEN command to the server\&.
934 The inquire \fIcallback\fP function should be used when \fBPWMD_OPTION_NO_PINENTRY\fP is set and is used to send the passphrase when needed\&.
936 \fBParameters:\fP
937 .RS 4
938 \fIpwm\fP A handle\&. 
940 \fIfilename\fP The filename to open\&. The \fIfilename\fP is not a full path but the data filename only\&. 
942 \fIcallback\fP A callback function to invoke when pwmd inquires data from the client\&. 
944 \fIdata\fP User data passed to the \fIcallback\fP function\&. 
947 \fBReturns:\fP
948 .RS 4
949 0 on success or an error code\&. 
952 \fBSee Also:\fP
953 .RS 4
954 \fBPWMD_OPTION_OVERRIDE_INQUIRE\fP, \fBPinentry Details\fP, \fBpwmd_password()\fP 
958 .SS "LIBPWMD_API gpg_error_t pwmd_password (\fBpwm_t\fP *pwm, const char *keyword, char **data, size_t *size)"
961 Obtain a passphrase from a local pinentry\&. This is the same function that libpwmd uses during an inquire when using the local pinentry and the inquire keyword is either PASSPHRASE or NEW_PASSPHRASE\&. Provided for convenience since it sets proper pinentry strings and handles new passphrase confirmation\&.
963 \fBParameters:\fP
964 .RS 4
965 \fIpwm\fP A handle\&. 
967 \fIkeyword\fP The keyword to determine pinentry strings\&. Usually PASSPHRASE or NEW_PASSPHRASE\&. 
969 \fIdata\fP The obtained passphrase which should be freed with \fBpwmd_free()\fP\&. 
971 \fIsize\fP The length of \fIdata\fP\&.
974 \fBReturns:\fP
975 .RS 4
976 0 on success or an error\&. 
980 .SS "LIBPWMD_API gpg_error_t pwmd_process (\fBpwm_t\fP *pwm)"
983 Check for socket activity\&. This function should be called periodically to check for any pending status messages sent from the server and when \fInot\fP in a command\&.
985 \fBParameters:\fP
986 .RS 4
987 \fIpwm\fP A handle\&. 
990 \fBReturns:\fP
991 .RS 4
992 0 on success or an error code\&.
995 \fBNote:\fP
996 .RS 4
997 This function makes use of \fBpwmd_status_cb_t\fP\&. 
1001 .SS "LIBPWMD_API void* pwmd_realloc (void *ptr, size_tsize)"
1004 A wrapper around realloc()\&. Like realloc(), but lets libpwmd keep track of the pointer\&.
1006 \fBParameters:\fP
1007 .RS 4
1008 \fIptr\fP The pointer to reallocate\&. 
1010 \fIsize\fP The new number of bytes to allocate\&. 
1013 \fBReturns:\fP
1014 .RS 4
1015 A newly allocated pointer or NULL if there wasn't enough memory\&. 
1018 \fBSee Also:\fP
1019 .RS 4
1020 realloc(3), \fBpwmd_free()\fP 
1024 .SS "LIBPWMD_API gpg_error_t pwmd_save (\fBpwm_t\fP *pwm, const char *args, \fBpwmd_inquire_cb_t\fPcallback, void *user)"
1027 Save a file on the pwmd server\&. This will send the SAVE command and write any changes to the document to disk\&.
1029 The inquire \fIcallback\fP function should be used when \fBPWMD_OPTION_NO_PINENTRY\fP is set or when a SAVE option specified in \fIargs\fP inquires more data\&. This function will also disable the pwmd pinentry when \fBPWMD_OPTION_NO_PINENTRY\fP or \fBPWMD_OPTION_LOCAL_PINENTRY\fP is set\&. It will not restore the pwmd pinentry mode that was previously set before calling this function\&.
1031 \fBParameters:\fP
1032 .RS 4
1033 \fIpwm\fP A handle\&. 
1035 \fIargs\fP Any SAVE protocol command options or NULL\&. 
1037 \fIcallback\fP A callback function to invoke when pwmd inquires data from the client\&. 
1039 \fIuser\fP User data passed to the \fIcallback\fP function\&. 
1042 \fBReturns:\fP
1043 .RS 4
1044 0 on success or an error code\&. 
1047 \fBSee Also:\fP
1048 .RS 4
1049 \fBPWMD_OPTION_OVERRIDE_INQUIRE\fP, \fBPWMD_OPTION_NO_PINENTRY\fP, \fBPWMD_OPTION_LOCAL_PINENTRY\fP, \fBpwmd_command()\fP, \fBPinentry Details\fP 
1053 .SS "LIBPWMD_API gpg_error_t pwmd_setopt (\fBpwm_t\fP *pwm, \fBpwmd_option_t\fPopt, \&.\&.\&.)"
1056 Set handle options\&. See \fBpwmd_option_t\fP for option specific details\&.
1058 \fBParameters:\fP
1059 .RS 4
1060 \fIpwm\fP A handle\&. 
1062 \fIopt\fP The option and following option value\&. 
1065 \fBReturns:\fP
1066 .RS 4
1067 0 on success or an error code\&. 
1071 .SS "LIBPWMD_API gpg_error_t pwmd_socket_type (\fBpwm_t\fP *pwm, \fBpwmd_socket_t\fP *type)"
1074 The type of connection a handle has\&. Useful when you want to know what kind of connection a handle has\&.
1076 \fBParameters:\fP
1077 .RS 4
1078 \fIpwm\fP A handle\&. 
1080 \fItype\fP The type of socket\&. 
1083 \fBReturns:\fP
1084 .RS 4
1085 0 on success or an error code\&.
1088 \fBSee Also:\fP
1089 .RS 4
1090 \fBpwmd_socket_t\fP 
1094 .SS "LIBPWMD_API char* pwmd_strdup (const char *str)"
1097 A wrapper around strdup()\&. Like strdup(), but lets libpwmd keep track of the pointer\&.
1099 \fBParameters:\fP
1100 .RS 4
1101 \fIstr\fP The string to duplicate\&. 
1104 \fBReturns:\fP
1105 .RS 4
1106 A newly allocated character pointer or NULL if there wasn't enough memory\&. 
1109 \fBSee Also:\fP
1110 .RS 4
1111 strdup(3), \fBpwmd_free()\fP 
1115 .SS "LIBPWMD_API char* pwmd_strdup_printf (const char *fmt, \&.\&.\&.)"
1118 Duplicate a formatted string\&. Like \fBasprintf(3)\fP, but lets libpwmd keep track of the pointer\&.
1120 \fBParameters:\fP
1121 .RS 4
1122 \fIfmt\fP The formatted string and any following arguments\&. 
1125 \fBReturns:\fP
1126 .RS 4
1127 A newly allocated character pointer or NULL if there wasn't enough memory\&. 
1130 \fBSee Also:\fP
1131 .RS 4
1132 \fBpwmd_free()\fP 
1136 .SS "LIBPWMD_API const char* pwmd_version ()"
1139 Returns this version of libpwmd\&. As a string\&. 
1141 \fBReturns:\fP
1142 .RS 4
1143 A string\&. 
1147 .SH "Author"
1148 .PP 
1149 Generated automatically by Doxygen for libpwmd from the source code\&.