1 .TH "libpwmd.h" 3 "Tue May 29 2012" "Version 7.0.0" "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 3\&.0 or later is required; either locally or remotely\&.
11 \fBlibpwmd\fP should be thread-safe on a per handle bases\&. Meaning that only one thread should access a \fBpwm_t\fP handle at a time\&.
12 .SH "Remote Connection Details"
14 There are two methods of connecting to a remote pwmd server: an SSH channel, or over TLS\&. Connections over SSH are less reliable than TLS connections since a proxy program is needed to connect to the pwmd UNIX Domain Socket\&. The kernel that pwmd runs under may buffer the UDS data before it reaches the proxy program and there isn't a portable way to modify kernel buffer settings\&. For larger transfers of data this is noticeable by the hanging of the command that initiated the transfer\&.
16 If you really do need an SSH connection you can do so by using an SSH channel to spawn a shell that executes a proxy server to connect to the pwmd local Unix Domain Socket\&. Authentication is done by using SSH public key (see \fBssh-keygen(1)\fP) authentication and verifying the host key against a local OpenSSH known hosts formatted file\&.
18 An unknown servers public key can be added to a known hosts file after user confirmation by setting the callback function \fBpwmd_knownhost_cb_t\fP before connecting to the unknown host\&.
20 On the server side you'll need a proxy server to connect to the pwmd server\&. Below is an example of an \fBauthorized_keys(5)\fP entry that will do this\&. The \fIpublic_key\fP portion should be the same as the contents of the \fBssh-keygen(1)\fP \fIidentity\&.pub\fP file generated on the client machine\&. The private key should be passed as the \fIidentity\fP parameter to \fBpwmd_connect()\fP:
24 command='socat UNIX-CONNECT:$HOME/\&.pwmd/socket -' <public_key> \&.\&.\&.
30 Only an SSH identity without a passphrase is supported\&. For now anyway\&. This is a limitation of libssh2 (version 1\&.2\&.8 as of this writing)\&.
35 6\&.0\&.3 The first version to use the OpenSSH known hosts file format exclusively\&. Earlier versions used only an SHA1 hash of the host key\&.
38 As mentioned, TLS connections are more reliable since there is no proxy program needed to connect to the pwmd server\&. pwmd itself can accept TLS connections and like SSH connections they are created with \fBpwmd_connect()\fP\&. You'll need to generate a client key and X509 certificate then sign it with the same certificate authority (CA) that the pwmd server certificate was signed with\&.
40 Certificates are similar to SSH public and private keys but a little harder to get setup correctly\&. See the \fBcerttool(1)\fP (recommended) and \fBopenssl(1)\fP manual pages for details\&.
41 .SH "Pinentry Details"
43 \fBpinentry(1)\fP is a program that prompts the user for input which is normally a passphrase or a confirmation\&. libpwmd can use this program either locally (X11 forwarding is not yet supported) or have the pwmd server (really gpg-agent) use it's pinentry to retrieve a passphrase when needed\&.
45 There are a few options that tell pinentry how and where to prompt for a needed passphrase\&. See the \fBpwmd_option_t\fP section for details\&. These options are only sent to pwmd in \fBpwmd_open()\fP and only when pinentry use has not been disabled and when not over an remote connnection\&.
47 Some pinentry options may also be specified in the local configuration file \fI'~/\&.pwmd/pinentry\&.conf'\fP\&. These options are initial values for each pinentry invokation (not retries) and may be changed by setting the appropriate \fBpwmd_option_t\fP\&. Options and values are separated with a '=' on a single line\&. Unrecognized options are ignored\&. Here are the recognized options:
51 \fIPATH\fP The full path to the location of the pinentry binary\&. Only useful for the local pinentry\&.
53 \fIDISPLAY\fP The X11 display to use\&.
55 \fITTYNAME\fP The full path to the tty that pinentry should prompt on\&.
57 \fITTYTYPE\fP The terminal type of the tty which is required if DISPLAY is not set\&.
59 \fILC_MESSAGES\fP Adjust for the current locale\&.
61 \fILC_CTYPE\fP Adjust for the current locale\&.
66 When the first character of a filename parameter is a tilde (~), it will be expanded to the home directory of the current user\&.
68 The initial values for the pinentry TTY, TERM and DISPLAY are set during \fBpwmd_new()\fP depending on the current environment\&. They can be reset or changed as needed\&.
70 After establishing an remote connection, pwmd's pinentry is disabled by passing the '--no-pinentry' option to the OPEN protocol command during \fBpwmd_open()\fP since X11 forwarding has not been implemented\&. A local pinentry will be used in the case of a remote connection\&.
75 \fBRemote Connection Details\fP
80 libpwmd uses libgpg-error for all error codes\&. Error codes can be described by using \fBgpg_strerror()\fP, or the thread-safe \fBgpg_strerror_r()\fP\&.
84 libgpg-error returns an error code as a bitmask of an error source and the error code\&. Determining the error source can help you find where the error occured, beit from \fBpinentry(1)\fP, \fBgpg-agent(1)\fP, \fBlibgcrypt\fP, \fBpwmd(1)\fP or \fBlibpwmd(3)\fP\&. pwmd uses the \fBGPG_ERR_SOURCE_USER_1\fP error source and libpwmd uses \fBGPG_ERR_SOURCE_USER_2\fP\&. To find the error source of an error code the \fBgpg-error(1)\fP command line utility may be of use\&. Also see the \fBlibgpg-error\fP documentation for error code manipulation\&.
95 .RI "#define \fBLIBPWMD_API\fP"
98 .RI "#define \fBGPG_ERR_SOURCE_DEFAULT\fP GPG_ERR_SOURCE_USER_2"
101 .RI "#define \fBLIBPWMD_VERSION\fP 0x070000"
104 .RI "#define \fBLIBPWMD_VERSION_MAJOR\fP 7"
107 .RI "#define \fBLIBPWMD_VERSION_MINOR\fP 0"
110 .RI "#define \fBLIBPWMD_VERSION_PATCH\fP 0"
113 .RI "#define \fBLIBPWMD_VERSION_STR\fP '7\&.0\&.0-dev'"
116 .RI "#define \fBPWMD_FEATURE_PINENTRY\fP"
119 .RI "#define \fBPWMD_FEATURE_CRACK\fP"
122 .RI "#define \fBPWMD_FEATURE_SSH\fP"
125 .RI "#define \fBPWMD_FEATURE_GNUTLS\fP"
132 .RI "typedef struct pwm_s \fBpwm_t\fP"
135 .RI "typedef gpg_error_t(* \fBpwmd_status_cb_t\fP )(void *user, const char *line)"
138 .RI "typedef gpg_error_t(* \fBpwmd_inquire_cb_t\fP )(void *user, const char *keyword, gpg_error_t rc, char **data, size_t *len)"
141 .RI "typedef gpg_error_t(* \fBpwmd_knownhost_cb_t\fP )(void *user, const char *host, const char *hostkey, size_t len)"
148 .RI "enum \fBpwmd_socket_t\fP { \fBPWMD_SOCKET_LOCAL\fP, \fBPWMD_SOCKET_SSH\fP, \fBPWMD_SOCKET_TLS\fP }"
151 .RI "enum \fBpwmd_pinentry_t\fP { \fBPWMD_PINENTRY_OPEN\fP, \fBPWMD_PINENTRY_OPEN_FAILED\fP, \fBPWMD_PINENTRY_SAVE\fP, \fBPWMD_PINENTRY_SAVE_CONFIRM\fP, \fBPWMD_PINENTRY_SAVE_FAILED\fP, \fBPWMD_PINENTRY_CONFIRM\fP, \fBPWMD_PINENTRY_USER\fP, \fBPWMD_PINENTRY_CLOSE\fP }"
154 .RI "enum \fBpwmd_option_t\fP { \fBPWMD_OPTION_PINENTRY_PATH\fP, \fBPWMD_OPTION_PINENTRY_TTY\fP, \fBPWMD_OPTION_PINENTRY_TERM\fP, \fBPWMD_OPTION_PINENTRY_DISPLAY\fP, \fBPWMD_OPTION_PINENTRY_ERROR\fP, \fBPWMD_OPTION_PINENTRY_PROMPT\fP, \fBPWMD_OPTION_PINENTRY_DESC\fP, \fBPWMD_OPTION_PINENTRY_LC_CTYPE\fP, \fBPWMD_OPTION_PINENTRY_LC_MESSAGES\fP, \fBPWMD_OPTION_PINENTRY_TIMEOUT\fP, \fBPWMD_OPTION_PINENTRY_TRIES\fP, \fBPWMD_OPTION_STATUS_CB\fP, \fBPWMD_OPTION_STATUS_DATA\fP, \fBPWMD_OPTION_KNOWNHOST_CB\fP, \fBPWMD_OPTION_KNOWNHOST_DATA\fP, \fBPWMD_OPTION_INQUIRE_TOTAL\fP, \fBPWMD_OPTION_LOCK_ON_OPEN\fP, \fBPWMD_OPTION_SSH_AGENT\fP, \fBPWMD_OPTION_NO_PINENTRY\fP, \fBPWMD_OPTION_LOCAL_PINENTRY\fP, \fBPWMD_OPTION_OVERRIDE_INQUIRE\fP, \fBPWMD_OPTION_SSH_TIMEOUT\fP, \fBPWMD_OPTION_SSH_KEEPALIVE\fP, \fBPWMD_OPTION_TLS_VERIFY\fP }"
161 .RI "LIBPWMD_API const char * \fBpwmd_version\fP ()"
164 .RI "LIBPWMD_API unsigned int \fBpwmd_features\fP ()"
167 .RI "LIBPWMD_API gpg_error_t \fBpwmd_init\fP (void)"
170 .RI "LIBPWMD_API void \fBpwmd_deinit\fP (void)"
173 .RI "LIBPWMD_API gpg_error_t \fBpwmd_new\fP (const char *name, \fBpwm_t\fP **pwm)"
176 .RI "LIBPWMD_API gpg_error_t \fBpwmd_connect\fP (\fBpwm_t\fP *pwm, const char *url,\&.\&.\&.)"
179 .RI "LIBPWMD_API gpg_error_t \fBpwmd_setopt\fP (\fBpwm_t\fP *pwm, \fBpwmd_option_t\fP opt,\&.\&.\&.)"
182 .RI "LIBPWMD_API gpg_error_t \fBpwmd_getpin\fP (\fBpwm_t\fP *pwm, const char *filename, char **result, size_t *len, \fBpwmd_pinentry_t\fP which)"
185 .RI "LIBPWMD_API gpg_error_t \fBpwmd_password\fP (\fBpwm_t\fP *pwm, const char *keyword, char **data, size_t *size)"
188 .RI "LIBPWMD_API gpg_error_t \fBpwmd_open\fP (\fBpwm_t\fP *pwm, const char *filename, \fBpwmd_inquire_cb_t\fP callback, void *data)"
191 .RI "LIBPWMD_API gpg_error_t \fBpwmd_process\fP (\fBpwm_t\fP *pwm)"
194 .RI "LIBPWMD_API gpg_error_t \fBpwmd_save\fP (\fBpwm_t\fP *pwm, const char *args, \fBpwmd_inquire_cb_t\fP callback, void *user)"
197 .RI "LIBPWMD_API gpg_error_t \fBpwmd_command\fP (\fBpwm_t\fP *pwm, char **result, size_t *len, \fBpwmd_inquire_cb_t\fP callback, void *user, const char *cmd,\&.\&.\&.)"
200 .RI "LIBPWMD_API gpg_error_t \fBpwmd_command_ap\fP (\fBpwm_t\fP *pwm, char **result, size_t *len, \fBpwmd_inquire_cb_t\fP callback, void *user, const char *cmd, va_list ap)"
203 .RI "LIBPWMD_API gpg_error_t \fBpwmd_disconnect\fP (\fBpwm_t\fP *pwm)"
206 .RI "LIBPWMD_API void \fBpwmd_close\fP (\fBpwm_t\fP *pwm)"
209 .RI "LIBPWMD_API gpg_error_t \fBpwmd_socket_type\fP (\fBpwm_t\fP *pwm, \fBpwmd_socket_t\fP *type)"
212 .RI "LIBPWMD_API gpg_error_t \fBpwmd_fd\fP (\fBpwm_t\fP *pwm, int *fd)"
215 .RI "LIBPWMD_API void \fBpwmd_free\fP (void *ptr)"
218 .RI "LIBPWMD_API void * \fBpwmd_malloc\fP (size_t size)"
221 .RI "LIBPWMD_API void * \fBpwmd_calloc\fP (size_t nmemb, size_t size)"
224 .RI "LIBPWMD_API void * \fBpwmd_realloc\fP (void *ptr, size_t size)"
227 .RI "LIBPWMD_API char * \fBpwmd_strdup\fP (const char *str)"
230 .RI "LIBPWMD_API char * \fBpwmd_strdup_printf\fP (const char *fmt,\&.\&.\&.)"
233 .RI "void \fBgnutls_global_set_mem_functions\fP (void *(*)(size_t), void *(*)(size_t), int(*)(const void *), void *(*)(void *, size_t), void(*)(void *))"
236 .SH "Constant Details"
238 .SS "#define \fBLIBPWMD_VERSION\fP 0x070000"
240 Version information\&. The version of this library\&.
241 .SS "#define \fBLIBPWMD_VERSION_MAJOR\fP 7"
243 Version information\&. The major release number of this library\&.
244 .SS "#define \fBLIBPWMD_VERSION_MINOR\fP 0"
246 Version information\&. The minor release number of this library\&.
247 .SS "#define \fBLIBPWMD_VERSION_PATCH\fP 0"
249 Version information\&. The patch level of this library\&.
250 .SS "#define \fBLIBPWMD_VERSION_STR\fP '7\&.0\&.0-dev'"
252 Version information\&. A string representation of the version of this library\&.
253 .SS "#define \fBPWMD_FEATURE_CRACK\fP"
255 Password quality checking\&. A password quality meter is shown when the pinentry supports it\&.
256 .SS "#define \fBPWMD_FEATURE_GNUTLS\fP"
258 Remote connections over TLS\&. \fBSee also:\fP
260 \fBRemote Connection Details\fP
264 .SS "#define \fBPWMD_FEATURE_PINENTRY\fP"
266 Pinentry support\&. This is for a local or fork()'ed pinentry\&.
267 .SS "#define \fBPWMD_FEATURE_SSH\fP"
269 Remote connections over an SSH channel\&. \fBSee also:\fP
271 \fBRemote Connection Details\fP
275 .SH "Typedef Details"
279 libpwmd handle\&. When a handle or context is mentioned in this documentation it is a pointer of this type\&. A new handle is created with \fBpwmd_new()\fP\&.
280 .SS "\fBpwmd_inquire_cb_t\fP"
282 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\&.
286 \fIuser\fP The user data pointer passed to the libpwmd function specifying this callback\&.
288 \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\&.
290 \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\&.
292 \fIdata\fP The next chunk of data to send or NULL\&.
294 \fIlen\fP The length of \fIdata\fP or 0\&.
299 \fI0\fP There is more data to be sent\&.
301 \fIGPG_ERR_EOF\fP No need to call this function again, the current \fIdata\fP is the last to send\&.
303 \fIcode\fP Any other error code which will cancel the INQUIRE\&.
308 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\&.
312 .SS "\fBpwmd_knownhost_cb_t\fP"
314 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\&.
318 \fIuser\fP User data which was set with \fBPWMD_OPTION_KNOWNHOST_DATA\fP\&.
320 \fIhost\fP The hostname as passed to \fBpwmd_connect()\fP\&.
322 \fIhostkey\fP The raw binary data of the host key\&.
324 \fIlen\fP The length of \fIhostkey\fP\&.
329 \fI0\fP Add the host key to the known hosts file\&.
331 \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\&.
336 If the known hosts file cannot be modified do to filesystem restrictions when trying to add the new host key, no error is returned\&. Instead, the host key is added to the current connections host key cache and the connection is accepted\&.
341 \fBRemote Connection Details\fP
345 .SS "\fBpwmd_status_cb_t\fP"
347 Process status messages\&. The value of the option \fBPWMD_OPTION_STATUS_CB\fP which is set with \fBpwmd_setopt()\fP\&.
351 \fIuser\fP A user data pointer which is set with \fBPWMD_OPTION_STATUS_DATA\fP\&.
353 \fIline\fP The status message line received from the server\&.
358 0 on success or an error code which will cause a command to fail\&.
362 .SH "Enumeration Details"
364 .SS "enum \fBpwmd_option_t\fP"
366 libpwmd options\&. Options are set with \fBpwmd_setopt()\fP\&. Some options must be set before a connection is made to have any effect\&.
370 When the first character of a filename parameter is a tilde (~), it will be expanded to the home directory of the current user\&.
378 \fB\fIPWMD_OPTION_PINENTRY_PATH \fP\fP
379 A string value which specifies the full path of the \fBpinentry(1)\fP binary\&. The default is specified at compile time\&.
383 This only affects the local pinentry\&.
388 \fBPinentry Details\fP
393 \fB\fIPWMD_OPTION_PINENTRY_TTY \fP\fP
394 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\&.
398 \fBPinentry Details\fP
403 \fB\fIPWMD_OPTION_PINENTRY_TERM \fP\fP
404 A string value which specifies the terminal type (i\&.e\&., vt100) that \fBpinentry(1)\fP will use when no X11 display is available\&.
408 \fBPinentry Details\fP
413 \fB\fIPWMD_OPTION_PINENTRY_DISPLAY \fP\fP
414 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\&.
418 \fBPinentry Details\fP
423 \fB\fIPWMD_OPTION_PINENTRY_ERROR \fP\fP
424 A character string that \fBpinentry(1)\fP will use in it's dialog window\&.
426 \fB\fIPWMD_OPTION_PINENTRY_PROMPT \fP\fP
427 A character string that \fBpinentry(1)\fP will use in it's dialog window\&.
429 \fB\fIPWMD_OPTION_PINENTRY_DESC \fP\fP
430 A character string that \fBpinentry(1)\fP will use in it's dialog window\&.
432 \fB\fIPWMD_OPTION_PINENTRY_LC_CTYPE \fP\fP
433 For \fBpinentry(1)\fP localization\&.
435 \fB\fIPWMD_OPTION_PINENTRY_LC_MESSAGES \fP\fP
436 For \fBpinentry(1)\fP localization\&.
438 \fB\fIPWMD_OPTION_PINENTRY_TIMEOUT \fP\fP
439 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\&.
443 This only affects the local pinentry\&.
448 \fB\fIPWMD_OPTION_PINENTRY_TRIES \fP\fP
449 An integer value that specifies the number of times to prompt for a passphrase before returning an error\&.
453 This only affects the local pinentry\&.
458 \fB\fIPWMD_OPTION_STATUS_CB \fP\fP
459 A function of type \fBpwmd_status_cb_t\fP that will process status messages received from the pwmd server\&.
461 \fB\fIPWMD_OPTION_STATUS_DATA \fP\fP
462 A user data pointer which is passed to the status message function \fBPWMD_OPTION_STATUS_CB\fP\&.
464 \fB\fIPWMD_OPTION_KNOWNHOST_CB \fP\fP
465 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\&.
469 \fBRemote Connection Details\fP
474 \fB\fIPWMD_OPTION_KNOWNHOST_DATA \fP\fP
475 User supplied data which is passed to the known host function \fBPWMD_OPTION_KNOWNHOST_CB\fP\&.
479 \fBRemote Connection Details\fP
484 \fB\fIPWMD_OPTION_INQUIRE_TOTAL \fP\fP
485 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 every function that uses an \fBpwmd_inquire_cb_t\fP\&.
489 During the INQUIRE, \fBPWMD_OPTION_STATUS_CB\fP is called, when set, after every iteration of the \fBpwmd_inquire_cb_t\fP\&.
491 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\&.
496 \fB\fIPWMD_OPTION_LOCK_ON_OPEN \fP\fP
497 When set to 1, lock the file mutex after opening a file as if the LOCK command had been sent\&.
499 \fB\fIPWMD_OPTION_SSH_AGENT \fP\fP
500 Use ssh-agent to retrieve the private key to authenticate when connecting to a remote pwmd server\&.
502 \fB\fIPWMD_OPTION_NO_PINENTRY \fP\fP
503 When 1, disable pinentry use\&. This will prevent both pwmd and libpwmd from using a pinentry program\&.
507 This must be set before calling \fBpwmd_open()\fP\&.
512 \fB\fIPWMD_OPTION_LOCAL_PINENTRY \fP\fP
513 When 1, libpwmd will disable pwmd's pinentry and use it's own fork(2)'ed pinentry\&.
517 This must be set before calling \fBpwmd_open()\fP\&.
522 \fB\fIPWMD_OPTION_OVERRIDE_INQUIRE \fP\fP
523 When set, override libpwmd's handling of server inquires with the PASSPHRASE and NEW_PASSPHRASE keywords\&. This handling is done automatically when \fBPWMD_OPTION_NO_PINENTRY\fP or \fBPWMD_OPTION_LOCAL_PINENTRY\fP is set or when the connection is a remote one\&.
527 \fBRemote Connection Details\fP, \fBPWMD_OPTION_LOCAL_PINENTRY\fP, \fBpwmd_password()\fP
532 \fB\fIPWMD_OPTION_SSH_TIMEOUT \fP\fP
533 An int specifying a timeout in seconds before a blocking ssh function will timeout causing a command to fail\&.
535 \fB\fIPWMD_OPTION_SSH_KEEPALIVE \fP\fP
536 An int specifying an interval in seconds that \fBpwmd_process()\fP will send a keepalive message to the remote SSH server\&.
538 \fB\fIPWMD_OPTION_TLS_VERIFY \fP\fP
539 An int specifying whether to enable TLS hostname verification on the server certificate chain\&. Default is 0 or disabled\&.
540 .SS "enum \fBpwmd_pinentry_t\fP"
542 Local pinentry commands and not pwmd pinentry\&. These determine what prompt a local or fork()'ed pinentry uses\&. For use with \fBpwmd_getpin()\fP\&.
547 \fB\fIPWMD_PINENTRY_OPEN \fP\fP
548 When opening a file\&.
550 \fB\fIPWMD_PINENTRY_OPEN_FAILED \fP\fP
551 When opening a file failed\&.
553 \fB\fIPWMD_PINENTRY_SAVE \fP\fP
554 When saving a file\&.
556 \fB\fIPWMD_PINENTRY_SAVE_CONFIRM \fP\fP
557 For passphrase confirmation\&.
559 \fB\fIPWMD_PINENTRY_SAVE_FAILED \fP\fP
560 When saving a file and passphrase confirmation failed\&.
562 \fB\fIPWMD_PINENTRY_CONFIRM \fP\fP
563 For confirmation of a user-defined prompt\&.
565 \fB\fIPWMD_PINENTRY_USER \fP\fP
566 For the default or user defined string set with \fBPWMD_OPTION_PINENTRY_DESC\fP\&.
568 \fB\fIPWMD_PINENTRY_CLOSE \fP\fP
569 To terminate the pinentry process created with \fBpwmd_getpin()\fP\&.
570 .SS "enum \fBpwmd_socket_t\fP"
572 The type of socket a handle is connected to\&. For use with \fBpwmd_socket_type()\fP\&.
577 \fB\fIPWMD_SOCKET_LOCAL \fP\fP
578 A local UNIX domain socket\&.
580 \fB\fIPWMD_SOCKET_SSH \fP\fP
581 An SSH channel over a TCP socket\&.
583 \fB\fIPWMD_SOCKET_TLS \fP\fP
585 .SH "Function Details"
587 .SS "void \fBgnutls_global_set_mem_functions\fP (void **)(size_t, void **)(size_t, int(*)(const void *), void **)(void *, size_t, void(*)(void *))"
589 Convenience declaration\&. This allows an application wanting both a TLS connection and libpwmd secure memory management in GnuTLS, not needing to have the GnuTLS development files installed\&. This function should be called before \fBpwmd_init()\fP\&.
591 It is not done in \fBpwmd_init()\fP itself since the application may have already initialized GnuTLS by some other means\&.
592 .SS "LIBPWMD_API void* \fBpwmd_calloc\fP (size_tnmemb, size_tsize)"
594 A wrapper around calloc()\&. Like calloc(), but lets libpwmd keep track of the pointer\&.
598 \fInmemb\fP The number of elements to allocate\&.
600 \fIsize\fP The number of bytes to allocate\&.
605 A newly allocated pointer or NULL if there wasn't enough memory\&.
610 calloc(3), \fBpwmd_free()\fP
614 .SS "LIBPWMD_API void \fBpwmd_close\fP (\fBpwm_t\fP *pwm)"
616 Close a handle\&. This will close the connection to a pwmd server and free any resources associated with it\&.
620 \fIpwm\fP A handle\&.
630 \fBpwmd_disconnect()\fP, \fBpwmd_new()\fP
634 .SS "LIBPWMD_API gpg_error_t \fBpwmd_command\fP (\fBpwm_t\fP *pwm, char **result, size_t *len, \fBpwmd_inquire_cb_t\fPcallback, void *user, const char *cmd, \&.\&.\&.)"
636 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\&.
638 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\&.
642 \fIpwm\fP A handle\&.
644 \fIresult\fP The result of the command when successful which must be freed with \fBpwmd_free()\fP\&.
646 \fIlen\fP The length of \fIresult\fP\&.
648 \fIcallback\fP A callback function to invoke when pwmd inquires data from the client\&.
650 \fIuser\fP User data passed to the \fIcallback\fP function\&.
652 \fIcmd\fP The command to send and any following arguments\&.
657 0 on success or an error code\&.
662 Not all commands return a \fIresult\fP\&.
666 .SS "LIBPWMD_API gpg_error_t \fBpwmd_command_ap\fP (\fBpwm_t\fP *pwm, char **result, size_t *len, \fBpwmd_inquire_cb_t\fPcallback, void *user, const char *cmd, va_listap)"
668 Send a command to the pwmd server\&. Like \fBpwmd_command()\fP but uses an argument pointer instead\&.
672 \fIpwm\fP A handle\&.
674 \fIresult\fP The result of the command when successful which must be freed with \fBpwmd_free()\fP\&.
676 \fIlen\fP The length of \fIresult\fP\&.
678 \fIcallback\fP A callback function to invoke when pwmd inquires data from the client\&.
680 \fIuser\fP User data passed to the \fIcallback\fP function\&.
682 \fIcmd\fP The command to send\&.
684 \fIap\fP The arguments to \fIcmd\fP\&.
689 0 on success or an error code\&.
694 Not all commands return a \fIresult\fP\&.
698 .SS "LIBPWMD_API gpg_error_t \fBpwmd_connect\fP (\fBpwm_t\fP *pwm, const char *url, \&.\&.\&.)"
700 Establish a connection to a pwmd server\&. Connects to the pwmd server specified in \fIurl\fP\&. The format of \fIurl\fP is:
704 file:///path/to/socket, or
709 ssh[46]://[username@]hostname[:port], or
714 tls[46]://hostname[:port]
717 If \fIurl\fP is NULL then the default local pwmd socket \fI~/\fP\&.pwmd/socket will be used\&.
719 The remaining arguments are parameters for the \fIurl\fP\&.
721 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\&.
723 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 should be a TLS cipher priority string or NULL to use the default of 'SECURE256'\&.
725 For local connections, any remaining parameters are ignored\&.
729 \fIpwm\fP A handle\&.
731 \fIurl\fP The socket to connect to\&.
733 \fI\&.\&.\&.\fP Remaining parameters for the \fIurl\fP\&.
738 0 on success or an error code\&.
743 When the first character of a filename parameter is a tilde (~), it will be expanded to the home directory of the current user\&.
748 \fBPWMD_OPTION_SSH_AGENT\fP, \fBpwmd_socket_type()\fP, \fBpwmd_disconnect()\fP, \fBRemote Connection Details\fP
752 .SS "LIBPWMD_API void \fBpwmd_deinit\fP (void)"
754 Deinitialize the library\&. This function is mainly for cleaning up other libraries that libpwmd links with to prevent leaks showing up a debugger\&. It should be the final libpwmd function call before your app exits\&.
755 .SS "LIBPWMD_API gpg_error_t \fBpwmd_disconnect\fP (\fBpwm_t\fP *pwm)"
757 Close a connection to the pwmd server\&. This will close the connection but keep any previously set options for the specified handle\&. Calling \fBpwmd_connect()\fP will re-acquire an libassuan context\&.
761 \fIpwm\fP A handle\&.
766 0 on success or an error code\&.
775 .SS "LIBPWMD_API gpg_error_t \fBpwmd_fd\fP (\fBpwm_t\fP *pwm, int *fd)"
777 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)\&.
781 \fIpwm\fP A handle\&.
783 \fIfd\fP Set to the file descriptor associated with \fIpwm\fP\&.
788 0 on success or an error code\&.
792 .SS "LIBPWMD_API unsigned int \fBpwmd_features\fP ()"
794 libpwmd compile time features\&. Useful for clients to determine what features are compiled into libpwmd at runtime\&.
798 A bitmask of features\&.
802 .SS "LIBPWMD_API void \fBpwmd_free\fP (void *ptr)"
804 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\&.
806 The difference between the standard free() and this function is that this one will zero out the contents of the pointer before freeing it\&.
810 \fIptr\fP The pointer to deallocate\&.
820 \fBpwmd_malloc()\fP, \fBpwmd_calloc()\fP, \fBpwmd_realloc()\fP, \fBpwmd_strdup()\fP, \fBpwmd_command()\fP
824 .SS "LIBPWMD_API gpg_error_t \fBpwmd_getpin\fP (\fBpwm_t\fP *pwm, const char *filename, char **result, size_t *len, \fBpwmd_pinentry_t\fPwhich)"
826 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\&.
828 This function may also be used to display a user confirmation dialog with pinentry when \fIwhich\fP is \fBPWMD_PINENTRY_CONFIRM\fP\&. The text to prompt with is set with \fBPWMD_OPTION_PINENTRY_DESC\fP\&.
832 \fIpwm\fP A handle\&.
834 \fIfilename\fP The filename to use in the pinentry dialog strings\&.
836 \fIresult\fP The entered value in the pinentry dialog which should be freed with \fBpwmd_free()\fP\&.
838 \fIlen\fP The length of \fIresult\fP\&.
840 \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\&.
845 0 on success or an error\&.
850 \fBpwmd_password()\fP
854 .SS "LIBPWMD_API gpg_error_t \fBpwmd_init\fP (void)"
856 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\&.
860 0 on success or an error code\&.
864 .SS "LIBPWMD_API void* \fBpwmd_malloc\fP (size_tsize)"
866 A wrapper around malloc\&. Like malloc(), but lets libpwmd keep track of the pointer\&.
870 \fIsize\fP The number of bytes to allocate\&.
875 A newly allocated pointer or NULL if there wasn't enough memory\&.
880 malloc(3), \fBpwmd_free()\fP
884 .SS "LIBPWMD_API gpg_error_t \fBpwmd_new\fP (const char *name, \fBpwm_t\fP **pwm)"
886 Creates a new handle\&. Creates a new handle for use with the other functions\&.
890 \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\&.
892 \fIpwm\fP A new handle for use with the other functions\&.
897 0 on success or an error code\&.
901 .SS "LIBPWMD_API gpg_error_t \fBpwmd_open\fP (\fBpwm_t\fP *pwm, const char *filename, \fBpwmd_inquire_cb_t\fPcallback, void *data)"
903 Open a file on the pwmd server\&. This will send the OPEN command to the server\&.
905 The inquire \fIcallback\fP function should be used when \fBPWMD_OPTION_NO_PINENTRY\fP is set and is used to send the passphrase when needed\&.
909 \fIpwm\fP A handle\&.
911 \fIfilename\fP The filename to open\&. The \fIfilename\fP is not a full path but the data filename only\&.
913 \fIcallback\fP A callback function to invoke when pwmd inquires data from the client\&.
915 \fIdata\fP User data passed to the \fIcallback\fP function\&.
920 0 on success or an error code\&.
925 \fBPinentry Details\fP, \fBpwmd_password()\fP
929 .SS "LIBPWMD_API gpg_error_t \fBpwmd_password\fP (\fBpwm_t\fP *pwm, const char *keyword, char **data, size_t *size)"
931 Obtain a passphrase from a local pinentry\&. This is the same function that libpwmd uses during an inquire when using the local pinentry and the inquire keyword is either PASSPHRASE or NEW_PASSPHRASE\&. Provided for convenience since it sets proper pinentry strings and handles new passphrase confirmation\&.
935 \fIpwm\fP A handle\&.
937 \fIkeyword\fP The keyword to determine pinentry strings\&. Usually PASSPHRASE or NEW_PASSPHRASE\&.
939 \fIdata\fP The obtained passphrase which should be freed with \fBpwmd_free()\fP\&.
941 \fIsize\fP The length of \fIdata\fP\&.
946 0 on success or an error\&.
951 It is an error for \fIsize\fP to be zero when inquiring a \fIkeyword\fP of PASSPHRASE\&. In this case GPG_ERR_CANCELED will be returned\&.
955 .SS "LIBPWMD_API gpg_error_t \fBpwmd_process\fP (\fBpwm_t\fP *pwm)"
957 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\&.
961 \fIpwm\fP A handle\&.
966 0 on success or an error code\&.
971 This function makes use of \fBpwmd_status_cb_t\fP\&.
975 .SS "LIBPWMD_API void* \fBpwmd_realloc\fP (void *ptr, size_tsize)"
977 A wrapper around realloc()\&. Like realloc(), but lets libpwmd keep track of the pointer\&.
981 \fIptr\fP The pointer to reallocate\&.
983 \fIsize\fP The new number of bytes to allocate\&.
988 A newly allocated pointer or NULL if there wasn't enough memory\&.
993 realloc(3), \fBpwmd_free()\fP
997 .SS "LIBPWMD_API gpg_error_t \fBpwmd_save\fP (\fBpwm_t\fP *pwm, const char *args, \fBpwmd_inquire_cb_t\fPcallback, void *user)"
999 Save a file on the pwmd server\&. This will send the SAVE command and write any changes to the document to disk\&.
1001 The inquire \fIcallback\fP function should be used when \fBPWMD_OPTION_NO_PINENTRY\fP is set or when a SAVE option specified in \fIargs\fP requires more data\&.
1005 \fIpwm\fP A handle\&.
1007 \fIargs\fP Any SAVE protocol command options or NULL\&.
1009 \fIcallback\fP A callback function to invoke when pwmd inquires data from the client\&.
1011 \fIuser\fP User data passed to the \fIcallback\fP function\&.
1016 0 on success or an error code\&.
1021 \fBpwmd_command()\fP, \fBPinentry Details\fP
1025 .SS "LIBPWMD_API gpg_error_t \fBpwmd_setopt\fP (\fBpwm_t\fP *pwm, \fBpwmd_option_t\fPopt, \&.\&.\&.)"
1027 Set handle options\&. See \fBpwmd_option_t\fP for option specific details\&.
1031 \fIpwm\fP A handle\&.
1033 \fIopt\fP The option and following option value\&.
1038 0 on success or an error code\&.
1042 .SS "LIBPWMD_API gpg_error_t \fBpwmd_socket_type\fP (\fBpwm_t\fP *pwm, \fBpwmd_socket_t\fP *type)"
1044 The type of connection a handle has\&. Useful when you want to know what kind of connection a handle has\&.
1048 \fIpwm\fP A handle\&.
1050 \fItype\fP The type of socket\&.
1055 0 on success or an error code\&.
1064 .SS "LIBPWMD_API char* \fBpwmd_strdup\fP (const char *str)"
1066 A wrapper around strdup()\&. Like strdup(), but lets libpwmd keep track of the pointer\&.
1070 \fIstr\fP The string to duplicate\&.
1075 A newly allocated character pointer or NULL if there wasn't enough memory\&.
1080 strdup(3), \fBpwmd_free()\fP
1084 .SS "LIBPWMD_API char* \fBpwmd_strdup_printf\fP (const char *fmt, \&.\&.\&.)"
1086 Duplicate a formatted string\&. Like \fBasprintf(3)\fP, but lets libpwmd keep track of the pointer\&.
1090 \fIfmt\fP The formatted string and any following arguments\&.
1095 A newly allocated character pointer or NULL if there wasn't enough memory\&.
1104 .SS "LIBPWMD_API const char* \fBpwmd_version\fP ()"
1106 Returns this version of libpwmd\&. As a string\&.
1116 Generated automatically by Doxygen for libpwmd from the source code\&.