contrib: Add helper to build Android dependencies.
[libpwmd.git] / doc / libpwmd.3
blob8b6e30d9286b9d4a40a81e0eae652d71bc063444
1 .TH "libpwmd.h" 3 "Wed Sep 28 2022" "Version 8.4.3" "libpwmd" \" -*- nroff -*-
2 .ad l
3 .nh
4 .SH NAME
5 libpwmd.h - an API for accessing pwmd
6 .SH SYNOPSIS
7 .br
8 .PP
9 .SS "Macros"
11 .in +1c
12 .ti -1c
13 .RI "#define \fBLIBPWMD_API\fP"
14 .br
15 .ti -1c
16 .RI "#define \fBGPG_ERR_SOURCE_DEFAULT\fP   GPG_ERR_SOURCE_USER_2"
17 .br
18 .ti -1c
19 .RI "#define \fBLIBPWMD_VERSION\fP   0x080403"
20 .br
21 .ti -1c
22 .RI "#define \fBLIBPWMD_VERSION_MAJOR\fP   8"
23 .br
24 .ti -1c
25 .RI "#define \fBLIBPWMD_VERSION_MINOR\fP   4"
26 .br
27 .ti -1c
28 .RI "#define \fBLIBPWMD_VERSION_PATCH\fP   3"
29 .br
30 .ti -1c
31 .RI "#define \fBLIBPWMD_VERSION_STR\fP   '8\&.4\&.3'"
32 .br
33 .ti -1c
34 .RI "#define \fBPWMD_FEATURE_PINENTRY\fP"
35 .br
36 .ti -1c
37 .RI "#define \fBPWMD_FEATURE_QUALITY\fP"
38 .br
39 .ti -1c
40 .RI "#define \fBPWMD_FEATURE_SSH\fP"
41 .br
42 .ti -1c
43 .RI "#define \fBPWMD_FEATURE_GNUTLS\fP"
44 .br
45 .in -1c
46 .SS "Typedefs"
48 .in +1c
49 .ti -1c
50 .RI "typedef struct pwm_s \fBpwm_t\fP"
51 .br
52 .ti -1c
53 .RI "typedef ssize_t(* \fBpwmd_read_cb_t\fP) (void *user, int fd, void *data, size_t len)"
54 .br
55 .ti -1c
56 .RI "typedef ssize_t(* \fBpwmd_write_cb_t\fP) (void *user, int fd, const void *data, size_t len)"
57 .br
58 .ti -1c
59 .RI "typedef gpg_error_t(* \fBpwmd_status_cb_t\fP) (void *user, const char *line)"
60 .br
61 .ti -1c
62 .RI "typedef gpg_error_t(* \fBpwmd_inquire_cb_t\fP) (void *user, const char *keyword, gpg_error_t rc, char **data, size_t *len)"
63 .br
64 .ti -1c
65 .RI "typedef gpg_error_t(* \fBpwmd_knownhost_cb_t\fP) (void *user, const char *host, const char *hostkey, size_t len)"
66 .br
67 .ti -1c
68 .RI "typedef gpg_error_t(* \fBpwmd_passphrase_cb_t\fP) (void *user, const char *host, const char *filename, char **passphrase)"
69 .br
70 .in -1c
71 .SS "Enumerations"
73 .in +1c
74 .ti -1c
75 .RI "enum \fBpwmd_socket_t\fP { \fBPWMD_SOCKET_LOCAL\fP, \fBPWMD_SOCKET_SSH\fP, \fBPWMD_SOCKET_TLS\fP, \fBPWMD_SOCKET_USER\fP }"
76 .br
77 .ti -1c
78 .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 }"
79 .br
80 .ti -1c
81 .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, \fBPWMD_OPTION_SIGPIPE\fP, \fBPWMD_OPTION_SERVER_VERSION\fP, \fBPWMD_OPTION_SSH_NEEDS_PASSPHRASE\fP, \fBPWMD_OPTION_SSH_PASSPHRASE\fP, \fBPWMD_OPTION_TLS_PRIORITY\fP, \fBPWMD_OPTION_READ_CB\fP, \fBPWMD_OPTION_READ_CB_DATA\fP, \fBPWMD_OPTION_WRITE_CB\fP, \fBPWMD_OPTION_WRITE_CB_DATA\fP, \fBPWMD_OPTION_LOCK_TIMEOUT\fP, \fBPWMD_OPTION_STATE_STATUS\fP, \fBPWMD_OPTION_PASSPHRASE_CB\fP, \fBPWMD_OPTION_PASSPHRASE_DATA\fP }"
82 .br
83 .in -1c
84 .SS "Functions"
86 .in +1c
87 .ti -1c
88 .RI "LIBPWMD_API const char * \fBpwmd_version\fP ()"
89 .br
90 .ti -1c
91 .RI "LIBPWMD_API unsigned int \fBpwmd_features\fP ()"
92 .br
93 .ti -1c
94 .RI "LIBPWMD_API gpg_error_t \fBpwmd_init\fP (void)"
95 .br
96 .ti -1c
97 .RI "LIBPWMD_API void \fBpwmd_deinit\fP (void)"
98 .br
99 .ti -1c
100 .RI "LIBPWMD_API gpg_error_t \fBpwmd_new\fP (const char *name, \fBpwm_t\fP **pwm)"
102 .ti -1c
103 .RI "LIBPWMD_API void \fBpwmd_set_pointer\fP (\fBpwm_t\fP *pwm, void *data)"
105 .ti -1c
106 .RI "LIBPWMD_API void * \fBpwmd_get_pointer\fP (\fBpwm_t\fP *pwm)"
108 .ti -1c
109 .RI "LIBPWMD_API gpg_error_t \fBpwmd_cancel\fP (\fBpwm_t\fP *pwm)"
111 .ti -1c
112 .RI "LIBPWMD_API gpg_error_t \fBpwmd_connect_fd\fP (\fBpwm_t\fP *pwm, int fd)"
114 .ti -1c
115 .RI "LIBPWMD_API gpg_error_t \fBpwmd_connect\fP (\fBpwm_t\fP *pwm, const char *url,\&.\&.\&.)"
117 .ti -1c
118 .RI "LIBPWMD_API int \fBpwmd_gnutls_error\fP (\fBpwm_t\fP *pwm, const char **str)"
120 .ti -1c
121 .RI "LIBPWMD_API gpg_error_t \fBpwmd_setopt\fP (\fBpwm_t\fP *pwm, int opt,\&.\&.\&.)"
123 .ti -1c
124 .RI "LIBPWMD_API gpg_error_t \fBpwmd_getopt\fP (\fBpwm_t\fP *pwm, int opt,\&.\&.\&.)"
126 .ti -1c
127 .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)"
129 .ti -1c
130 .RI "LIBPWMD_API gpg_error_t \fBpwmd_password\fP (\fBpwm_t\fP *pwm, const char *keyword, char **result, size_t *size)"
132 .ti -1c
133 .RI "LIBPWMD_API gpg_error_t \fBpwmd_test_quality\fP (const char *passphrase, double *result)"
135 .ti -1c
136 .RI "LIBPWMD_API gpg_error_t \fBpwmd_open\fP (\fBpwm_t\fP *pwm, const char *filename, \fBpwmd_inquire_cb_t\fP callback, void *data)"
138 .ti -1c
139 .RI "LIBPWMD_API gpg_error_t \fBpwmd_process\fP (\fBpwm_t\fP *pwm)"
141 .ti -1c
142 .RI "LIBPWMD_API gpg_error_t \fBpwmd_genkey\fP (\fBpwm_t\fP *pwm, const char *args, \fBpwmd_inquire_cb_t\fP callback, void *user)"
144 .ti -1c
145 .RI "LIBPWMD_API gpg_error_t \fBpwmd_save\fP (\fBpwm_t\fP *pwm, const char *args, \fBpwmd_inquire_cb_t\fP callback, void *user)"
147 .ti -1c
148 .RI "LIBPWMD_API gpg_error_t \fBpwmd_passwd\fP (\fBpwm_t\fP *pwm, const char *args, \fBpwmd_inquire_cb_t\fP callback, void *user)"
150 .ti -1c
151 .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,\&.\&.\&.)"
153 .ti -1c
154 .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)"
156 .ti -1c
157 .RI "LIBPWMD_API gpg_error_t \fBpwmd_disconnect\fP (\fBpwm_t\fP *pwm)"
159 .ti -1c
160 .RI "LIBPWMD_API void \fBpwmd_close\fP (\fBpwm_t\fP *pwm)"
162 .ti -1c
163 .RI "LIBPWMD_API gpg_error_t \fBpwmd_socket_type\fP (\fBpwm_t\fP *pwm, \fBpwmd_socket_t\fP *type)"
165 .ti -1c
166 .RI "LIBPWMD_API gpg_error_t \fBpwmd_fd\fP (\fBpwm_t\fP *pwm, int *fd)"
168 .ti -1c
169 .RI "LIBPWMD_API void \fBpwmd_free\fP (void *ptr)"
171 .ti -1c
172 .RI "LIBPWMD_API void * \fBpwmd_malloc\fP (size_t size)"
174 .ti -1c
175 .RI "LIBPWMD_API void * \fBpwmd_calloc\fP (size_t nmemb, size_t size)"
177 .ti -1c
178 .RI "LIBPWMD_API void * \fBpwmd_realloc\fP (void *ptr, size_t size)"
180 .ti -1c
181 .RI "LIBPWMD_API char * \fBpwmd_strdup\fP (const char *str)"
183 .ti -1c
184 .RI "LIBPWMD_API char * \fBpwmd_strdup_printf\fP (const char *fmt,\&.\&.\&.)"
186 .ti -1c
187 .RI "LIBPWMD_API gpg_error_t \fBpwmd_bulk\fP (\fBpwm_t\fP *pwm, char **result, size_t *len, \fBpwmd_inquire_cb_t\fP callback, void *user, const char *cmds, size_t size)"
189 .ti -1c
190 .RI "LIBPWMD_API gpg_error_t \fBpwmd_bulk_append\fP (char **result, const char *id, size_t id_size, const char *cmd, const char *data, size_t data_size, size_t *offset)"
192 .ti -1c
193 .RI "LIBPWMD_API gpg_error_t \fBpwmd_bulk_append_rc\fP (char **result, gpg_error_t *rcs, const char *id, size_t id_size, const char *cmd, const char *data, size_t data_size, size_t *offset)"
195 .ti -1c
196 .RI "LIBPWMD_API gpg_error_t \fBpwmd_bulk_finalize\fP (char **result)"
198 .ti -1c
199 .RI "LIBPWMD_API gpg_error_t \fBpwmd_bulk_result\fP (const char *str, size_t size, const char *id, size_t id_size, size_t *offset, const char **result, size_t *result_len, gpg_error_t *cmd_rc)"
201 .in -1c
202 .SH "Detailed Description"
203 .PP 
204 libpwmd is a library making it easy for applications to use the pwmd server\&. Pwmd version 3\&.2 or later is required; either locally or remotely\&.
205 .SH "Threads"
207 \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\&.
208 .SH "Remote Connection Details"
210 There are two methods of connecting to a remote pwmd server: over SSH and over TLS\&.
212 Connections over SSH are done by creating 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\&.
214 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\&.
216 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:
220 command="socat UNIX-CONNECT:$HOME/\&.pwmd/socket -" <public_key> \&.\&.\&.
224 Pwmd itself can accept TLS connections so no proxy program is needed as is when using SSH\&. Like SSH connections, TLS connections are created with \fBpwmd_connect()\fP\&. You will need to generate a client key and X509 certificate and then sign it with the same certificate authority (CA) that the pwmd server certificate was signed with\&.
226 Certificates are similar to SSH public and private keys but a little harder to setup correctly\&. See the \fBcerttool(1)\fP (recommended) and \fBopenssl(1)\fP manual pages for details\&.
227 .SH "Pinentry Details"
229 \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 (read: \fBgpg-agent(1)\fP) call pinentry to retrieve a passphrase when needed\&.
231 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 sent to pwmd during \fBpwmd_open()\fP, \fBpwmd_save()\fP and \fBpwmd_passwd()\fP only when pinentry use has not been disabled (\fBPWMD_OPTION_NO_PINENTRY\fP) and when not over a remote connection\&.
233 Some pinentry options may also be specified in the local configuration file \fI'~/\&.config/libpwmd\&.conf'\fP\&.
235 \fBNote\fP
236 .RS 4
237 When the first character of a filename parameter is a tilde (~), it will be expanded to the home directory of the current user\&.
239 The initial values for the pinentry TTY, TERM and DISPLAY are set during \fBpwmd_new()\fP depending on the current environment\&. They are then updated to the values specified in \fI~/\fP\&.config/libpwmd\&.conf\&. They can then be reset or changed as needed by using \fBpwmd_setopt()\fP\&.
241 After establishing a remote connection, pwmd's pinentry is disabled by sending the pwmd option \fI'disable-pinentry'\fP during \fBpwmd_open()\fP\&. A local pinentry will be used instead\&.
244 \fBSee also\fP
245 .RS 4
246 \fBRemote Connection Details\fP, \fBConfiguration File\fP
249 .SH "Configuration File"
251 Initial values overriding libpwmd defaults for a handle may be specified in the configuration file \fI~/\fP\&.config/libpwmd\&.conf\&. This file is read only once during \fBpwmd_new()\fP\&. Option values may be updated by setting the associated option with \fBpwmd_setopt()\fP\&. Blank lines and lines beginning with a '#' are ignored as are unrecognized options\&. See the documentation for each option for its' value type\&. Valid options are:
253 \fBpinentry-path\fP
254 .RS 4
255 Same as \fBPWMD_OPTION_PINENTRY_PATH\fP\&. This option is deprecated and does nothing\&.
258 \fBpinentry-display\fP
259 .RS 4
260 Same as \fBPWMD_OPTION_PINENTRY_DISPLAY\fP\&.
263 \fBpinentry-ttyname\fP
264 .RS 4
265 Same as \fBPWMD_OPTION_PINENTRY_TTY\fP\&.
268 \fBpinentry-ttytype\fP
269 .RS 4
270 Same as \fBPWMD_OPTION_PINENTRY_TERM\fP\&.
273 \fBpinentry-lc-messages\fP
274 .RS 4
275 Same as \fBPWMD_OPTION_PINENTRY_LC_MESSAGES\fP\&.
278 \fBpinentry-lc-ctype\fP
279 .RS 4
280 Same as \fBPWMD_OPTION_PINENTRY_LC_CTYPE\fP\&.
283 \fBpinentry-timeout\fP
284 .RS 4
285 Same as \fBPWMD_OPTION_PINENTRY_TIMEOUT\fP\&.
288 \fBpinentry-tries\fP
289 .RS 4
290 Same as \fBPWMD_OPTION_PINENTRY_TRIES\fP\&.
293 \fBno-pinentry\fP
294 .RS 4
295 Same as \fBPWMD_OPTION_NO_PINENTRY\fP\&.
298 \fBlocal-pinentry\fP
299 .RS 4
300 Same as \fBPWMD_OPTION_LOCAL_PINENTRY\fP\&.
303 \fBno-ssh-agent\fP
304 .RS 4
305 Same as \fBPWMD_OPTION_SSH_AGENT\fP\&.
308 \fBno-tls-verify\fP
309 .RS 4
310 Same as \fBPWMD_OPTION_TLS_VERIFY\fP\&.
313 \fBtls-priority\fP
314 .RS 4
315 Same as \fBPWMD_OPTION_TLS_PRIORITY\fP\&.
318 \fBsocket-timeout\fP
319 .RS 4
320 Same as \fBPWMD_OPTION_SOCKET_TIMEOUT\fP\&.
323 \fBno-lock\fP
324 .RS 4
325 Same as \fBPWMD_OPTION_LOCK_ON_OPEN\fP\&.
328 \fBlock-timeout\fP
329 .RS 4
330 Same as \fBPWMD_OPTION_LOCK_TIMEOUT\fP\&.
333 \fBinclude\fP
334 .RS 4
335 Path to file containing additional libpwmd\&.conf settings\&.
338 .SH "Errors"
340 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\&.
342 \fBNote\fP
343 .RS 4
344 libgpg-error returns an error code as a bitmask of an error source and the error code\&. Determining the error source can help you determine where the error occurred, be it 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 view the error source and description of an error code the \fBgpg-error(1)\fP command line utility may be of use\&. Also see the \fBlibgpg-error\fP texinfo documentation for error code manipulation\&. 
348 .SH "Macro Definition Documentation"
349 .PP 
350 .SS "#define LIBPWMD_VERSION   0x080403"
353 Version information\&. The version of this library\&. 
354 .SS "#define LIBPWMD_VERSION_MAJOR   8"
357 Version information\&. The major release number of this library\&. 
358 .SS "#define LIBPWMD_VERSION_MINOR   4"
361 Version information\&. The minor release number of this library\&. 
362 .SS "#define LIBPWMD_VERSION_PATCH   3"
365 Version information\&. The patch level of this library\&. 
366 .SS "#define LIBPWMD_VERSION_STR   '8\&.4\&.3'"
369 Version information\&. A string representation of the version of this library\&. 
370 .SS "#define PWMD_FEATURE_GNUTLS"
373 Remote connections over TLS\&. 
375 \fBSee also\fP
376 .RS 4
377 \fBRemote Connection Details\fP 
381 .SS "#define PWMD_FEATURE_PINENTRY"
384 Pinentry support\&. This is for a local or fork()'ed pinentry\&. 
385 .SS "#define PWMD_FEATURE_QUALITY"
388 Password quality checking\&. A password quality meter is shown when the pinentry supports it\&. 
389 .SS "#define PWMD_FEATURE_SSH"
392 Remote connections over an SSH channel\&. 
394 \fBSee also\fP
395 .RS 4
396 \fBRemote Connection Details\fP 
400 .SH "Typedef Documentation"
401 .PP 
402 .SS "\fBpwm_t\fP"
405 A libpwmd handle\&. When a pwmd handle or context is mentioned in this documentation it is a pointer of this type\&. A new handle is created with \fBpwmd_new()\fP\&. 
406 .SS "pwmd_inquire_cb_t"
409 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\&.
411 \fBParameters\fP
412 .RS 4
413 \fIuser\fP The user data pointer passed to the libpwmd function specifying this callback\&. 
415 \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\&. 
417 \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\&. 
419 \fIdata\fP The next chunk of data to send or NULL\&. 
421 \fIlen\fP The length of \fIdata\fP or 0\&.
424 \fBReturn values\fP
425 .RS 4
426 \fI0\fP There is more data to be sent\&. 
428 \fIGPG_ERR_EOF\fP No need to call this function again, the current \fIdata\fP is the last to send\&. 
430 \fIcode\fP Any other error code which will cancel the INQUIRE\&.
433 \fBNote\fP
434 .RS 4
435 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\&. 
439 .SS "pwmd_knownhost_cb_t"
442 Verify a remote SSH connection\&. When the current SSH 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\&. When \fBPWMD_OPTION_KNOWNHOST_CB\fP is not set then the default callback function will be used\&.
444 \fBParameters\fP
445 .RS 4
446 \fIuser\fP User data which was set with \fBPWMD_OPTION_KNOWNHOST_DATA\fP\&. 
448 \fIhost\fP The hostname as passed to \fBpwmd_connect()\fP\&. 
450 \fIhostkey\fP The raw binary data of the host key\&. 
452 \fIlen\fP The length of \fIhostkey\fP\&. 
455 \fBReturn values\fP
456 .RS 4
457 \fI0\fP Add the host key to the known hosts file\&. 
459 \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\&.
462 \fBNote\fP
463 .RS 4
464 If the known hosts file cannot be modified do to filesystem restrictions when adding 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\&.
467 \fBSee also\fP
468 .RS 4
469 \fBRemote Connection Details\fP 
473 .SS "pwmd_passphrase_cb_t"
476 Obtain a passphrase during SSH authentication\&. If your SSH identity file requires a passphrase then this callback can be used to obtain it\&. When \fBPWMD_OPTION_PASSPHRASE_CB\fP is not set then the default callback function will be used\&.
478 \fBParameters\fP
479 .RS 4
480 \fIuser\fP User data which was set with \fBPWMD_OPTION_PASSPHRASE_DATA\fP\&. 
482 \fIhost\fP The hostname as passed to \fBpwmd_connect()\fP\&. 
484 \fIfilename\fP The identity file to decrypt\&. 
486 \fIpassphrase\fP The passphrase to use for decryption which must be allocated with \fBpwmd_strdup()\fP, \fBpwmd_malloc()\fP or \fBpwmd_calloc\fP ()\&. It will be freed by libpwmd\&. 
489 \fBReturn values\fP
490 .RS 4
491 \fI0\fP The passphrase was set successfullly and continue authentication\&. 
493 \fInon-zero\fP Abort the connection\&.
496 \fBSee also\fP
497 .RS 4
498 \fBRemote Connection Details\fP 
502 .SS "pwmd_read_cb_t"
505 Custom socket read callback function\&. Use this function to override the libpwmd function used for reading from a socket\&. Set with \fBpwmd_setopt()\fP\&.
507 \fBParameters\fP
508 .RS 4
509 \fIuser\fP A user data pointer which is set with \fBPWMD_OPTION_READ_CB_DATA\fP\&. 
511 \fIfd\fP The file descriptor to read from\&. 
513 \fIdata\fP The buffer to store the read data to\&. 
515 \fIlen\fP The size of the data buffer\&. 
518 \fBReturns\fP
519 .RS 4
520 The amount of bytes read\&. 
523 \fBSee also\fP
524 .RS 4
525 \fBpwmd_connect_fd()\fP 
529 .SS "pwmd_status_cb_t"
532 Process status messages\&. The value of the option \fBPWMD_OPTION_STATUS_CB\fP which is set with \fBpwmd_setopt()\fP\&.
534 \fBParameters\fP
535 .RS 4
536 \fIuser\fP A user data pointer which is set with \fBPWMD_OPTION_STATUS_DATA\fP\&. 
538 \fIline\fP The status message line received from the server\&. 
541 \fBReturns\fP
542 .RS 4
543 0 on success or an error code which will cause a command to fail\&. 
547 .SS "pwmd_write_cb_t"
550 Custom socket write callback function\&. Use this function to override the libpwmd function used for writing to a socket\&. Set with \fBpwmd_setopt()\fP\&.
552 \fBParameters\fP
553 .RS 4
554 \fIuser\fP A user data pointer which is set with \fBPWMD_OPTION_WRITE_CB_DATA\fP\&. 
556 \fIfd\fP The file descriptor to write to\&. 
558 \fIdata\fP The data to write\&. 
560 \fIlen\fP The amount of data bytes to write\&. 
563 \fBReturns\fP
564 .RS 4
565 The amount of bytes written\&. 
568 \fBSee also\fP
569 .RS 4
570 \fBpwmd_connect_fd()\fP 
574 .SH "Enumeration Type Documentation"
575 .PP 
576 .SS "enum \fBpwmd_option_t\fP"
579 libpwmd options\&. Options are set with \fBpwmd_setopt()\fP\&. Some options must be set before a connection is made to have any effect\&.
581 \fBNote\fP
582 .RS 4
583 When the first character of a filename parameter is a tilde (~), it will be expanded to the home directory of the current user\&. 
588 \fBEnumerator\fP
589 .in +1c
591 \fB\fIPWMD_OPTION_PINENTRY_PATH \fP\fP
592 A string value which specifies the full path of the \fBpinentry(1)\fP binary\&. The default is specified at compile time\&. This option is deprecated and does nothing\&.
594 \fBNote\fP
595 .RS 4
596 This only affects the local pinentry\&. 
599 \fBSee also\fP
600 .RS 4
601 \fBPinentry Details\fP 
606 \fB\fIPWMD_OPTION_PINENTRY_TTY \fP\fP
607 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\&.
609 \fBSee also\fP
610 .RS 4
611 \fBPinentry Details\fP 
616 \fB\fIPWMD_OPTION_PINENTRY_TERM \fP\fP
617 A string value which specifies the terminal type (i\&.e\&., vt100) that \fBpinentry(1)\fP will use when no X11 display is available\&.
619 \fBSee also\fP
620 .RS 4
621 \fBPinentry Details\fP 
626 \fB\fIPWMD_OPTION_PINENTRY_DISPLAY \fP\fP
627 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\&.
629 \fBSee also\fP
630 .RS 4
631 \fBPinentry Details\fP 
636 \fB\fIPWMD_OPTION_PINENTRY_ERROR \fP\fP
637 A character string that \fBpinentry(1)\fP will use in it's dialog window\&. 
639 \fB\fIPWMD_OPTION_PINENTRY_PROMPT \fP\fP
640 A character string that \fBpinentry(1)\fP will use in it's dialog window\&. 
642 \fB\fIPWMD_OPTION_PINENTRY_DESC \fP\fP
643 A character string that \fBpinentry(1)\fP will use in it's dialog window\&. 
645 \fB\fIPWMD_OPTION_PINENTRY_LC_CTYPE \fP\fP
646 For \fBpinentry(1)\fP localization\&. 
648 \fB\fIPWMD_OPTION_PINENTRY_LC_MESSAGES \fP\fP
649 For \fBpinentry(1)\fP localization\&. 
651 \fB\fIPWMD_OPTION_PINENTRY_TIMEOUT \fP\fP
652 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\&.
654 \fBNote\fP
655 .RS 4
656 This only affects the local pinentry\&. 
661 \fB\fIPWMD_OPTION_PINENTRY_TRIES \fP\fP
662 An integer value that specifies the number of times to prompt for a passphrase before returning an error\&.
664 \fBNote\fP
665 .RS 4
666 This only affects the local pinentry\&. 
671 \fB\fIPWMD_OPTION_STATUS_CB \fP\fP
672 A function of type \fBpwmd_status_cb_t\fP that will process status messages received from the pwmd server\&. 
674 \fB\fIPWMD_OPTION_STATUS_DATA \fP\fP
675 A user data pointer which is passed to the status message function \fBPWMD_OPTION_STATUS_CB\fP\&. 
677 \fB\fIPWMD_OPTION_KNOWNHOST_CB \fP\fP
678 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\&.
680 \fBSee also\fP
681 .RS 4
682 \fBRemote Connection Details\fP 
687 \fB\fIPWMD_OPTION_KNOWNHOST_DATA \fP\fP
688 User supplied data which is passed to the known host function \fBPWMD_OPTION_KNOWNHOST_CB\fP\&.
690 \fBSee also\fP
691 .RS 4
692 \fBRemote Connection Details\fP 
697 \fB\fIPWMD_OPTION_INQUIRE_TOTAL \fP\fP
698 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\&.
700 \fBNote\fP
701 .RS 4
702 During the INQUIRE, \fBPWMD_OPTION_STATUS_CB\fP is called, when set, after every iteration of the \fBpwmd_inquire_cb_t\fP\&.
704 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\&. 
709 \fB\fIPWMD_OPTION_LOCK_ON_OPEN \fP\fP
710 When set to 1, lock the file mutex during \fBpwmd_open()\fP as if the LOCK command had been sent\&. 
712 \fB\fIPWMD_OPTION_SSH_AGENT \fP\fP
713 Use ssh-agent to retrieve the private key to authenticate with when connecting to a remote pwmd server\&. 
715 \fB\fIPWMD_OPTION_NO_PINENTRY \fP\fP
716 When 1, disable pinentry use\&. This will prevent both pwmd and libpwmd from using a pinentry program and will prompt from the terminal if available\&.
718 \fBNote\fP
719 .RS 4
720 This must be set before calling \fBpwmd_open()\fP\&. 
723 \fBSee also\fP
724 .RS 4
725 \fBPWMD_OPTION_OVERRIDE_INQUIRE\fP, \fBPWMD_OPTION_LOCAL_PINENTRY\fP 
730 \fB\fIPWMD_OPTION_LOCAL_PINENTRY \fP\fP
731 When 1, libpwmd will disable pwmd's pinentry and use it's own pinentry\&. This option is set by default when the connection is a remote one\&.
733 \fBNote\fP
734 .RS 4
735 This must be set before calling \fBpwmd_open()\fP\&. 
740 \fB\fIPWMD_OPTION_OVERRIDE_INQUIRE \fP\fP
741 When set, override libpwmd's internal handling of server inquires with the PASSPHRASE, NEW_PASSPHRASE and SIGN_PASSPHRASE keywords\&. Handling of these keywords 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\&.
743 \fBSee also\fP
744 .RS 4
745 \fBRemote Connection Details\fP, \fBPWMD_OPTION_LOCAL_PINENTRY\fP, \fBpwmd_password()\fP 
750 \fB\fIPWMD_OPTION_SOCKET_TIMEOUT \fP\fP
751 An int specifying a timeout in seconds before a TCP connection or data 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\&. 
753 \fB\fIPWMD_OPTION_TLS_VERIFY \fP\fP
754 An int specifying whether to enable TLS hostname verification against the server certificate chain\&. Default is 0 or disabled\&. 
756 \fB\fIPWMD_OPTION_SIGPIPE \fP\fP
757 Set to 1 to not modify the signal handler to ignore SIGPIPE\&. The default is 0, or to ignore this signal\&. 
759 \fB\fIPWMD_OPTION_SERVER_VERSION \fP\fP
760 Get the version of the pwmd server as an unsigned integer\&. This is a read-only setting and is only available after connecting\&. 
762 \fB\fIPWMD_OPTION_SSH_NEEDS_PASSPHRASE \fP\fP
763 The SSH identity file requires a passphrase\&. When set, prompt for the passphrase after connecting\&. This option has been deprecated\&. Libpwmd will prompt for a password when needed\&. 
765 \fB\fIPWMD_OPTION_SSH_PASSPHRASE \fP\fP
766 Set SSH private identity passphrase\&. The value of this option is duplicated then freed after the call to \fBpwmd_connect()\fP\&. 
768 \fB\fIPWMD_OPTION_TLS_PRIORITY \fP\fP
769 The TLS cipher priority string to use for a TLS connection\&. The default is SECURE256:SECURE192:SECURE128:-VERS-SSL3\&.0:-VERS-TLS1\&.0\&. 
771 \fB\fIPWMD_OPTION_READ_CB \fP\fP
772 The callback function of type \fBpwmd_read_cb_t\fP to use to read from a socket\&. 
774 \fB\fIPWMD_OPTION_READ_CB_DATA \fP\fP
775 The data to pass to the custom read function \fBpwmd_read_cb_t\fP\&. 
777 \fB\fIPWMD_OPTION_WRITE_CB \fP\fP
778 The callback function of type \fBpwmd_write_cb_t\fP to use to write to a socket\&. 
780 \fB\fIPWMD_OPTION_WRITE_CB_DATA \fP\fP
781 The data to pass to the custom write function \fBpwmd_write_cb_t\fP\&. 
783 \fB\fIPWMD_OPTION_LOCK_TIMEOUT \fP\fP
784 The time in tenths of a second to wait for another client to release the mutex associated with a data file before returning an error\&. See the pwmd(1) manual for details\&. 
786 \fB\fIPWMD_OPTION_STATE_STATUS \fP\fP
787 Whether to inform pwmd that you would like to receive client state changes for other clients via a status message\&. 
789 \fB\fIPWMD_OPTION_PASSPHRASE_CB \fP\fP
790 A function of type \fBpwmd_passphrase_cb_t\fP that will be used to obtain a passphrase to use for decryption of an SSH identity file\&.
792 \fBSee also\fP
793 .RS 4
794 \fBRemote Connection Details\fP 
799 \fB\fIPWMD_OPTION_PASSPHRASE_DATA \fP\fP
800 User supplied data which is passed to the passphrase function \fBPWMD_OPTION_PASSPHRASE_CB\fP\&.
802 \fBSee also\fP
803 .RS 4
804 \fBRemote Connection Details\fP 
808 .SS "enum \fBpwmd_pinentry_t\fP"
811 Local pinentry commands and not pwmd pinentry\&. These determine what prompt a local pinentry uses\&. For use with \fBpwmd_getpin()\fP\&. 
813 \fBEnumerator\fP
814 .in +1c
816 \fB\fIPWMD_PINENTRY_OPEN \fP\fP
817 When opening a file\&. 
819 \fB\fIPWMD_PINENTRY_OPEN_FAILED \fP\fP
820 When opening a file failed due to a bad passphrase\&. 
822 \fB\fIPWMD_PINENTRY_SAVE \fP\fP
823 When saving a file\&. 
825 \fB\fIPWMD_PINENTRY_SAVE_CONFIRM \fP\fP
826 For passphrase confirmation\&. 
828 \fB\fIPWMD_PINENTRY_SAVE_FAILED \fP\fP
829 When saving a file and passphrase confirmation failed\&. 
831 \fB\fIPWMD_PINENTRY_CONFIRM \fP\fP
832 For confirmation of a user-defined prompt\&. 
834 \fB\fIPWMD_PINENTRY_USER \fP\fP
835 For the default or user defined string set with \fBPWMD_OPTION_PINENTRY_DESC\fP\&. 
837 \fB\fIPWMD_PINENTRY_CLOSE \fP\fP
838 To terminate the pinentry process created with \fBpwmd_getpin()\fP\&. 
839 .SS "enum \fBpwmd_socket_t\fP"
842 The type of socket a handle is connected to\&. For use with \fBpwmd_socket_type()\fP\&. 
844 \fBEnumerator\fP
845 .in +1c
847 \fB\fIPWMD_SOCKET_LOCAL \fP\fP
848 A local UNIX domain socket\&. 
850 \fB\fIPWMD_SOCKET_SSH \fP\fP
851 An SSH channel over a TCP socket\&. 
853 \fB\fIPWMD_SOCKET_TLS \fP\fP
854 A TLS connection over a TCP socket\&. 
856 \fB\fIPWMD_SOCKET_USER \fP\fP
857 A socket set with \fBpwmd_connect_fd()\fP\&. 
858 .SH "Function Documentation"
859 .PP 
860 .SS "LIBPWMD_API gpg_error_t pwmd_bulk (\fBpwm_t\fP * pwm, char ** result, size_t * len, \fBpwmd_inquire_cb_t\fP callback, void * user, const char * cmds, size_t size)"
863 Send multiple commands in sequence\&. Multiple commands may be sent to a pwmd server by using the \fCBULK\fP protocol command to send an s-expression containing all of the commands to send along with their unique identifiers and command data\&. See the \fCpwmd\fP documentation for details about this command\&.
865 This function uses the \fIINQUIRE\fP variation of the \fCBULK\fP command\&. If you do not need to use any callback functions for any command in \fIcmds\fP, then you can avoid the extra socket IO that an inquire uses by calling \fBpwmd_command()\fP instead\&.
867 \fBpwmd_bulk_append()\fP may be used to create a command list with the required syntax\&.
869 This function returns the result of all commands and can be easily parsed with \fBpwmd_bulk_result()\fP\&.
871 \fBParameters\fP
872 .RS 4
873 \fIpwm\fP A handle\&. 
875 \fIresult\fP The result of all commands in the \fCpwmd\fP bulk-result syntax and freed with \fBpwmd_free()\fP\&. 
877 \fIlen\fP The length of \fIresult\fP\&. 
879 \fIcallback\fP A callback function to invoke when pwmd inquires data from the client\&. 
881 \fIuser\fP User data passed to the \fIcallback\fP function\&. 
883 \fIcmds\fP The canonical s-expression bulk command list to send\&. 
885 \fIsize\fP The length of \fIcmds\fP\&. 
888 \fBReturns\fP
889 .RS 4
890 0 on success or an error code\&. 
893 \fBSee also\fP
894 .RS 4
895 \fBpwmd_bulk_append()\fP, \fBpwmd_bulk_append_rc()\fP, \fBpwmd_bulk_finalize()\fP, \fBpwmd_bulk_result()\fP 
899 .SS "LIBPWMD_API gpg_error_t pwmd_bulk_append (char ** result, const char * id, size_t id_size, const char * cmd, const char * data, size_t data_size, size_t * offset)"
902 Create or append a command to a command list\&. This function creates the required \fCpwmd\fP s-expression syntax for use with \fBpwmd_bulk()\fP from the function parameters\&.
904 \fBParameters\fP
905 .RS 4
906 \fIresult\fP A newly allocated or modified command list containing the s-expression syntax to be passed to the \fCBULK\fP protocol command\&. Can be used more than once to append more commands to the same \fIresult\fP\&. 
908 \fIid\fP A unique identifier for this command\&. 
910 \fIid_size\fP The length of \fIid\fP\&. 
912 \fIcmd\fP The protocol command name to send\&. 
914 \fIdata\fP Data for the command which may be NULL\&. 
916 \fIdata_size\fP The length of \fIdata\fP\&. 
918 \fIoffset\fP When not \fCNULL\fP, the position in \fIresult\fP where this command syntax will be inserted\&. It is updated to point to the end position of the newly created syntax\&. When \fCNULL\fP, the syntax is appended to the end of \fIresult\fP\&. 
921 \fBReturns\fP
922 .RS 4
923 0 on success or an error code\&. 
926 \fBSee also\fP
927 .RS 4
928 \fBpwmd_bulk_append_rc()\fP, \fBpwmd_bulk_finalize()\fP, \fBpwmd_bulk_result()\fP, \fBpwmd_bulk()\fP 
932 .SS "LIBPWMD_API gpg_error_t pwmd_bulk_append_rc (char ** result, gpg_error_t * rcs, const char * id, size_t id_size, const char * cmd, const char * data, size_t data_size, size_t * offset)"
935 Add return code syntax to a command list\&. Creates the needed s-expression syntax to consider a return code for a previously added command by using the \fIoffset\fP result of \fBpwmd_bulk_append()\fP\&. When the return code for the previous command matches one or more of the specified \fIrcs\fP, the new command branch created from the parameters is run\&.
937 Normally, the \fIoffset\fP will point to the end of the previously added command, and by using the same \fIoffset\fP you can test multiple return codes for the same command\&.
939 To consider the return code for a command that was added with this function, decrement the \fIoffset\fP by \fC1\fP to place the specified command syntax inside the previous commands parentheses\&.
941 The \fIrcs\fP parameter is an array of \fCgpg_error_t\fP error codes and must be terminated with \fCGPG_ERR_MISSING_ERRNO\fP\&.
943 \fBParameters\fP
944 .RS 4
945 \fIresult\fP A modified command list containing the s-expression syntax to be passed to the \fCBULK\fP protocol command\&. Can be used more than once to consider multiple return codes for a previous command\&. 
947 \fIrcs\fP The return code(s) to test for\&. 
949 \fIid\fP A unique identifier for this command\&. 
951 \fIid_size\fP The length of \fIid\fP\&. 
953 \fIcmd\fP The protocol command name to send\&. 
955 \fIdata\fP Data for the command which may be NULL\&. 
957 \fIdata_size\fP The length of \fIdata\fP\&. 
959 \fIoffset\fP Where in \fIresult\fP to insert the return code s-expression syntax\&. It is updated to point to the end position of the newly created syntax\&. 
962 \fBReturns\fP
963 .RS 4
964 0 on success or an error code\&. 
967 \fBSee also\fP
968 .RS 4
969 \fBpwmd_bulk_append()\fP, \fBpwmd_bulk_finalize()\fP, \fBpwmd_bulk_result()\fP, \fBpwmd_bulk()\fP 
973 .SS "LIBPWMD_API gpg_error_t pwmd_bulk_finalize (char ** result)"
976 Finalize a bulk command list\&. This function must be called after the final command is added to a command list\&. It fixes up the syntax for the bulk command list\&.
978 \fBParameters\fP
979 .RS 4
980 \fIresult\fP The bulk command list created with \fBpwmd_bulk_append()\fP\&. 
983 \fBReturns\fP
984 .RS 4
985 0 on success or an error code\&. 
988 \fBSee also\fP
989 .RS 4
990 \fBpwmd_bulk_append()\fP, \fBpwmd_bulk_append_rc()\fP, \fBpwmd_bulk()\fP 
994 .SS "LIBPWMD_API gpg_error_t pwmd_bulk_result (const char * str, size_t size, const char * id, size_t id_size, size_t * offset, const char ** result, size_t * result_len, gpg_error_t * cmd_rc)"
997 Extract the result of a bulk command\&. Pass the result of the \fCBULK\fP command to this function to extract the return value and any command data for a given command \fIid\fP\&. The \fIoffset\fP is adjusted to point to the next commnand \fIid\fP so the order of processing command results should be in the same sequence as was passed to the \fCBULK\fP command\&.
999 \fBParameters\fP
1000 .RS 4
1001 \fIstr\fP The resulting s-expression as returned from \fBpwmd_bulk()\fP\&. 
1003 \fIsize\fP The length of \fIstr\fP\&. 
1005 \fIid\fP The command ID to extract\&. 
1007 \fIid_size\fP The length of \fIid\fP\&. 
1009 \fIoffset\fP The offset of \fIstr\fP to start searching for \fIid\fP\&. When \fIid\fP is found in \fIstr\fP, the \fIoffset\fP is updated to point past the data of the current \fIid\fP\&. 
1011 \fIresult\fP The data of the command or NULL if there was none\&. This is a pointer to a location in \fIstr\fP\&. 
1013 \fIresult_len\fP The length of \fIresult\fP\&. 
1015 \fIcmd_rc\fP The return code of the command\&. 
1018 \fBReturns\fP
1019 .RS 4
1020 0 on success or an error code\&. 
1023 \fBSee also\fP
1024 .RS 4
1025 \fBpwmd_bulk()\fP 
1029 .SS "LIBPWMD_API void * pwmd_calloc (size_t nmemb, size_t size)"
1032 A wrapper around calloc()\&. Like calloc(), but lets libpwmd keep track of the pointer\&.
1034 \fBParameters\fP
1035 .RS 4
1036 \fInmemb\fP The number of elements to allocate\&. 
1038 \fIsize\fP The number of bytes to allocate\&. 
1041 \fBReturns\fP
1042 .RS 4
1043 A newly allocated pointer or NULL if there wasn't enough memory\&. 
1046 \fBSee also\fP
1047 .RS 4
1048 calloc(3), \fBpwmd_free()\fP 
1052 .SS "LIBPWMD_API gpg_error_t pwmd_cancel (\fBpwm_t\fP * pwm)"
1055 Cancel an operation\&. This is limited in functionality as it will only cancel an initiating connection to the pwmd server\&. Command cancellation is not yet supported\&.
1057 \fBParameters\fP
1058 .RS 4
1059 \fIpwm\fP A handle\&. 
1062 \fBReturns\fP
1063 .RS 4
1064 0 on success or an error code\&. 
1068 .SS "LIBPWMD_API void pwmd_close (\fBpwm_t\fP * pwm)"
1071 Close a handle\&. This will close the connection to a pwmd server and free any resources associated with it\&.
1073 \fBParameters\fP
1074 .RS 4
1075 \fIpwm\fP A handle\&. 
1078 \fBSee also\fP
1079 .RS 4
1080 \fBpwmd_disconnect()\fP, \fBpwmd_new()\fP 
1084 .SS "LIBPWMD_API gpg_error_t pwmd_command (\fBpwm_t\fP * pwm, char ** result, size_t * len, \fBpwmd_inquire_cb_t\fP callback, void * user, const char * cmd,  \&.\&.\&.)"
1087 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\&.
1089 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\&.
1091 \fBParameters\fP
1092 .RS 4
1093 \fIpwm\fP A handle\&. 
1095 \fIresult\fP The result of the command when successful which must be freed with \fBpwmd_free()\fP\&. 
1097 \fIlen\fP The length of \fIresult\fP\&. 
1099 \fIcallback\fP A callback function to invoke when pwmd inquires data from the client\&. 
1101 \fIuser\fP User data passed to the \fIcallback\fP function\&. 
1103 \fIcmd\fP The command to send and any command arguments\&. 
1106 \fBReturns\fP
1107 .RS 4
1108 0 on success or an error code\&.
1111 \fBNote\fP
1112 .RS 4
1113 Not all commands return a \fIresult\fP\&. 
1117 .SS "LIBPWMD_API gpg_error_t pwmd_command_ap (\fBpwm_t\fP * pwm, char ** result, size_t * len, \fBpwmd_inquire_cb_t\fP callback, void * user, const char * cmd, va_list ap)"
1120 Send a command to the pwmd server\&. Like \fBpwmd_command()\fP but uses an argument pointer instead\&.
1122 \fBParameters\fP
1123 .RS 4
1124 \fIpwm\fP A handle\&. 
1126 \fIresult\fP The result of the command when successful which must be freed with \fBpwmd_free()\fP\&. 
1128 \fIlen\fP The length of \fIresult\fP\&. 
1130 \fIcallback\fP A callback function to invoke when pwmd inquires data from the client\&. 
1132 \fIuser\fP User data passed to the \fIcallback\fP function\&. 
1134 \fIcmd\fP The command to send\&. 
1136 \fIap\fP The arguments to \fIcmd\fP\&. 
1139 \fBReturns\fP
1140 .RS 4
1141 0 on success or an error code\&.
1144 \fBNote\fP
1145 .RS 4
1146 Not all commands return a \fIresult\fP\&. 
1150 .SS "LIBPWMD_API gpg_error_t pwmd_connect (\fBpwm_t\fP * pwm, const char * url,  \&.\&.\&.)"
1153 Establish a connection to a pwmd server\&. Connects to the pwmd server specified in \fIurl\fP\&. The format of \fIurl\fP is: 
1155 \fB\fP
1156 .RS 4
1157 file:///path/to/socket, or 
1160 \fB\fP
1161 .RS 4
1162 ssh[46]://[username@]hostname[:port], or 
1165 \fB\fP
1166 .RS 4
1167 tls[46]://hostname[:port]
1170 If \fIurl\fP is NULL then the default local pwmd socket \fI~/\fP\&.pwmd/socket will be used\&.
1172 The remaining arguments are parameters for the \fIurl\fP\&.
1174 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\&.
1176 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 final parameter is an SHA-256 hash of the server fingerprint to verify against, or NULL\&.
1178 For local connections, any remaining parameters are ignored\&.
1180 \fBParameters\fP
1181 .RS 4
1182 \fIpwm\fP A handle\&. 
1184 \fIurl\fP The socket to connect to\&. 
1186 \fI\&.\&.\&.\fP Remaining parameters for the \fIurl\fP\&. 
1189 \fBReturns\fP
1190 .RS 4
1191 0 on success or an error code\&. 
1194 \fBNote\fP
1195 .RS 4
1196 When the first character of a filename parameter is a tilde (~), it will be expanded to the home directory of the current user\&. 
1199 \fBSee also\fP
1200 .RS 4
1201 \fBPWMD_OPTION_SSH_AGENT\fP, \fBPWMD_OPTION_SOCKET_TIMEOUT\fP, \fBpwmd_socket_type()\fP, \fBpwmd_disconnect()\fP, \fBRemote Connection Details\fP 
1205 .SS "LIBPWMD_API gpg_error_t pwmd_connect_fd (\fBpwm_t\fP * pwm, int fd)"
1208 Associate an already connected socket with a handle\&. Sets a file descriptor for use with the custom read and write callbacks\&. The callbacks must be set before calling this function\&.
1210 \fBParameters\fP
1211 .RS 4
1212 \fIpwm\fP A handle\&. 
1214 \fIfd\fP A connected file descriptor\&. 
1217 \fBReturns\fP
1218 .RS 4
1219 0 on success or an error code\&. 
1222 \fBSee also\fP
1223 .RS 4
1224 \fBpwmd_read_cb_t\fP, \fBpwmd_write_cb_t\fP 
1228 .SS "LIBPWMD_API void pwmd_deinit (void)"
1231 Deinitialize the library\&. This function is mainly for cleaning up other libraries that libpwmd links with to prevent memory and other leaks showing up in a debugger\&. It should be the final libpwmd function call before your app exits\&. 
1232 .SS "LIBPWMD_API gpg_error_t pwmd_disconnect (\fBpwm_t\fP * pwm)"
1235 Close a connection to the pwmd server\&. This will close the connection but keep any previously set options for the specified handle \fIpwm\fP\&. Calling \fBpwmd_connect()\fP will re-acquire an libassuan context\&.
1237 \fBParameters\fP
1238 .RS 4
1239 \fIpwm\fP A handle\&. 
1242 \fBReturns\fP
1243 .RS 4
1244 0 on success or an error code\&. 
1247 \fBSee also\fP
1248 .RS 4
1249 \fBpwmd_close()\fP 
1253 .SS "LIBPWMD_API gpg_error_t pwmd_fd (\fBpwm_t\fP * pwm, int * fd)"
1256 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)\&.
1258 \fBParameters\fP
1259 .RS 4
1260 \fIpwm\fP A handle\&. 
1262 \fIfd\fP Set to the file descriptor associated with \fIpwm\fP\&. 
1265 \fBReturns\fP
1266 .RS 4
1267 0 on success or an error code\&. 
1271 .SS "LIBPWMD_API unsigned int pwmd_features ()"
1274 libpwmd compile time features\&. Useful for clients to determine what features are compiled into libpwmd at runtime\&.
1276 \fBReturns\fP
1277 .RS 4
1278 A bitmask of features\&. 
1282 .SS "LIBPWMD_API void pwmd_free (void * ptr)"
1285 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\&.
1287 The difference between the standard free() and this function is that this one will zero out the contents of the pointer before freeing it\&.
1289 \fBParameters\fP
1290 .RS 4
1291 \fIptr\fP The pointer to deallocate\&. 
1294 \fBSee also\fP
1295 .RS 4
1296 \fBpwmd_malloc()\fP, \fBpwmd_calloc()\fP, \fBpwmd_realloc()\fP, \fBpwmd_strdup()\fP, \fBpwmd_command()\fP 
1300 .SS "LIBPWMD_API gpg_error_t pwmd_genkey (\fBpwm_t\fP * pwm, const char * args, \fBpwmd_inquire_cb_t\fP callback, void * user)"
1303 Generate a new key\&. Generate a new signing or encryption key or both\&. This will only generate a key without saving the XML document to disk\&.
1305 The inquire \fIcallback\fP function should be used when a GENKEY option specified in \fIargs\fP inquires data\&.
1307 \fBParameters\fP
1308 .RS 4
1309 \fIpwm\fP A handle\&. 
1311 \fIargs\fP Any GENKEY protocol command options or NULL\&. 
1313 \fIcallback\fP A callback function to invoke when pwmd inquires data from the client\&. 
1315 \fIuser\fP User data passed to the \fIcallback\fP function\&. 
1318 \fBReturns\fP
1319 .RS 4
1320 0 on success or an error code\&. 
1323 \fBSee also\fP
1324 .RS 4
1325 \fBPWMD_OPTION_OVERRIDE_INQUIRE\fP, \fBPWMD_OPTION_NO_PINENTRY\fP, \fBPWMD_OPTION_LOCAL_PINENTRY\fP, \fBpwmd_command()\fP, \fBPinentry Details\fP 
1329 .SS "LIBPWMD_API void * pwmd_get_pointer (\fBpwm_t\fP * pwm)"
1332 Get user data for a handle\&. Return the user data pointer previously set with \fBpwmd_set_pointer()\fP\&.
1334 \fBParameters\fP
1335 .RS 4
1336 \fIpwm\fP A handle\&. 
1339 \fBReturns\fP
1340 .RS 4
1341 A pointer to the user data\&. 
1345 .SS "LIBPWMD_API gpg_error_t pwmd_getopt (\fBpwm_t\fP * pwm, int opt,  \&.\&.\&.)"
1348 Get the value for a handle option\&. Retrieves the default or previously set value for a handle option\&. See \fBpwmd_option_t\fP for option specific details\&.
1350 \fBParameters\fP
1351 .RS 4
1352 \fIpwm\fP A handle\&. 
1354 \fIopt\fP The option\&. 
1356 \fI\&.\&.\&.\fP A pointer to the option value type to store the value\&. 
1359 \fBReturns\fP
1360 .RS 4
1361 0 on success or an error code\&. 
1364 \fBNote\fP
1365 .RS 4
1366 The value is returned as a pointer and not duplicated\&. 
1370 .SS "LIBPWMD_API gpg_error_t pwmd_getpin (\fBpwm_t\fP * pwm, const char * filename, char ** result, size_t * len, \fBpwmd_pinentry_t\fP which)"
1373 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\&.
1375 This function may also be used to display a user confirmation dialog with pinentry when \fIwhich\fP is \fBPWMD_PINENTRY_CONFIRM\fP\&. The text show in the pinentry is set with \fBpwmd_setopt()\fP\&.
1377 \fBParameters\fP
1378 .RS 4
1379 \fIpwm\fP A handle\&. 
1381 \fIfilename\fP The filename to use in the pinentry dialog strings when using the default pinentry strings\&. 
1383 \fIresult\fP The entered value in the pinentry dialog which should be freed with \fBpwmd_free()\fP\&. 
1385 \fIlen\fP The length of \fIresult\fP\&. 
1387 \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\&.
1390 \fBReturns\fP
1391 .RS 4
1392 0 on success or an error\&.
1395 \fBSee also\fP
1396 .RS 4
1397 \fBpwmd_password()\fP 
1401 .SS "LIBPWMD_API int pwmd_gnutls_error (\fBpwm_t\fP * pwm, const char ** str)"
1404 Get the error code of a failed GnuTLS function\&. When an TLS error occurs while connecting or during a command, this function can be used to get the error code and error description\&.
1406 \fBParameters\fP
1407 .RS 4
1408 \fIpwm\fP A handle\&. 
1410 \fIstr\fP The textual representation of the gnutls error code\&. 
1413 \fBReturns\fP
1414 .RS 4
1415 0 on success or a GnuTLS error code\&. 
1419 .SS "LIBPWMD_API gpg_error_t pwmd_init (void)"
1422 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\&.
1424 \fBReturns\fP
1425 .RS 4
1426 0 on success or an error code\&. 
1430 .SS "LIBPWMD_API void * pwmd_malloc (size_t size)"
1433 A wrapper around malloc\&. Like malloc(), but lets libpwmd keep track of the pointer\&.
1435 \fBParameters\fP
1436 .RS 4
1437 \fIsize\fP The number of bytes to allocate\&. 
1440 \fBReturns\fP
1441 .RS 4
1442 A newly allocated pointer or NULL if there wasn't enough memory\&. 
1445 \fBSee also\fP
1446 .RS 4
1447 malloc(3), \fBpwmd_free()\fP 
1451 .SS "LIBPWMD_API gpg_error_t pwmd_new (const char * name, \fBpwm_t\fP ** pwm)"
1454 Creates a new handle\&. Creates a new handle or context for use with the other functions\&.
1456 \fBParameters\fP
1457 .RS 4
1458 \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\&. 
1460 \fIpwm\fP A new handle for use with the other functions\&.
1463 \fBReturns\fP
1464 .RS 4
1465 0 on success or an error code\&. 
1469 .SS "LIBPWMD_API gpg_error_t pwmd_open (\fBpwm_t\fP * pwm, const char * filename, \fBpwmd_inquire_cb_t\fP callback, void * data)"
1472 Open a file on the pwmd server\&. This will send the OPEN command to the server\&.
1474 To make use of \fIcallback\fP, \fBPWMD_OPTION_OVERRIDE_INQUIRE\fP must also be set\&.
1476 \fBParameters\fP
1477 .RS 4
1478 \fIpwm\fP A handle\&. 
1480 \fIfilename\fP The filename to open\&. The \fIfilename\fP is not a full path but the data filename only\&. 
1482 \fIcallback\fP A callback function to invoke when pwmd inquires data from the client\&. 
1484 \fIdata\fP User data passed to the \fIcallback\fP function\&. 
1487 \fBReturns\fP
1488 .RS 4
1489 0 on success or an error code\&. 
1492 \fBSee also\fP
1493 .RS 4
1494 \fBPWMD_OPTION_OVERRIDE_INQUIRE\fP, \fBPinentry Details\fP, \fBpwmd_password()\fP 
1498 .SS "LIBPWMD_API gpg_error_t pwmd_passwd (\fBpwm_t\fP * pwm, const char * args, \fBpwmd_inquire_cb_t\fP callback, void * user)"
1501 Change the passphrase for a data file\&. This will send the PASSWD command to the server taking care of pinentry settings\&.
1503 The inquire \fIcallback\fP function should be used when a PASSWD option specified in \fIargs\fP inquires data\&.
1505 \fBParameters\fP
1506 .RS 4
1507 \fIpwm\fP A handle\&. 
1509 \fIargs\fP Any PASSWD protocol command options or NULL\&. 
1511 \fIcallback\fP A callback function to invoke when pwmd inquires data from the client\&. 
1513 \fIuser\fP User data passed to the \fIcallback\fP function\&. 
1516 \fBReturns\fP
1517 .RS 4
1518 0 on success or an error code\&. 
1521 \fBSee also\fP
1522 .RS 4
1523 \fBPWMD_OPTION_OVERRIDE_INQUIRE\fP, \fBPWMD_OPTION_NO_PINENTRY\fP, \fBPWMD_OPTION_LOCAL_PINENTRY\fP, \fBpwmd_command()\fP, \fBPinentry Details\fP 
1527 .SS "LIBPWMD_API gpg_error_t pwmd_password (\fBpwm_t\fP * pwm, const char * keyword, char ** result, size_t * size)"
1530 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 one of PASSPHRASE, NEW_PASSPHRASE or SIGN_PASSPHRASE\&. Provided for convenience since it sets proper pinentry strings and handles new passphrase confirmation\&.
1532 \fBParameters\fP
1533 .RS 4
1534 \fIpwm\fP A handle\&. 
1536 \fIkeyword\fP The keyword to determine pinentry strings\&. Usually one of PASSPHRASE, NEW_PASSPHRASE or SIGN_PASSPHRASE as sent by pwmd\&. 
1538 \fIresult\fP The obtained passphrase which should be freed with \fBpwmd_free()\fP\&. 
1540 \fIsize\fP The length of \fIresult\fP\&.
1543 \fBReturns\fP
1544 .RS 4
1545 0 on success or an error\&. 
1549 .SS "LIBPWMD_API gpg_error_t pwmd_process (\fBpwm_t\fP * pwm)"
1552 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\&.
1554 \fBParameters\fP
1555 .RS 4
1556 \fIpwm\fP A handle\&. 
1559 \fBReturns\fP
1560 .RS 4
1561 0 on success or an error code\&.
1564 \fBNote\fP
1565 .RS 4
1566 This function makes use of \fBpwmd_status_cb_t\fP\&. 
1570 .SS "LIBPWMD_API void * pwmd_realloc (void * ptr, size_t size)"
1573 A wrapper around realloc()\&. Like realloc(), but lets libpwmd keep track of the pointer\&.
1575 \fBParameters\fP
1576 .RS 4
1577 \fIptr\fP The pointer to reallocate\&. 
1579 \fIsize\fP The new number of bytes to allocate\&. 
1582 \fBReturns\fP
1583 .RS 4
1584 A newly allocated pointer or NULL if there wasn't enough memory\&. 
1587 \fBSee also\fP
1588 .RS 4
1589 realloc(3), \fBpwmd_free()\fP 
1593 .SS "LIBPWMD_API gpg_error_t pwmd_save (\fBpwm_t\fP * pwm, const char * args, \fBpwmd_inquire_cb_t\fP callback, void * user)"
1596 Save a file on the pwmd server\&. This will send the SAVE command and write any changes to the document to disk\&.
1598 The inquire \fIcallback\fP function should be used when a SAVE option specified in \fIargs\fP inquires data\&.
1600 \fBParameters\fP
1601 .RS 4
1602 \fIpwm\fP A handle\&. 
1604 \fIargs\fP Any SAVE protocol command options or NULL\&. 
1606 \fIcallback\fP A callback function to invoke when pwmd inquires data from the client\&. 
1608 \fIuser\fP User data passed to the \fIcallback\fP function\&. 
1611 \fBReturns\fP
1612 .RS 4
1613 0 on success or an error code\&. 
1616 \fBSee also\fP
1617 .RS 4
1618 \fBPWMD_OPTION_OVERRIDE_INQUIRE\fP, \fBPWMD_OPTION_NO_PINENTRY\fP, \fBPWMD_OPTION_LOCAL_PINENTRY\fP, \fBpwmd_command()\fP, \fBPinentry Details\fP 
1622 .SS "LIBPWMD_API void pwmd_set_pointer (\fBpwm_t\fP * pwm, void * data)"
1625 Set user data for a handle\&. Use this function to associate user data with a handle that can later be retrieved with \fBpwmd_get_pointer()\fP\&.
1627 \fBParameters\fP
1628 .RS 4
1629 \fIpwm\fP A handle\&. 
1631 \fIdata\fP A pointer to the user data\&. 
1635 .SS "LIBPWMD_API gpg_error_t pwmd_setopt (\fBpwm_t\fP * pwm, int opt,  \&.\&.\&.)"
1638 Set handle options\&. See \fBpwmd_option_t\fP for option specific details\&.
1640 \fBParameters\fP
1641 .RS 4
1642 \fIpwm\fP A handle\&. 
1644 \fIopt\fP The option\&. 
1646 \fI\&.\&.\&.\fP The option value\&. 
1649 \fBReturns\fP
1650 .RS 4
1651 0 on success or an error code\&. 
1655 .SS "LIBPWMD_API gpg_error_t pwmd_socket_type (\fBpwm_t\fP * pwm, \fBpwmd_socket_t\fP * type)"
1658 The type of connection a handle has\&. Useful when you need to know what kind of connection a handle has\&.
1660 \fBParameters\fP
1661 .RS 4
1662 \fIpwm\fP A handle\&. 
1664 \fItype\fP The type of socket\&. 
1667 \fBReturns\fP
1668 .RS 4
1669 0 on success or an error code\&.
1672 \fBSee also\fP
1673 .RS 4
1674 \fBpwmd_socket_t\fP 
1678 .SS "LIBPWMD_API char * pwmd_strdup (const char * str)"
1681 A wrapper around strdup()\&. Like strdup(), but lets libpwmd keep track of the pointer\&.
1683 \fBParameters\fP
1684 .RS 4
1685 \fIstr\fP The string to duplicate\&. 
1688 \fBReturns\fP
1689 .RS 4
1690 A newly allocated character pointer or NULL if there wasn't enough memory\&. 
1693 \fBSee also\fP
1694 .RS 4
1695 strdup(3), \fBpwmd_free()\fP 
1699 .SS "LIBPWMD_API char * pwmd_strdup_printf (const char * fmt,  \&.\&.\&.)"
1702 Duplicate a formatted string\&. Like \fBasprintf(3)\fP, but lets libpwmd keep track of the pointer\&.
1704 \fBParameters\fP
1705 .RS 4
1706 \fIfmt\fP The formatted string and any following arguments\&. 
1709 \fBReturns\fP
1710 .RS 4
1711 A newly allocated character pointer or NULL if there wasn't enough memory\&. 
1714 \fBSee also\fP
1715 .RS 4
1716 \fBpwmd_free()\fP 
1720 .SS "LIBPWMD_API gpg_error_t pwmd_test_quality (const char * passphrase, double * result)"
1723 Test the quality of a passphrase\&. When built with passphrase quality checking, you can test the amount of entropy a passphrase contains with this function\&. It simply wraps around the zxcvbn-c quality checking function\&.
1725 \fBParameters\fP
1726 .RS 4
1727 \fIpassphrase\fP The passphrase to test\&. 
1729 \fIresult\fP The entropy of the passphrase in bits\&.
1732 \fBReturns\fP
1733 .RS 4
1734 0 on success or an error code\&. 
1738 .SS "LIBPWMD_API const char * pwmd_version ()"
1741 Returns this version of libpwmd\&. As a string\&. 
1743 \fBReturns\fP
1744 .RS 4
1745 A string\&. 
1749 .SH "Author"
1750 .PP 
1751 Generated automatically by Doxygen for libpwmd from the source code\&.