1 .TH "libpwmd.h" 3 "26 May 2010" "Version 6.0.3" "libpwmd" \" -*- nroff -*-
5 libpwmd.h - an API for accessing pwmd
8 libpwmd is a library making it easy for applications to use the pwmd server. Pwmd version 2.0 or later is required; either locally or remotely.
11 A remote connection to a pwmd server is possible by using an SSH channel which spawns a shell and executes a proxy server that connects 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.
13 The servers public key can be had by using \fBpwmd_get_hostkey()\fP and storing the result in a file or done automatially by using a callback function \fBpwmd_knownhost_cb_t\fP while connecting to the unknown host.
15 On the server side you'll need a proxy server to connect to the real pwmd server. Here's an example \fBauthorized_keys(5)\fP entry that will do this. The hash portion should be the same as the contents of the generated \fBssh-keygen(1)\fP \fIidentity.pub\fP file which is passed as a parameter to the SSH connection functions:
19 command='socat UNIX-CONNECT:$HOME/.pwmd/socket -' <hash> ...
25 Only an SSH identity without a passphrase is supported. For now anyway. This is a limitation of libssh2 (version 1.1 as of this writing).
30 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.
35 X11 port forwarding so a remote pinentry can use the local display.
38 .SH "Pinentry Details"
40 \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 use it's pinentry to retrieve a passphrase when needed. How this is done depends what function gets called and whether the pwmd connection is over an SSH channel.
42 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 not sent (when using pwmd's pinentry, not the local one) until the pinentry is needed.
44 If using a local pinentry by calling \fBpwmd_open2()\fP, \fBpwmd_save2()\fP, \fBpwmd_open_async2()\fP or \fBpwmd_save_async2()\fP, libpwmd will send the command 'SET ENABLE_PINENTRY=0' to the pwmd server. This is needed so pwmd wont try to launch it's own pinentry on passphrase or confirmation failure. So you may need to reset this option manually depending on your needs; especially when changing pinentry methods when doing a save (the passphrase may be set as empty since the remote pinentry is disabled!).
46 Some pinentry options can also be specified in a 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. Each option and value is separated with a '=' on a single line. Unrecognized options are ignored. Here are the recognized options:
50 \fIPATH\fP The full path to the location of the pinentry binary.
52 \fIDISPLAY\fP The X11 display to use.
54 \fITTYNAME\fP The full path to the tty that pinentry should prompt on.
56 \fITTYTYPE\fP The terminal type of the tty which is required if DISPLAY is not set.
61 When the first character of a filename parameter is a tilde (~), it will be expanded to the home directory of the current user.
63 The initial values for the pinentry TTY, TERM and DISPLAY are set during \fBpwmd_new()\fP depending on the current environment. They may need to be reset as needed.
65 After establishing an SSH connection, the pwmd pinentry is disabled by sending the command 'SET ENABLE_PINENTRY=0'. This is needed because there currently isn't a way to have the remote pinentry use the local display. You must be careful to use either a local pinentry or set a passphrase manually with \fBpwmd_setopt()\fP when a passphrase is required or needed.
70 X11 port forwarding so a remote pinentry can use the local display.
80 libpwmd uses libgpg-error for all error codes. Some are user defined GPG_ERR_USER_N codes, but most are reused from the existing ones. Error codes can be described by using \fBpwmd_strerror()\fP, or the thread-safe \fBpwmd_strerror_r()\fP.
84 libgpg-error normally returns an error code as a bitmask of an error source and the actual error code. In order to simplify the result codes, libpwmd strips any error source from the error code before returning it.
95 .RI "struct \fBpwmd_fd_t\fP"
102 .RI "#define \fBLIBPWMD_VERSION\fP 0x603"
105 .RI "#define \fBLIBPWMD_VERSION_MAJOR\fP 6"
108 .RI "#define \fBLIBPWMD_VERSION_MINOR\fP 0"
111 .RI "#define \fBLIBPWMD_VERSION_PATCH\fP 3"
114 .RI "#define \fBLIBPWMD_VERSION_STR\fP '6.0.3-git'"
117 .RI "#define \fBPWMD_FD_READABLE\fP 0x01"
120 .RI "#define \fBPWMD_FD_WRITABLE\fP 0x02"
123 .RI "#define \fBEPWMD_NO_FILE\fP"
126 .RI "#define \fBEPWMD_LIBXML_ERROR\fP"
129 .RI "#define \fBEPWMD_FILE_MODIFIED\fP"
132 .RI "#define \fBEPWMD_MAX\fP"
139 .RI "typedef struct pwm_s \fBpwm_t\fP"
142 .RI "typedef gpg_error_t(* \fBpwmd_passphrase_cb_t\fP )(void *user, char **passphrase)"
145 .RI "typedef int(* \fBpwmd_status_cb_t\fP )(void *user, const char *line)"
148 .RI "typedef gpg_error_t(* \fBpwmd_inquire_cb_t\fP )(void *user, const char *cmd, gpg_error_t rc, char **data, size_t *len)"
151 .RI "typedef gpg_error_t(* \fBpwmd_knownhost_cb_t\fP )(void *user, const char *host, const char *key, size_t len)"
158 .RI "enum \fBpwmd_async_t\fP { \fBASYNC_INIT\fP, \fBASYNC_PROCESS\fP, \fBASYNC_DONE\fP }"
161 .RI "enum \fBpwmd_ip_version_t\fP { \fBPWMD_IP_ANY\fP, \fBPWMD_IPV4\fP, \fBPWMD_IPV6\fP }"
164 .RI "enum \fBpwmd_socket_t\fP { \fBPWMD_SOCKET_LOCAL\fP, \fBPWMD_SOCKET_SSH\fP }"
167 .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_CONFIRM\fP, \fBPWMD_PINENTRY_DEFAULT\fP, \fBPWMD_PINENTRY_CLOSE\fP }"
170 .RI "enum \fBpwmd_option_t\fP { \fBPWMD_OPTION_PASSPHRASE_CB\fP, \fBPWMD_OPTION_PASSPHRASE_DATA\fP, \fBPWMD_OPTION_PASSPHRASE\fP, \fBPWMD_OPTION_PINENTRY_TRIES\fP, \fBPWMD_OPTION_PINENTRY_PATH\fP, \fBPWMD_OPTION_PINENTRY_TTY\fP, \fBPWMD_OPTION_PINENTRY_TERM\fP, \fBPWMD_OPTION_PINENTRY_DISPLAY\fP, \fBPWMD_OPTION_PINENTRY_TITLE\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_STATUS_CB\fP, \fBPWMD_OPTION_STATUS_DATA\fP, \fBPWMD_OPTION_IP_VERSION\fP, \fBPWMD_OPTION_KNOWNHOST_CB\fP, \fBPWMD_OPTION_KNOWNHOST_DATA\fP, \fBPWMD_OPTION_INQUIRE_TOTAL\fP }"
177 .RI "LIBPWMD_API const char * \fBpwmd_version\fP ()"
180 .RI "LIBPWMD_API gpg_error_t \fBpwmd_init\fP (void)"
183 .RI "LIBPWMD_API \fBpwm_t\fP * \fBpwmd_new\fP (const char *name)"
186 .RI "LIBPWMD_API gpg_error_t \fBpwmd_connect\fP (\fBpwm_t\fP *pwm, const char *path)"
189 .RI "LIBPWMD_API gpg_error_t \fBpwmd_ssh_connect\fP (\fBpwm_t\fP *pwm, const char *host, int port, const char *identity, const char *user, const char *known_hosts)"
192 .RI "LIBPWMD_API gpg_error_t \fBpwmd_ssh_connect_async\fP (\fBpwm_t\fP *pwm, const char *host, int port, const char *identity, const char *user, const char *known_hosts)"
195 .RI "LIBPWMD_API gpg_error_t \fBpwmd_connect_url\fP (\fBpwm_t\fP *pwm, const char *url)"
198 .RI "LIBPWMD_API gpg_error_t \fBpwmd_connect_url_async\fP (\fBpwm_t\fP *pwm, const char *url)"
201 .RI "LIBPWMD_API gpg_error_t \fBpwmd_get_hostkey\fP (\fBpwm_t\fP *pwm, const char *host, int port, char **result)"
204 .RI "LIBPWMD_API gpg_error_t \fBpwmd_get_hostkey_async\fP (\fBpwm_t\fP *pwm, const char *host, int port)"
207 .RI "LIBPWMD_API gpg_error_t \fBpwmd_get_fds\fP (\fBpwm_t\fP *pwm, \fBpwmd_fd_t\fP *fds, int *n_fds)"
210 .RI "LIBPWMD_API gpg_error_t \fBpwmd_pending_line\fP (\fBpwm_t\fP *pwm)"
213 .RI "LIBPWMD_API gpg_error_t \fBpwmd_setopt\fP (\fBpwm_t\fP *pwm, \fBpwmd_option_t\fP opt,...)"
216 .RI "LIBPWMD_API gpg_error_t \fBpwmd_getpin\fP (\fBpwm_t\fP *pwm, const char *filename, char **result, \fBpwmd_pinentry_t\fP which)"
219 .RI "LIBPWMD_API gpg_error_t \fBpwmd_open\fP (\fBpwm_t\fP *pwm, const char *filename)"
222 .RI "LIBPWMD_API gpg_error_t \fBpwmd_open2\fP (\fBpwm_t\fP *pwm, const char *filename)"
225 .RI "LIBPWMD_API gpg_error_t \fBpwmd_open_async2\fP (\fBpwm_t\fP *pwm, const char *filename)"
228 .RI "LIBPWMD_API gpg_error_t \fBpwmd_open_async\fP (\fBpwm_t\fP *pwm, const char *filename)"
231 .RI "LIBPWMD_API \fBpwmd_async_t\fP \fBpwmd_process\fP (\fBpwm_t\fP *pwm, gpg_error_t *rc, char **result)"
234 .RI "LIBPWMD_API gpg_error_t \fBpwmd_save\fP (\fBpwm_t\fP *pwm)"
237 .RI "LIBPWMD_API gpg_error_t \fBpwmd_save2\fP (\fBpwm_t\fP *pwm)"
240 .RI "LIBPWMD_API gpg_error_t \fBpwmd_save_async2\fP (\fBpwm_t\fP *pwm)"
243 .RI "LIBPWMD_API gpg_error_t \fBpwmd_save_async\fP (\fBpwm_t\fP *pwm)"
246 .RI "LIBPWMD_API gpg_error_t \fBpwmd_command\fP (\fBpwm_t\fP *pwm, char **result, const char *cmd,...)"
249 .RI "LIBPWMD_API gpg_error_t \fBpwmd_command_ap\fP (\fBpwm_t\fP *pwm, char **result, const char *cmd, va_list ap)"
252 .RI "LIBPWMD_API gpg_error_t \fBpwmd_inquire\fP (\fBpwm_t\fP *pwm, const char *cmd, \fBpwmd_inquire_cb_t\fP func, void *user)"
255 .RI "LIBPWMD_API gpg_error_t \fBpwmd_disconnect\fP (\fBpwm_t\fP *pwm)"
258 .RI "LIBPWMD_API void \fBpwmd_close\fP (\fBpwm_t\fP *pwm)"
261 .RI "LIBPWMD_API gpg_error_t \fBpwmd_socket_type\fP (\fBpwm_t\fP *pwm, \fBpwmd_socket_t\fP *type)"
264 .RI "LIBPWMD_API void \fBpwmd_free\fP (void *ptr)"
267 .RI "LIBPWMD_API void * \fBpwmd_malloc\fP (size_t size)"
270 .RI "LIBPWMD_API void * \fBpwmd_calloc\fP (size_t nmemb, size_t size)"
273 .RI "LIBPWMD_API void * \fBpwmd_realloc\fP (void *ptr, size_t size)"
276 .RI "LIBPWMD_API char * \fBpwmd_strdup\fP (const char *str)"
279 .RI "LIBPWMD_API char * \fBpwmd_strdup_printf\fP (const char *fmt,...)"
282 .RI "LIBPWMD_API const char * \fBpwmd_strerror\fP (gpg_error_t code)"
285 .RI "LIBPWMD_API int \fBpwmd_strerror_r\fP (gpg_error_t code, char *buf, size_t size)"
288 .SH "Constant Details"
290 .SS "#define EPWMD_FILE_MODIFIED"
292 The data file has been modified. Rather than process the next command this error is returned to prevent overwriting new data which may have been saved by another client.
293 .SS "#define EPWMD_LIBXML_ERROR"
295 libxml2 error. This can be a memory allocation error or a parse error. The details of the error cannot be obtained with libpwmd. You'd have to connect to the pwmd socket and do the command directly to get the actual error.
296 .SS "#define EPWMD_MAX"
298 libgpg-error error code offset. If you use your own libgpg-error codes then this should be the base of them.
299 .SS "#define EPWMD_NO_FILE"
301 No data file has been opened. Some commands don't require an open data file but most do.
302 .SS "#define LIBPWMD_VERSION 0x603"
304 Version information. The version of this library.
305 .SS "#define LIBPWMD_VERSION_MAJOR 6"
307 Version information. The major release number of this library.
308 .SS "#define LIBPWMD_VERSION_MINOR 0"
310 Version information. The minor release number of this library.
311 .SS "#define LIBPWMD_VERSION_PATCH 3"
313 Version information. The patch level of this library.
314 .SS "#define LIBPWMD_VERSION_STR '6.0.3-git'"
316 Version information. A string representation of the version of this library.
317 .SS "#define PWMD_FD_READABLE 0x01"
319 For use with \fBpwmd_get_fds()\fP. Set when the file descriptor is readable.
320 .SS "#define PWMD_FD_WRITABLE 0x02"
322 For use with \fBpwmd_get_fds()\fP. Set when the file descriptor is writable.
323 .SH "Typedef Details"
327 libpwmd handle. When a handle is mentioned in this documentation it is a pointer of this type. A new handle is created with \fBpwmd_new()\fP.
328 .SS "\fBpwmd_inquire_cb_t\fP"
330 Send data to the pwmd server. This is a callback function that gets passed to \fBpwmd_inquire()\fP. It is used for sending data to the server for commands that need to reply to an INQUIRE server response (STORE and IMPORT). The reason for this callback is to let the client send as many bytes as it wants rather than the entire chunk 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.
334 \fIuser\fP The user data pointer passed to \fBpwmd_inquire()\fP.
336 \fIcmd\fP The same as the \fIcmd\fP argument to \fBpwmd_inquire()\fP.
338 \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.
340 \fIdata\fP The next chunk of data to send or NULL.
342 \fIlen\fP The length of \fIdata\fP or 0.
347 \fI0\fP There is more data to be sent.
349 \fIGPG_ERR_EOF\fP No need to call this function again, the current \fIline\fP is the last to send.
351 \fIcode\fP Any other error code which will terminate the INQUIRE.
356 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.
360 .SS "\fBpwmd_knownhost_cb_t\fP"
362 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.
366 \fIuser\fP User data which was set with \fBPWMD_OPTION_KNOWNHOST_DATA\fP.
368 \fIhost\fP The hostname as passed to the connecting function.
370 \fIkey\fP The raw host key. Note that this differs from the format returned from \fBpwmd_get_hostkey()\fP.
372 \fIlen\fP The host key length.
377 \fI0\fP Add the host key to the known hosts file.
379 \fIGPG_ERR_NOT_CONFIRMED\fP Do not add the host key and abort the connection.
384 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 considered verified.
393 .SS "\fBpwmd_passphrase_cb_t\fP"
395 Custom passphrase retrieval function. The value of the option \fBPWMD_OPTION_PASSPHRASE_CB\fP which is set with \fBpwmd_setopt()\fP.
399 \fIuser\fP A user data pointer which is set with \fBPWMD_OPTION_PASSPHRASE_DATA\fP.
401 \fIpassphrase\fP The passphrase which may be an empty string or NULL. It is not modified by libpwmd but must remain allocated for as long as it is needed.
406 0 on success or an error code which will cause a command to fail.
410 .SS "\fBpwmd_status_cb_t\fP"
412 Process status messages. The value of the option \fBPWMD_OPTION_STATUS_CB\fP which is set with \fBpwmd_setopt()\fP.
416 \fIuser\fP A user data pointer which is set with \fBPWMD_OPTION_STATUS_DATA\fP.
418 \fIline\fP The status message line received from the server.
423 0 on success or an error code which will cause a command to fail.
427 .SH "Enumeration Details"
429 .SS "enum \fBpwmd_async_t\fP"
431 Asynchronous return value. The return code of \fBpwmd_process()\fP which is used for all asynchronous commands.
436 \fB\fIASYNC_INIT \fP\fP
438 \fBFor internal use only.\fP
444 \fB\fIASYNC_PROCESS \fP\fP
445 \fBpwmd_process()\fP should be called again.
447 \fB\fIASYNC_DONE \fP\fP
448 The command has completed. The result code should be checked for an error.
449 .SS "enum \fBpwmd_ip_version_t\fP"
451 IP protocol version for remote SSH connections. The value of the option \fBPWMD_OPTION_IP_VERSION\fP which is set with \fBpwmd_setopt()\fP.
456 \fB\fIPWMD_IP_ANY \fP\fP
457 Try both IPv4 and IPv6 addresses. Note that IPv4 is tried first and that \fBPWMD_IP_ANY\fP only affects a hostname and not an IP address in the address specification.
459 \fB\fIPWMD_IPV4 \fP\fP
462 \fB\fIPWMD_IPV6 \fP\fP
464 .SS "enum \fBpwmd_option_t\fP"
466 libpwmd options. Options are set with \fBpwmd_setopt()\fP.
470 When the first character of a filename parameter is a tilde (~), it will be expanded to the home directory of the current user.
478 \fB\fIPWMD_OPTION_PASSPHRASE_CB \fP\fP
479 A custom passphrase retrieval function which, when set, will be used instead of \fBpinentry(1)\fP. This function will not be used if opening a file and the passphrase is cached on the server or the file is a new one. The value of this option should be a \fBpwmd_passphrase_cb_t\fP.
483 An empty string as the passphrase is allowed.
488 \fB\fIPWMD_OPTION_PASSPHRASE_DATA \fP\fP
489 User supplied data which is passed to the custom passphrase function.
491 \fB\fIPWMD_OPTION_PASSPHRASE \fP\fP
492 A string to use as the passphrase when doing an open or save. When not NULL, this option has precedence over \fBPWMD_OPTION_PASSPHRASE_CB\fP.
496 An empty string as the passphrase is allowed.
501 \fB\fIPWMD_OPTION_PINENTRY_TRIES \fP\fP
502 An integer value that specifies the number of tries before \fBpinentry(1)\fP will give up when opening a file with the wrong supplied passphrase. The default is 3.
506 This option has no effect when trying to save a file. The user must either cancel the pinentry causing the save to fail or enter the correct passphrase during passphrase confirmation.
511 \fB\fIPWMD_OPTION_PINENTRY_PATH \fP\fP
512 A character string value which specifies the full path of the \fBpinentry(1)\fP binary. For the local \fBpinentry(1)\fP method, the default is specified at compile time.
516 \fBPinentry Details\fP
521 \fB\fIPWMD_OPTION_PINENTRY_TTY \fP\fP
522 A 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.
526 \fBPinentry Details\fP
531 \fB\fIPWMD_OPTION_PINENTRY_TERM \fP\fP
532 A value which specifies the terminal type (e.g., vt100) that \fBpinentry(1)\fP will use when no X11 display is available.
536 \fBPinentry Details\fP
541 \fB\fIPWMD_OPTION_PINENTRY_DISPLAY \fP\fP
542 A value which specifies the X11 display that \fBpinentry(1)\fP will use.
546 X11 port forwarding so a remote pinentry can use the local display.
551 \fBPinentry Details\fP
556 \fB\fIPWMD_OPTION_PINENTRY_TITLE \fP\fP
557 A character string that \fBpinentry(1)\fP will use in it's dialog window.
559 \fB\fIPWMD_OPTION_PINENTRY_PROMPT \fP\fP
560 A character string that \fBpinentry(1)\fP will use in it's dialog window.
562 \fB\fIPWMD_OPTION_PINENTRY_DESC \fP\fP
563 A character string that \fBpinentry(1)\fP will use in it's dialog window.
565 \fB\fIPWMD_OPTION_PINENTRY_LC_CTYPE \fP\fP
566 For \fBpinentry(1)\fP localization.
568 \fB\fIPWMD_OPTION_PINENTRY_LC_MESSAGES \fP\fP
569 For \fBpinentry(1)\fP localization.
571 \fB\fIPWMD_OPTION_PINENTRY_TIMEOUT \fP\fP
572 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.
574 \fB\fIPWMD_OPTION_STATUS_CB \fP\fP
575 A function of type \fBpwmd_status_cb_t\fP that will process status messages received from the pwmd server.
577 \fB\fIPWMD_OPTION_STATUS_DATA \fP\fP
578 A user data pointer which is passed to the status message function.
580 \fB\fIPWMD_OPTION_IP_VERSION \fP\fP
581 The IP version of type \fBpwmd_ip_version_t\fP that \fBpwmd_ssh_connect()\fP and \fBpwmd_ssh_connect_async()\fP will use when connecting to the remote pwmd server. The default is \fBPWMD_IP_ANY\fP.
585 This option must be set before a connection is made when not the default.
590 \fB\fIPWMD_OPTION_KNOWNHOST_CB \fP\fP
591 A function to confirm an unknown host hash which wasn't found in the known hosts file.
600 \fB\fIPWMD_OPTION_KNOWNHOST_DATA \fP\fP
601 User supplied data which is passed to the known host function.
610 \fB\fIPWMD_OPTION_INQUIRE_TOTAL \fP\fP
611 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 set before each call to \fBpwmd_inquire()\fP.
615 During the INQUIRE, PWMD_OPTION_STATUS_CB is called after every ASSUAN_LINELENGTH bytes have been successfully transferred.
617 This is a libpwmd feature. pwmd itself does not send XFER status messages during an INQUIRE. Status messages can be parsed only when PWMD_OPTION_STATUS_CB is set.
621 .SS "enum \fBpwmd_pinentry_t\fP"
623 Local pinentry commands and not pwmd pinentry. For use with \fBpwmd_getpin()\fP.
628 \fB\fIPWMD_PINENTRY_OPEN \fP\fP
631 \fB\fIPWMD_PINENTRY_OPEN_FAILED \fP\fP
632 When opening a file failed.
634 \fB\fIPWMD_PINENTRY_SAVE \fP\fP
637 \fB\fIPWMD_PINENTRY_SAVE_CONFIRM \fP\fP
638 For passphrase confirmation.
640 \fB\fIPWMD_PINENTRY_CONFIRM \fP\fP
641 For confirmation of a user-defined prompt.
643 \fB\fIPWMD_PINENTRY_DEFAULT \fP\fP
644 For the default or user defined string set with \fBPWMD_OPTION_PINENTRY_DESC\fP.
646 \fB\fIPWMD_PINENTRY_CLOSE \fP\fP
647 To terminate the pinentry process created with \fBpwmd_getpin()\fP.
648 .SS "enum \fBpwmd_socket_t\fP"
650 The type of socket a handle is connected to. For use with \fBpwmd_socket_type()\fP.
655 \fB\fIPWMD_SOCKET_LOCAL \fP\fP
656 A local domain socket.
658 \fB\fIPWMD_SOCKET_SSH \fP\fP
659 An SSH connection over a TCP socket.
660 .SH "Function Details"
662 .SS "LIBPWMD_API void* pwmd_calloc (size_t nmemb, size_t size)"
664 A wrapper around calloc(). Like calloc(), but lets libpwmd keep track of the pointer.
668 \fInmemb\fP The number of elements to allocate.
670 \fIsize\fP The number of bytes to allocate.
675 A newly allocated pointer or NULL if there wasn't enough memory.
680 calloc(3), \fBpwmd_free()\fP
684 .SS "LIBPWMD_API void pwmd_close (\fBpwm_t\fP * pwm)"
686 Close a handle. This will close the connection to a pwmd server and free any resources associated with it.
700 \fBpwmd_disconnect()\fP, \fBpwmd_new()\fP
704 .SS "LIBPWMD_API gpg_error_t pwmd_command (\fBpwm_t\fP * pwm, char ** result, const char * cmd, ...)"
706 Send a command to the pwmd server. Sends 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. For commands that use an INQUIRE to send data to the server (STORE and IMPORT), \fBpwmd_inquire()\fP must be used and not this function.
712 \fIresult\fP The result of the command when successful which must be freed with \fBpwmd_free()\fP.
714 \fIcmd\fP The command to send and any following arguments.
719 0 on success or an error code.
724 Not all commands return a result.
728 .SS "LIBPWMD_API gpg_error_t pwmd_command_ap (\fBpwm_t\fP * pwm, char ** result, const char * cmd, va_list ap)"
730 Send a command to the pwmd server. Like \fBpwmd_command()\fP but uses an argument pointer instead.
736 \fIresult\fP The result of the command when successful which must be freed with \fBpwmd_free()\fP.
738 \fIcmd\fP The command to send.
740 \fIap\fP The arguments to \fIcmd\fP.
745 0 on success or an error code.
750 Not all commands return a result.
754 .SS "LIBPWMD_API gpg_error_t pwmd_connect (\fBpwm_t\fP * pwm, const char * path)"
756 Connect to a local pwmd server. Connects to a local unix domain socket.
762 \fIpath\fP The socket path to connect to. If NULL, then a default of \fI'~/.pwmd/socket'\fP will be used.
767 0 on success or an error code.
772 When the first character of a filename parameter is a tilde (~), it will be expanded to the home directory of the current user.
777 \fBpwmd_ssh_connect()\fP, \fBpwmd_ssh_connect_async()\fP, \fBpwmd_disconnect()\fP
781 .SS "LIBPWMD_API gpg_error_t pwmd_connect_url (\fBpwm_t\fP * pwm, const char * url)"
783 Establish a connection by parsing a URL. This allows for connecting to a pwmd server by parsing the given URL string. Whether the connection is to a remote or local server depends on the contents:
786 file://[path/to/local/socket]
790 ssh[46]://[username@]hostname[:port],identity,known_hosts
795 The parameters in square brackets are optional and if not specified then defaults will be used. If neither socket specification is matched, the \fIurl\fP is assumed to be a file://.
801 \fIurl\fP The string to parse.
806 When the first character of a filename parameter is a tilde (~), it will be expanded to the home directory of the current user.
811 0 on success or an error code.
816 \fBpwmd_socket_type()\fP, \fBpwmd_disconnect()\fP
820 .SS "LIBPWMD_API gpg_error_t pwmd_connect_url_async (\fBpwm_t\fP * pwm, const char * url)"
822 Establish a connection by parsing a URL (asynchronously). This allows for connecting to a pwmd server by parsing the given URL string. Whether the connection is to a remote or local server depends on the contents:
825 file://[path/to/local/socket]
829 ssh[46]://[username@]hostname[:port],identity,known_hosts
834 The parameters in square brackets are optional and if not specified then defaults will be used. If neither socket specification is matched, the \fIurl\fP is assumed to be a file://.
836 \fBpwmd_process()\fP should be called until the command completes.
842 \fIurl\fP The string to parse.
847 When the first character of a filename parameter is a tilde (~), it will be expanded to the home directory of the current user.
852 0 on success or an error code.
857 \fBpwmd_socket_type()\fP, \fBpwmd_disconnect()\fP
861 .SS "LIBPWMD_API gpg_error_t pwmd_disconnect (\fBpwm_t\fP * pwm)"
863 Close a connection to the pwmd server. This will close the connection but keep any previously set options for the specified handle.
872 0 on success or an error code.
881 .SS "LIBPWMD_API void pwmd_free (void * ptr)"
883 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.
885 The difference between the standard free() and this function is that this one will zero out the contents of the pointer before freeing it.
889 \fIptr\fP The pointer to deallocate.
899 \fBpwmd_malloc()\fP, \fBpwmd_calloc()\fP, \fBpwmd_realloc()\fP, \fBpwmd_strdup()\fP, \fBpwmd_process()\fP, \fBpwmd_command()\fP
903 .SS "LIBPWMD_API gpg_error_t pwmd_get_fds (\fBpwm_t\fP * pwm, \fBpwmd_fd_t\fP * fds, int * n_fds)"
905 Get the associated file descriptor(s) for a handle. This function lets the application manually poll the available file descriptors for the specified handle. It should be called after each asynchronous function call and after each call to \fBpwmd_process()\fP since the polled file descriptors may have been closed since the previous call.
907 After returning, \fIn_fds\fP is set to the number of available file descriptors which are stored in \fIfds\fP. The .flags member of \fBpwmd_fd_t\fP specifies what can be monitored and is a bitmask of \fBPWMD_FD_READABLE\fP and \fBPWMD_FD_WRITABLE\fP. When ready, \fBpwmd_process()\fP should be called.
913 \fIfds\fP Set to the file descriptor(s) of the associated handle.
915 \fIn_fds\fP Initially the size of \fIfds\fP then updated to the number of available file descriptors which are stored in \fIfds\fP.
920 \fI0\fP on success or an error code.
922 \fIGPG_ERR_ERANGE\fP There are more file descriptors than the amount specified in \fIn_fds\fP. \fIfds\fP and \fIn_fds\fP are still usable though.
931 .SS "LIBPWMD_API gpg_error_t pwmd_get_hostkey (\fBpwm_t\fP * pwm, const char * host, int port, char ** result)"
933 Retrieve a remote SSH public host key. This key is needed for host verification of the remote pwmd server. You should be sure that the remote host is really the host that your wanting to connect to and not subject to a man-in-the-middle attack.
939 \fIhost\fP The hostname or IP to connect to.
941 \fIport\fP The port or -1 for the default of 22.
943 \fIresult\fP An OpenSSH known hosts formatted string containing the servers public key which should be freed with \fBpwmd_free()\fP. If the \fIhost\fP was a hostname then two newline separated known host entries will be returned; one for the hostname and one for the resolved IP address. The IP known host entry will always be the second in the string.
948 0 on success or an error code.
953 6.0.3 The connection is kept open but not verified after returning. It can be resumed from one of the SSH connection functions.
958 \fBpwmd_get_hostkey_async()\fP, \fBpwmd_ssh_connect()\fP, \fBSSH Details\fP
962 .SS "LIBPWMD_API gpg_error_t pwmd_get_hostkey_async (\fBpwm_t\fP * pwm, const char * host, int port)"
964 Retrieve a remote SSH host key (asynchronously). This key is needed for host verification of the remote pwmd server. You should be sure that the remote host is really the host that your wanting to connect to and not subject to a man-in-the-middle attack.
966 \fBpwmd_process()\fP should be called until the command completes.
972 \fIhost\fP The hostname or IP to connect to.
974 \fIport\fP The port or -1 for the default of 22.
979 0 on success or an error code. The result is obtained from \fBpwmd_process()\fP should be freed with \fBpwmd_free()\fP. It has the same format as the result from \fBpwmd_get_hostkey()\fP.
984 6.0.3 The connection is kept open but not verified after returning. It can be resumed from one of the SSH connection functions.
989 \fBpwmd_get_hostkey()\fP, \fBpwmd_ssh_connect_async()\fP, \fBpwmd_process()\fP, \fBSSH Details\fP
993 .SS "LIBPWMD_API gpg_error_t pwmd_getpin (\fBpwm_t\fP * pwm, const char * filename, char ** result, \fBpwmd_pinentry_t\fP which)"
995 Launch a local pinentry. Does not send any command to the server. Maybe useful if a passphrase is needed before opening a file over a remote connection. This passphrase can then be set with \fBpwmd_setopt()\fP.
997 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_TITLE\fP.
1003 \fIfilename\fP The filename to use in the pinentry dialog strings.
1005 \fIresult\fP The entered value in the pinentry dialog which should be freed with \fBpwmd_free()\fP.
1007 \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_DEFAULT\fP should be used. \fBPWMD_PINENTRY_CLOSE\fP should be used to terminate the pinentry process when the pinentry is no longer needed.
1012 0 on success or an error.
1016 .SS "LIBPWMD_API gpg_error_t pwmd_init (void)"
1018 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.
1022 0 on success or an error code.
1026 .SS "LIBPWMD_API gpg_error_t pwmd_inquire (\fBpwm_t\fP * pwm, const char * cmd, \fBpwmd_inquire_cb_t\fP func, void * user)"
1028 Send data to a pwmd server. This lets commands that use an INQUIRE (STORE and IMPORT) send the data to the server. Use this function rather than \fBpwmd_command()\fP for these pwmd commands.
1034 \fIcmd\fP The command (without arguments) to send that uses an INQUIRE.
1036 \fIfunc\fP A callback function of type \fBpwmd_inquire_cb_t\fP which sets the data to be sent.
1038 \fIuser\fP A user data pointer passed to the callback function \fIfunc\fP.
1043 0 on success or an error code.
1048 \fBpwmd_inquire_cb_t\fP
1052 .SS "LIBPWMD_API void* pwmd_malloc (size_t size)"
1054 A wrapper around malloc. Like malloc(), but lets libpwmd keep track of the pointer.
1058 \fIsize\fP The number of bytes to allocate.
1063 A newly allocated pointer or NULL if there wasn't enough memory.
1068 malloc(3), \fBpwmd_free()\fP
1072 .SS "LIBPWMD_API \fBpwm_t\fP* pwmd_new (const char * name)"
1074 Creates a new handle. Creates a new handle for use with the other functions.
1078 \fIname\fP If not NULL, the name of the application. The application name is sent to the pwmd server after successfully connecting.
1083 a new handle or NULL if there was not enough memory.
1087 .SS "LIBPWMD_API gpg_error_t pwmd_open (\fBpwm_t\fP * pwm, const char * filename)"
1089 Open a file on the pwmd server. This will send the OPEN command to the server.
1095 \fIfilename\fP The filename to open. The \fIfilename\fP is not a full path but the data file only.
1100 0 on success or an error code.
1105 \fBPinentry Details\fP
1109 .SS "LIBPWMD_API gpg_error_t pwmd_open2 (\fBpwm_t\fP * pwm, const char * filename)"
1111 Open a file on the pwmd server using a local pinentry. This will send the OPEN command to the server like \fBpwmd_open()\fP but will use the local pinentry and not pwmd's pinentry.
1115 This function will catch SIGALRM during the lifetime of the pinentry process and set it to SIG_DFL when finished. This is needed for pinentry timeouts.
1117 This pinentry method is not thread safe. It needs to set a couple of global variables for the pinentry timeout to work properly.
1124 \fIfilename\fP The filename to open. The \fIfilename\fP is not a full path but the data file only.
1129 0 on success or an error code.
1132 \fBReturn values:\fP
1134 \fIGPG_ERR_PIN_BLOCKED\fP Another handle is using the local pinentry.
1139 \fBPinentry Details\fP
1143 .SS "LIBPWMD_API gpg_error_t pwmd_open_async (\fBpwm_t\fP * pwm, const char * filename)"
1145 Open a file on the pwmd server (asynchronously). This will send the OPEN command to the pwmd server. The difference from \fBpwmd_open()\fP is that it will not block if a pinentry is needed for passphrase input.
1147 \fBpwmd_process()\fP should be called until the command completes.
1153 \fIfilename\fP The filename to open. The \fIfilename\fP is not a full path but the data file only.
1158 0 on success or an error code.
1163 \fBpwmd_process()\fP, \fBPinentry Details\fP
1167 .SS "LIBPWMD_API gpg_error_t pwmd_open_async2 (\fBpwm_t\fP * pwm, const char * filename)"
1169 Open a file on the pwmd server asynchronously (fork method). This is kind of a hybrid of \fBpwmd_open2()\fP and \fBpwmd_open_async()\fP. It will use the local pinentry asynchronously and also do the OPEN command asynchronously.
1171 \fBpwmd_process()\fP should be called until the command completes.
1175 This function will catch SIGALRM during the lifetime of the pinentry process and set it to SIG_DFL when finished. This is needed for pinentry timeouts.
1182 \fIfilename\fP The filename to open. The \fIfilename\fP is not a full path but the data file only.
1187 0 on success or an error code.
1192 \fBpwmd_process()\fP, \fBPinentry Details\fP
1196 .SS "LIBPWMD_API gpg_error_t pwmd_pending_line (\fBpwm_t\fP * pwm)"
1198 Check for a unparsed buffered line. A buffered line is a line that was read from the server but has not yet been processed. This function determines if there is such a line.
1205 \fBReturn values:\fP
1207 \fI0\fP if there is a pending line.
1209 \fIGPG_ERR_NO_DATA\fP if there is no pending line.
1214 \fBpwmd_process()\fP
1218 .SS "LIBPWMD_API \fBpwmd_async_t\fP pwmd_process (\fBpwm_t\fP * pwm, gpg_error_t * rc, char ** result)"
1220 Process an asynchronous function. After an asynchronous function has been called and has returned successfully, this function must be called to process the command and retrieve the result and return value.
1222 This function may also be called when not in a command to check for pending status messages sent from the server or to process a pending line.
1228 \fIrc\fP Set to the return code of the original command after ASYNC_DONE has been returned. This value must be checked to determine if the command succeeded.
1230 \fIresult\fP Set to the result of the command when \fIrc\fP is 0. Note that not all commands return a result.
1233 \fBReturn values:\fP
1235 \fIASYNC_DONE\fP The command has completed. \fIrc\fP should be checked to determine if the command was successful or not.
1237 \fIASYNC_PROCESS\fP The command is still running and this function should be called again.
1242 \fBpwmd_get_fds()\fP, \fBpwmd_pending_line()\fP
1246 .SS "LIBPWMD_API void* pwmd_realloc (void * ptr, size_t size)"
1248 A wrapper around realloc(). Like realloc(), but lets libpwmd keep track of the pointer.
1252 This function will try and allocate the entire \fIsize\fP before freeing the original pointer and returning the new one.
1257 \fIptr\fP The pointer to reallocate.
1259 \fIsize\fP The new number of bytes to allocate.
1264 A newly allocated pointer or NULL if there wasn't enough memory.
1269 realloc(3), \fBpwmd_free()\fP
1273 .SS "LIBPWMD_API gpg_error_t pwmd_save (\fBpwm_t\fP * pwm)"
1275 Save a file on the pwmd server. This will send the SAVE command.
1284 0 on success or an error code.
1289 \fBPinentry Details\fP
1293 .SS "LIBPWMD_API gpg_error_t pwmd_save2 (\fBpwm_t\fP * pwm)"
1295 Save a file on the pwmd server using the local pinentry. This will send the SAVE command like \fBpwmd_save()\fP but will use a local pinentry and not pwmd's pinentry.
1304 0 on success or an error code.
1309 \fBPinentry Details\fP
1313 .SS "LIBPWMD_API gpg_error_t pwmd_save_async (\fBpwm_t\fP * pwm)"
1315 Save changes to a file on the pwmd server (asynchronously). This will send the SAVE command to the pwmd server. The difference from \fBpwmd_save()\fP is that it will not block if a pinentry is needed for passphrase input.
1317 \fBpwmd_process()\fP should be called until the command completes.
1326 0 on success or an error code.
1331 \fBpwmd_process()\fP, \fBPinentry Details\fP
1335 .SS "LIBPWMD_API gpg_error_t pwmd_save_async2 (\fBpwm_t\fP * pwm)"
1337 Save a file on the pwmd server asynchronously (fork method). This is kind of a hybrid of \fBpwmd_save2()\fP and \fBpwmd_save_async()\fP. It will use the local pinentry asynchronously and also do the SAVE command asynchronously.
1339 \fBpwmd_process()\fP should be called until the command completes.
1348 0 on success or an error code.
1353 \fBpwmd_process()\fP, \fBPinentry Details\fP
1357 .SS "LIBPWMD_API gpg_error_t pwmd_setopt (\fBpwm_t\fP * pwm, \fBpwmd_option_t\fP opt, ...)"
1359 Set handle options. See \fBpwmd_option_t\fP for option specific details.
1365 \fIopt\fP The option and following value.
1370 0 on success or an error code.
1374 .SS "LIBPWMD_API gpg_error_t pwmd_socket_type (\fBpwm_t\fP * pwm, \fBpwmd_socket_t\fP * type)"
1376 The type of connection a handle has. Useful when you want to know what kind of connection a handle has.
1382 \fItype\fP The type of socket.
1387 0 on success or an error code.
1392 \fBpwmd_connect_url()\fP
1396 .SS "LIBPWMD_API gpg_error_t pwmd_ssh_connect (\fBpwm_t\fP * pwm, const char * host, int port, const char * identity, const char * user, const char * known_hosts)"
1398 Establish a remote connection to a pwmd server. Connects to a pwmd server over an SSH channel.
1404 \fIhost\fP The hostname to connect to or NULL to resume a connection previously started with \fBpwmd_get_hostkey()\fP.
1406 \fIport\fP The port or -1 for the default of 22.
1408 \fIidentity\fP The SSH identity file to use for authentication. This should specify the private key. The public key is assumed to be \fIidentity.pub\fP.
1410 \fIuser\fP The username on the SSH server to login as. If NULL then invoking username will be used.
1412 \fIknown_hosts\fP An OpenSSH known hosts formatted file containing public SSH server hashes which may be obtained with \fBpwmd_get_hostkey()\fP or via \fBpwmd_knownhost_cb_t\fP during a connection. If NULL, the default of \fI'~/.ssh/known_hosts'\fP will be used.
1417 0 on success or an error code.
1422 When the first character of a filename parameter is a tilde (~), it will be expanded to the home directory of the current user.
1427 \fBpwmd_ssh_connect_async()\fP, \fBPWMD_OPTION_IP_VERSION\fP, \fBpwmd_disconnect()\fP, \fBSSH Details\fP
1431 .SS "LIBPWMD_API gpg_error_t pwmd_ssh_connect_async (\fBpwm_t\fP * pwm, const char * host, int port, const char * identity, const char * user, const char * known_hosts)"
1433 Establish a remote connection to a pwmd server (asynchronously). This is a variant of \fBpwmd_ssh_connect()\fP that will not block while doing DNS lookups or while connecting.
1435 \fBpwmd_process()\fP should be called until the command completes.
1441 \fIhost\fP The hostname to connect to or NULL to resume a connection previously started with \fBpwmd_get_hostkey()\fP.
1443 \fIport\fP The port or -1 for the default of 22.
1445 \fIidentity\fP The SSH identity file to use for authentication. This should specify the private key. The public key is assumed to be \fIidentity.pub\fP.
1447 \fIuser\fP The username on the SSH server to login as. If NULL, the invoking username will be used.
1449 \fIknown_hosts\fP An OpenSSH known hosts formatted file containing public SSH server hashes which may be obtained with \fBpwmd_get_hostkey()\fP or via \fBpwmd_knownhost_cb_t\fP during a connection. If NULL, the default of \fI'~/.ssh/known_hosts'\fP will be used.
1454 0 on success or an error code.
1459 When the first character of a filename parameter is a tilde (~), it will be expanded to the home directory of the current user.
1464 \fBpwmd_process()\fP, \fBPWMD_OPTION_IP_VERSION\fP, \fBpwmd_disconnect()\fP, \fBSSH Details\fP
1468 .SS "LIBPWMD_API char* pwmd_strdup (const char * str)"
1470 A wrapper around strdup(). Like strdup(), but lets libpwmd keep track of the pointer.
1474 \fIstr\fP The string to duplicate.
1479 A newly allocated character pointer or NULL if there wasn't enough memory.
1484 strdup(3), \fBpwmd_free()\fP
1488 .SS "LIBPWMD_API char* pwmd_strdup_printf (const char * fmt, ...)"
1490 Duplicate a formatted string. Like \fBsprintf(3)\fP but returns an allocated string.
1494 \fIfmt\fP The formatted string and any following arguments.
1499 A newly allocated character pointer or NULL if there wasn't enough memory.
1508 .SS "LIBPWMD_API const char* pwmd_strerror (gpg_error_t code)"
1510 Return a description of an error code. \fBParameters:\fP
1512 \fIcode\fP The error code to describe.
1517 A character description of the error code.
1522 \fBpwmd_strerror_r()\fP
1526 .SS "LIBPWMD_API int pwmd_strerror_r (gpg_error_t code, char * buf, size_t size)"
1528 Return a description of an error code (thread-safe). This is a thread-safe version of \fBpwmd_strerror()\fP.
1532 \fIcode\fP The error code to describe.
1534 \fIbuf\fP An allocated buffer to hold the error description.
1536 \fIsize\fP The size of the allocated buffer \fIbuf\fP.
1539 \fBReturn values:\fP
1543 \fIERANGE\fP \fIsize\fP was not large enough to hold the entire description and \fIbuf\fP is set to the truncated error string.
1547 .SS "LIBPWMD_API const char* pwmd_version ()"
1549 Returns this version of libpwmd. As a string.
1552 Generated automatically by Doxygen for libpwmd from the source code.