Fix pwmd_save() to determine whether to use pinentry.
[libpwmd.git] / src / libpwmd.h.in
blobc6a88a8f1ffdf7300f12b8fabe789ec8b0cc2b46
1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
2 /*
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
4 Ben Kibbey <bjk@luxsci.net>
6 This file is part of libpwmd.
8 Libpwmd is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
13 Libpwmd is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Libpwmd. If not, see <http://www.gnu.org/licenses/>.
21 /*! \headerfile libpwmd.h
23 * libpwmd is a library making it easy for applications to use the pwmd
24 * server. Pwmd version 3.0 or later is required; either locally or remotely.
27 /*! \section threads Threads
29 * \ref libpwmd should be thread-safe on a per handle bases. Meaning that only
30 * one thread should access a \ref pwm_t handle at a time.
33 /*! \section remote Remote Connection Details
35 * There are two methods of connecting to a remote pwmd server: an SSH
36 * channel, or over TLS. Connections over SSH are less reliable than TLS
37 * connections since a proxy program is needed to connect to the pwmd UNIX
38 * Domain Socket. The kernel that pwmd runs under may buffer the UDS data
39 * before it reaches the proxy program and there isn't a portable way to
40 * modify kernel buffer settings. For larger transfers of data this is
41 * noticeable by the hanging of the command that initiated the transfer.
43 * If you really do need an SSH connection you can do so by using an SSH
44 * channel to spawn a shell that executes a proxy server to connect to the
45 * pwmd local Unix Domain Socket. Authentication is done by using SSH public
46 * key (see \ref ssh-keygen(1)) authentication and verifying the host key
47 * against a local OpenSSH known hosts formatted file.
49 * An unknown servers public key can be added to a known hosts file after user
50 * confirmation by setting the callback function \ref pwmd_knownhost_cb_t
51 * before connecting to the unknown host.
53 * On the server side you'll need a proxy server to connect to the pwmd
54 * server. Below is an example of an \ref authorized_keys(5) entry that will
55 * do this. The \a public_key portion should be the same as the contents of
56 * the \ref ssh-keygen(1) \a identity.pub file generated on the client
57 * machine. The private key should be passed as the \a identity parameter to
58 * \ref pwmd_connect():
60 * \code
61 * command="socat UNIX-CONNECT:$HOME/.pwmd/socket -" <public_key> ...
62 * \endcode
64 * \note Only an SSH identity without a passphrase is supported. For now
65 * anyway. This is a limitation of libssh2 (version 1.2.8 as of this writing).
67 * \version 6.0.3
68 * The first version to use the OpenSSH known hosts file format exclusively.
69 * Earlier versions used only an SHA1 hash of the host key.
71 * As mentioned, TLS connections are more reliable since there is no proxy
72 * program needed to connect to the pwmd server. pwmd itself can accept TLS
73 * connections and like SSH connections they are created with \ref
74 * pwmd_connect(). You'll need to generate a client key and X509 certificate
75 * then sign it with the same certificate authority (CA) that the pwmd server
76 * certificate was signed with.
78 * Certificates are similar to SSH public and private keys but a little harder
79 * to get setup correctly. See the \ref certtool(1) (recommended) and \ref
80 * openssl(1) manual pages for details.
83 /*! \section pinentry Pinentry Details
85 * \ref pinentry(1) is a program that prompts the user for input which is
86 * normally a passphrase or a confirmation. libpwmd can use this program
87 * either locally (X11 forwarding is not yet supported) or have the pwmd
88 * server or gpg-agent use it's pinentry to retrieve a passphrase when
89 * needed.
91 * There are a few options that tell pinentry how and where to prompt for a
92 * needed passphrase. See the \ref pwmd_option_t section for details. These
93 * options are only sent to pwmd in \ref pwmd_open() and only when pinentry
94 * use has not been disabled and when not over an remote connnection.
96 * Some pinentry options may also be specified in the local configuration file
97 * \a "~/.pwmd/pinentry.conf". These options are initial values for each
98 * pinentry invokation (not retries) and may be changed by setting the
99 * appropriate \ref pwmd_option_t. Options and values are separated with a '='
100 * on a single line. Unrecognized options are ignored. Here are the recognized
101 * options:
103 * \param PATH The full path to the location of the pinentry binary. Only
104 * useful for the local pinentry.
105 * \param DISPLAY The X11 display to use.
106 * \param TTYNAME The full path to the tty that pinentry should prompt on.
107 * \param TTYTYPE The terminal type of the tty which is required if DISPLAY is
108 * not set.
109 * \param LC_MESSAGES Adjust for the current locale.
110 * \param LC_CTYPE Adjust for the current locale.
112 * \filepath
114 * \note The initial values for the pinentry TTY, TERM and DISPLAY are set
115 * during \ref pwmd_new() depending on the current environment. They can be
116 * reset or changed as needed.
118 * \note After establishing a remote connection, pwmd's pinentry is disabled
119 * by passing the "--no-pinentry" option to the OPEN protocol command during
120 * \ref pwmd_open() since X11 forwarding has not been implemented. A local
121 * pinentry will be used in the case of a remote connection.
123 * \see \ref remote
126 /*! \section Errors
128 * libpwmd uses libgpg-error for all error codes. Error codes can be
129 * described by using \ref gpg_strerror(), or the thread-safe \ref
130 * gpg_strerror_r().
132 * \note libgpg-error returns an error code as a bitmask of an error source
133 * and the error code. Determining the error source can help you find where
134 * the error occured, beit from \ref pinentry(1), \ref gpg-agent(1), \ref
135 * libgcrypt, \ref pwmd(1) or \ref libpwmd(3). pwmd uses the \ref
136 * GPG_ERR_SOURCE_USER_1 error source and libpwmd uses \ref
137 * GPG_ERR_SOURCE_USER_2. To find the error source of an error code the \ref
138 * gpg-error(1) command line utility may be of use. Also see the \ref
139 * libgpg-error documentation for error code manipulation.
142 /*! \file */
143 #ifndef LIBPWMD_H
144 #define LIBPWMD_H
146 #ifndef LIBPWMD_API
147 #define LIBPWMD_API
148 #endif
150 #ifdef GPG_ERR_SOURCE_DEFAULT
151 #error "GPG_ERR_SOURCE_DEFAULT already defined."
152 #else
153 #define GPG_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_USER_2
154 #endif
155 #include <gpg-error.h>
156 #include <stdarg.h>
158 #ifdef __cplusplus
159 extern "C"
161 #endif
163 /*! \def LIBPWMD_VERSION
164 * \brief Version information.
166 * The version of this library.
168 #define LIBPWMD_VERSION 0x@VER_MAJOR_HEX@@VER_MINOR_HEX@@VER_PATCH_HEX@
171 /*! \def LIBPWMD_VERSION_MAJOR
172 * \brief Version information.
174 * The major release number of this library.
176 #define LIBPWMD_VERSION_MAJOR @VER_MAJOR@
179 /*! \def LIBPWMD_VERSION_MINOR
180 * \brief Version information.
182 * The minor release number of this library.
184 #define LIBPWMD_VERSION_MINOR @VER_MINOR@
187 /*! \def LIBPWMD_VERSION_PATCH
188 * \brief Version information.
190 * The patch level of this library.
192 #define LIBPWMD_VERSION_PATCH @VER_PATCH@
195 /*! \def LIBPWMD_VERSION_STR
196 * \brief Version information.
198 * A string representation of the version of this library.
200 #define LIBPWMD_VERSION_STR @VER_STRING@
203 /*! \brief Returns this version of libpwmd.
205 * As a string.
206 * \return A string.
208 LIBPWMD_API const char *pwmd_version ();
211 struct pwm_s;
212 /*! \typedef pwm_t
213 * \brief libpwmd handle.
215 * When a handle or context is mentioned in this documentation it is a pointer
216 * of this type. A new handle is created with \ref pwmd_new().
218 typedef struct pwm_s pwm_t;
221 /*! \typedef pwmd_socket_t
222 * \brief The type of socket a handle is connected to.
224 * For use with \ref pwmd_socket_type().
226 typedef enum
228 /*! A local UNIX domain socket. */
229 PWMD_SOCKET_LOCAL,
231 /*! An SSH channel over a TCP socket. */
232 PWMD_SOCKET_SSH,
234 /*! A TLS connection over a TCP socket. */
235 PWMD_SOCKET_TLS
236 } pwmd_socket_t;
239 /*! \typedef pwmd_pinentry_t
240 * \brief Local pinentry commands and not pwmd pinentry.
242 * These determine what prompt a local or fork()'ed pinentry uses. For use
243 * with \ref pwmd_getpin().
245 typedef enum
247 /*! When opening a file. */
248 PWMD_PINENTRY_OPEN,
250 /*! When opening a file failed due to a bad passphrase. */
251 PWMD_PINENTRY_OPEN_FAILED,
253 /*! When saving a file. */
254 PWMD_PINENTRY_SAVE,
256 /*! For passphrase confirmation. */
257 PWMD_PINENTRY_SAVE_CONFIRM,
259 /*! When saving a file and passphrase confirmation failed. */
260 PWMD_PINENTRY_SAVE_FAILED,
262 /*! For confirmation of a user-defined prompt. */
263 PWMD_PINENTRY_CONFIRM,
265 /*! For the default or user defined string set with \ref
266 * PWMD_OPTION_PINENTRY_DESC. */
267 PWMD_PINENTRY_USER,
269 /*! To terminate the pinentry process created with \ref pwmd_getpin(). */
270 PWMD_PINENTRY_CLOSE
271 } pwmd_pinentry_t;
274 /*! \typedef pwmd_status_cb_t
275 * \brief Process status messages.
277 * The value of the option \ref PWMD_OPTION_STATUS_CB which is set with \ref
278 * pwmd_setopt().
280 * \param user A user data pointer which is set with \ref
281 * PWMD_OPTION_STATUS_DATA.
282 * \param line The status message line received from the server.
283 * \return 0 on success or an error code which will cause a command to fail.
285 typedef gpg_error_t (*pwmd_status_cb_t) (void *user, const char *line);
288 /*! \typedef pwmd_inquire_cb_t
289 * \brief Send data to the pwmd server.
291 * This is a callback function that is used for sending data to the server for
292 * commands that need to reply to an INQUIRE server response. The reason for
293 * this callback is to let the client send as many bytes as it wants rather
294 * than the entire data at once. It gets called during an internal \ref
295 * assuan_transact() from an internal inquire callback function which in turn
296 * calls this function by looping over its return value.
298 * \param user The user data pointer passed to the libpwmd function specifying
299 * this callback.
300 * \param keyword The name of this inquire. Could be a command name or some
301 * keyword describing what needs to be sent. See the pwmd and \ref
302 * gpg-agent(1) documentation for details.
303 * \param rc The result of the last internal call to \ref assuan_send_data()
304 * which did the sending of the data to the pwmd server. On the first call to
305 * this callback it's value will always be 0 since no data has been sent yet.
306 * This should be checked during each call to this function and should return
307 * the same error code when set. Its purpose is to let the client clean up
308 * before letting the command fail.
309 * \param[out] data The next chunk of data to send or NULL.
310 * \param[out] len The length of \a data or 0.
312 * \retval 0 There is more data to be sent.
313 * \retval GPG_ERR_EOF No need to call this function again, the current
314 * \a data is the last to send.
315 * \retval code Any other error code which will cancel the INQUIRE.
317 * \note The sent data is processed line-per-line. The line is either newline
318 * terminated or is buffered until ASSUAN_LINELENGTH bytes have been
319 * allocated. Any remaining bytes are sent after the INQUIRE has finished.
321 typedef gpg_error_t (*pwmd_inquire_cb_t) (void *user, const char *keyword,
322 gpg_error_t rc, char **data,
323 size_t * len);
326 /*! \typedef pwmd_knownhost_cb_t
327 * \brief Verify a remote SSH connection.
329 * When \ref PWMD_OPTION_KNOWNHOST_CB is set and a the current connections
330 * host key was not found in the known hosts file, then this callback function
331 * can be used to confirm the addition of the new host key to the known_hosts
332 * file.
334 * \param user User data which was set with \ref PWMD_OPTION_KNOWNHOST_DATA.
335 * \param host The hostname as passed to \ref pwmd_connect().
336 * \param hostkey The raw binary data of the host key.
337 * \param len The length of \a hostkey.
338 * \retval 0 Add the host key to the known hosts file.
339 * \retval GPG_ERR_NOT_CONFIRMED Do not add the host key and abort the
340 * connection. This is the recommended error code although any other non-zero
341 * return value will also abort the connection.
343 * \note If the known hosts file cannot be modified do to filesystem
344 * restrictions when trying to add the new host key, no error is returned.
345 * Instead, the host key is added to the current connections host key cache
346 * and the connection is accepted.
348 * \see \ref remote
350 typedef gpg_error_t (*pwmd_knownhost_cb_t) (void *user, const char *host,
351 const char *hostkey,
352 size_t len);
355 /*! \enum pwmd_option_t
356 * \brief libpwmd options.
358 * Options are set with \ref pwmd_setopt(). Some options must be set before a
359 * connection is made to have any effect.
361 * \filepath
363 /* Note to self: dont change the order or insert. Only append. */
364 typedef enum
366 /*! A string value which specifies the full path of the \ref pinentry(1)
367 * binary. The default is specified at compile time.
369 * \note This only affects the local pinentry.
370 * \see \ref pinentry
372 PWMD_OPTION_PINENTRY_PATH,
374 /*! A string value which specifies the full path to the TTY that \ref
375 * pinentry(1) will use to prompt on. When set and no DISPLAY is
376 * available, \ref PWMD_OPTION_PINENTRY_TERM must also be set.
378 * \see \ref pinentry
380 PWMD_OPTION_PINENTRY_TTY,
382 /*! A string value which specifies the terminal type (i.e., vt100) that
383 * \ref pinentry(1) will use when no X11 display is available.
385 * \see \ref pinentry
387 PWMD_OPTION_PINENTRY_TERM,
389 /*! A string value which specifies the X11 display that \ref pinentry(1)
390 * will use. \ref pinentry(1) seems to make DISPLAY have a higher priority
391 * than \ref PWMD_OPTION_PINENTRY_TTY.
393 * \see \ref pinentry
395 PWMD_OPTION_PINENTRY_DISPLAY,
397 /*! A character string that \ref pinentry(1) will use in it's dialog
398 * window.
400 PWMD_OPTION_PINENTRY_ERROR,
402 /*! \copydoc PWMD_OPTION_PINENTRY_ERROR */
403 PWMD_OPTION_PINENTRY_PROMPT,
405 /*! \copydoc PWMD_OPTION_PINENTRY_ERROR */
406 PWMD_OPTION_PINENTRY_DESC,
408 /*! For \ref pinentry(1) localization. */
409 PWMD_OPTION_PINENTRY_LC_CTYPE,
411 /*! \copydoc PWMD_OPTION_PINENTRY_LC_CTYPE */
412 PWMD_OPTION_PINENTRY_LC_MESSAGES,
414 /*! An integer value that specifies the number of seconds \ref pinentry(1)
415 * will wait for input before timing out and aborting the current command.
416 * If 0, then no timeout will be used. The default is 30.
418 * \note This only affects the local pinentry.
420 PWMD_OPTION_PINENTRY_TIMEOUT,
422 /*! An integer value that specifies the number of times to prompt for a
423 * passphrase before returning an error.
425 * \note This only affects the local pinentry.
427 PWMD_OPTION_PINENTRY_TRIES,
429 /*! A function of type \ref pwmd_status_cb_t that will process status
430 * messages received from the pwmd server.
432 PWMD_OPTION_STATUS_CB,
434 /*! A user data pointer which is passed to the status message function
435 * \ref PWMD_OPTION_STATUS_CB. */
436 PWMD_OPTION_STATUS_DATA,
438 /*! A function of type \ref pwmd_knownhost_cb_t that will be used to
439 * confirm a host key that was not found in the known hosts file.
441 * \see \ref remote
443 PWMD_OPTION_KNOWNHOST_CB,
445 /*! User supplied data which is passed to the known host function \ref
446 * PWMD_OPTION_KNOWNHOST_CB.
448 * \see \ref remote
450 PWMD_OPTION_KNOWNHOST_DATA,
452 /*! When the total number of bytes to be sent via an INQUIRE is known,
453 * this should be set so XFER status messages can be parsed correctly.
454 * When not known or unset, 0 is used as the total argument to the XFER
455 * status message. This option should be reset in every function that
456 * uses an \ref pwmd_inquire_cb_t.
458 * \note During the INQUIRE, \ref PWMD_OPTION_STATUS_CB is called, when
459 * set, after every iteration of the \ref pwmd_inquire_cb_t.
461 * \note This is a libpwmd feature. pwmd itself does not send XFER status
462 * messages during an INQUIRE. Status messages can be parsed only when
463 * \ref PWMD_OPTION_STATUS_CB is set.
465 PWMD_OPTION_INQUIRE_TOTAL,
467 /*! When set to 1, lock the file mutex after opening a file as if the LOCK
468 * command had been sent.
470 PWMD_OPTION_LOCK_ON_OPEN,
472 /*! Use ssh-agent to retrieve the private key to authenticate when
473 * connecting to a remote pwmd server. */
474 PWMD_OPTION_SSH_AGENT,
476 /*! When 1, disable pinentry use. This will prevent both pwmd and libpwmd
477 * from using a pinentry program.
479 * \note This must be set before calling \ref pwmd_open().
481 PWMD_OPTION_NO_PINENTRY,
483 /*! When 1, libpwmd will disable pwmd's pinentry and use it's own
484 * fork(2)'ed pinentry.
486 * \note This must be set before calling \ref pwmd_open().
488 PWMD_OPTION_LOCAL_PINENTRY,
490 /*! When set, override libpwmd's handling of server inquires with the
491 * PASSPHRASE and NEW_PASSPHRASE keywords. This handling is done
492 * automatically when \ref PWMD_OPTION_NO_PINENTRY or \ref
493 * PWMD_OPTION_LOCAL_PINENTRY is set or when the connection is a remote
494 * one.
496 * \see \ref remote, \ref PWMD_OPTION_LOCAL_PINENTRY, \ref pwmd_password()
498 PWMD_OPTION_OVERRIDE_INQUIRE,
500 /*! An int specifying a timeout in seconds before a TCP connection or
501 * transfer function will timeout causing a connection or command to
502 * fail. This option can be specified both before and after a connection
503 * has been established. When 0, no timeout is used.
505 PWMD_OPTION_SOCKET_TIMEOUT,
507 /*! An int specifying whether to enable TLS hostname verification on the
508 * server certificate chain. Default is 0 or disabled. */
509 PWMD_OPTION_TLS_VERIFY,
510 } pwmd_option_t;
513 /*! \def PWMD_FEATURE_PINENTRY
514 * \hideinitializer
515 * \brief Pinentry support.
517 * This is for a local or fork()'ed pinentry.
519 #define PWMD_FEATURE_PINENTRY 0x0001
521 /*! \def PWMD_FEATURE_CRACK
522 * \hideinitializer
523 * \brief Password quality checking.
525 * A password quality meter is shown when the pinentry supports it.
527 #define PWMD_FEATURE_CRACK 0x0002
529 /*! \def PWMD_FEATURE_SSH
530 * \hideinitializer
531 * \brief Remote connections over an SSH channel.
533 * \see \ref remote
535 #define PWMD_FEATURE_SSH 0x0004
537 /*! \def PWMD_FEATURE_GNUTLS
538 * \hideinitializer
539 * \brief Remote connections over TLS.
541 * \see \ref remote
543 #define PWMD_FEATURE_GNUTLS 0x0008
546 /*! \brief libpwmd compile time features.
548 * Useful for clients to determine what features are compiled into libpwmd at
549 * runtime.
551 * \return A bitmask of features.
553 LIBPWMD_API unsigned int pwmd_features ();
556 /*! \brief Initialize the library.
558 * This function must be the first function called in the library before any
559 * others. It sets up the memory allocators and internationalization among
560 * other things.
562 * \return 0 on success or an error code.
564 LIBPWMD_API gpg_error_t pwmd_init (void);
566 /*! \brief Deinitialize the library.
568 * This function is mainly for cleaning up other libraries that libpwmd links
569 * with to prevent leaks showing up a debugger. It should be the final libpwmd
570 * function call before your app exits.
572 LIBPWMD_API void pwmd_deinit (void);
575 /*! \brief Creates a new handle.
577 * Creates a new handle for use with the other functions.
579 * \param name If not NULL, the name of the application. The application name
580 * is sent to the pwmd server after successfully connecting and is used in
581 * pwmd logging.
582 * \param[in] pwm A new handle for use with the other functions.
584 * \return 0 on success or an error code.
586 LIBPWMD_API gpg_error_t pwmd_new (const char *name, pwm_t ** pwm);
589 /*! \brief Establish a connection to a pwmd server.
591 * Connects to the pwmd server specified in \a url. The format of \a url is:
592 * \par
593 * file:///path/to/socket, or
594 * \par
595 * ssh[46]://[username@]hostname[:port], or
596 * \par
597 * tls[46]://hostname[:port]
599 * If \a url is NULL then the default local pwmd socket \a ~/.pwmd/socket
600 * will be used.
602 * The remaining arguments are parameters for the \a url.
604 * For SSH connections, the first of the positional parameters should be the
605 * identity file to use and is required to be non-NULL unless \ref
606 * PWMD_OPTION_SSH_AGENT is set. The final parameter is the known hosts file
607 * to use or NULL to use a default of \a ~/.ssh/knownhosts.
609 * For TLS connections, the first positional parameter should be the client
610 * certificate filename. The second parameter should be the client
611 * certificate key filename. The third parameter should be the Certificate
612 * Authority (CA) file that was used to sign the server certificate. The
613 * fourth parameter should be a TLS cipher priority string or NULL to use the
614 * default of "SECURE256". The final parameter is an SHA-1 hash of the server
615 * fingerprint or NULL.
617 * For local connections, any remaining parameters are ignored.
619 * \param pwm A handle.
620 * \param url The socket to connect to.
621 * \param ... Remaining parameters for the \a url.
622 * \return 0 on success or an error code.
623 * \filepath
624 * \see \ref PWMD_OPTION_SSH_AGENT, \ref PWMD_OPTION_SOCKET_TIMEOUT,
625 * pwmd_socket_type(), pwmd_disconnect(),
626 * \ref remote
628 LIBPWMD_API gpg_error_t pwmd_connect (pwm_t * pwm, const char *url, ...);
631 /*! \brief Set handle options.
633 * See \ref pwmd_option_t for option specific details.
635 * \param pwm A handle.
636 * \param opt The option and following option value.
637 * \return 0 on success or an error code.
639 LIBPWMD_API gpg_error_t pwmd_setopt (pwm_t * pwm, pwmd_option_t opt, ...);
642 /*! \brief Launch a local pinentry.
644 * Does not send any command to the pwmd server. This maybe useful if a
645 * passphrase is needed while opening a file over a remote connection and
646 * during an \ref pwmd_open() server inquire.
648 * This function may also be used to display a user confirmation dialog with
649 * pinentry when \a which is \ref PWMD_PINENTRY_CONFIRM. The text to prompt
650 * with is set with \ref PWMD_OPTION_PINENTRY_DESC.
652 * \param pwm A handle.
653 * \param filename The filename to use in the pinentry dialog strings.
654 * \param[in] result The entered value in the pinentry dialog which should be
655 * freed with \ref pwmd_free().
656 * \param[in] len The length of \a result.
657 * \param which Determines the default strings shown in the pinentry
658 * dialog. \ref pwmd_setopt() may also be used to override the defaults. In
659 * this case \ref PWMD_PINENTRY_USER should be used. \ref PWMD_PINENTRY_CLOSE
660 * should be used to terminate the pinentry process when the pinentry is no
661 * longer needed.
663 * \return 0 on success or an error.
665 * \see pwmd_password()
667 LIBPWMD_API gpg_error_t pwmd_getpin (pwm_t * pwm, const char *filename,
668 char **result, size_t * len,
669 pwmd_pinentry_t which);
671 /*! \brief Obtain a passphrase from a local pinentry.
673 * This is the same function that libpwmd uses during an inquire when using
674 * the local pinentry and the inquire keyword is either PASSPHRASE or
675 * NEW_PASSPHRASE. Provided for convenience since it sets proper pinentry
676 * strings and handles new passphrase confirmation.
678 * \param pwm A handle.
679 * \param keyword The keyword to determine pinentry strings. Usually
680 * PASSPHRASE or NEW_PASSPHRASE.
681 * \param[in] data The obtained passphrase which should be freed with \ref
682 * pwmd_free().
683 * \param[in] size The length of \a data.
685 * \return 0 on success or an error.
687 LIBPWMD_API gpg_error_t pwmd_password (pwm_t * pwm, const char *keyword,
688 char **data, size_t * size);
690 /*! \brief Open a file on the pwmd server.
692 * This will send the OPEN command to the server.
694 * The inquire \a callback function should be used when \ref
695 * PWMD_OPTION_NO_PINENTRY is set and is used to send the passphrase when
696 * needed.
698 * \param pwm A handle.
699 * \param filename The filename to open. The \a filename is not a full path
700 * but the data filename only.
701 * \param callback A callback function to invoke when pwmd inquires data from
702 * the client.
703 * \param data User data passed to the \a callback function.
704 * \return 0 on success or an error code.
705 * \see \ref PWMD_OPTION_OVERRIDE_INQUIRE, \ref pinentry, pwmd_password()
707 LIBPWMD_API gpg_error_t pwmd_open (pwm_t * pwm, const char *filename,
708 pwmd_inquire_cb_t callback, void *data);
711 /*! \brief Check for socket activity.
713 * This function should be called periodically to check for any pending status
714 * messages sent from the server and when \em not in a command.
716 * \param pwm A handle.
717 * \return 0 on success or an error code.
719 * \note This function makes use of \ref pwmd_status_cb_t.
721 LIBPWMD_API gpg_error_t pwmd_process (pwm_t * pwm);
724 /*! \brief Save a file on the pwmd server.
726 * This will send the SAVE command and write any changes to the document to
727 * disk.
729 * The inquire \a callback function should be used when \ref
730 * PWMD_OPTION_NO_PINENTRY is set or when a SAVE option specified in \a args
731 * inquires more data. This function will also disable the pwmd pinentry when
732 * \ref PWMD_OPTION_NO_PINENTRY or \ref PWMD_OPTION_LOCAL_PINENTRY is set. It
733 * will not restore the pwmd pinentry mode that was previously set before
734 * calling this function.
736 * \param pwm A handle.
737 * \param args Any SAVE protocol command options or NULL.
738 * \param callback A callback function to invoke when pwmd inquires data from
739 * the client.
740 * \param user User data passed to the \a callback function.
741 * \return 0 on success or an error code.
742 * \see \ref PWMD_OPTION_OVERRIDE_INQUIRE, \ref PWMD_OPTION_NO_PINENTRY,
743 * \ref PWMD_OPTION_LOCAL_PINENTRY, \ref pwmd_command(), \ref pinentry
745 LIBPWMD_API gpg_error_t pwmd_save (pwm_t * pwm, const char *args,
746 pwmd_inquire_cb_t callback, void *user);
749 /*! \brief Send a command to the pwmd server.
751 * You should avoid sending the BYE command here because the assuan context
752 * will be freed and bad things will happen. Use \ref pwmd_close() instead.
754 * For pwmd commands that use an INQUIRE to retrieve data from a client, the
755 * \a callback parameter must be non-NULL and will be used to send the data to
756 * pwmd.
758 * \param pwm A handle.
759 * \param[in] result The result of the command when successful which must be
760 * freed with \ref pwmd_free().
761 * \param[in] len The length of \a result.
762 * \param callback A callback function to invoke when pwmd inquires data from
763 * the client.
764 * \param user User data passed to the \a callback function.
765 * \param cmd The command to send and any following arguments.
766 * \return 0 on success or an error code.
768 * \note Not all commands return a \a result.
770 LIBPWMD_API gpg_error_t pwmd_command (pwm_t * pwm, char **result,
771 size_t * len,
772 pwmd_inquire_cb_t callback,
773 void *user, const char *cmd, ...);
776 /*! \brief Send a command to the pwmd server.
778 * Like \ref pwmd_command() but uses an argument pointer instead.
780 * \param pwm A handle.
781 * \param[in] result The result of the command when successful which must be
782 * freed with \ref pwmd_free().
783 * \param[in] len The length of \a result.
784 * \param callback A callback function to invoke when pwmd inquires data from
785 * the client.
786 * \param user User data passed to the \a callback function.
787 * \param cmd The command to send.
788 * \param ap The arguments to \a cmd.
789 * \return 0 on success or an error code.
791 * \note Not all commands return a \a result.
793 LIBPWMD_API gpg_error_t pwmd_command_ap (pwm_t * pwm, char **result,
794 size_t * len,
795 pwmd_inquire_cb_t callback,
796 void *user, const char *cmd,
797 va_list ap);
800 /*! \brief Close a connection to the pwmd server.
802 * This will close the connection but keep any previously set options for the
803 * specified handle. Calling \ref pwmd_connect() will re-acquire an libassuan
804 * context.
806 * \param pwm A handle.
807 * \return 0 on success or an error code.
808 * \see \ref pwmd_close()
810 LIBPWMD_API gpg_error_t pwmd_disconnect (pwm_t * pwm);
813 /*! \brief Close a handle.
815 * This will close the connection to a pwmd server and free any resources
816 * associated with it.
818 * \param pwm A handle.
819 * \return Nothing.
820 * \see \ref pwmd_disconnect(), \ref pwmd_new()
822 LIBPWMD_API void pwmd_close (pwm_t * pwm);
825 /*! \brief The type of connection a handle has.
827 * Useful when you want to know what kind of connection a handle has.
829 * \param pwm A handle.
830 * \param[out] type The type of socket.
831 * \return 0 on success or an error code.
833 * \see \ref pwmd_socket_t
835 LIBPWMD_API gpg_error_t pwmd_socket_type (pwm_t * pwm,
836 pwmd_socket_t * type);
838 /*! \brief Get the file descriptor associated with a handle.
840 * May be useful to determine whether a handle is ready for reading or
841 * writing by using select(2) or poll(2).
843 * \param pwm A handle.
844 * \param[out] fd Set to the file descriptor associated with \a pwm.
845 * \return 0 on success or an error code.
847 LIBPWMD_API gpg_error_t pwmd_fd (pwm_t * pwm, int *fd);
850 /*! \brief Free a previously allocated pointer.
852 * Use this function to free resources allocated by the other libpwmd memory
853 * functions. Do not use it to free allocations made by other allocators.
855 * The difference between the standard free() and this function is that
856 * this one will zero out the contents of the pointer before freeing it.
858 * \param ptr The pointer to deallocate.
859 * \return Nothing.
860 * \see pwmd_malloc(), pwmd_calloc(), pwmd_realloc(), pwmd_strdup(),
861 * pwmd_command()
863 LIBPWMD_API void pwmd_free (void *ptr);
866 /*! \brief A wrapper around malloc.
868 * Like malloc(), but lets libpwmd keep track of the pointer.
870 * \param size The number of bytes to allocate.
871 * \return A newly allocated pointer or NULL if there wasn't enough memory.
872 * \see malloc(3), pwmd_free()
874 LIBPWMD_API void *pwmd_malloc (size_t size);
877 /*! \brief A wrapper around calloc().
879 * Like calloc(), but lets libpwmd keep track of the pointer.
881 * \param nmemb The number of elements to allocate.
882 * \param size The number of bytes to allocate.
883 * \return A newly allocated pointer or NULL if there wasn't enough memory.
884 * \see calloc(3), pwmd_free()
886 LIBPWMD_API void *pwmd_calloc (size_t nmemb, size_t size);
889 /*! \brief A wrapper around realloc().
891 * Like realloc(), but lets libpwmd keep track of the pointer.
893 * \param ptr The pointer to reallocate.
894 * \param size The new number of bytes to allocate.
895 * \return A newly allocated pointer or NULL if there wasn't enough memory.
896 * \see realloc(3), pwmd_free()
898 LIBPWMD_API void *pwmd_realloc (void *ptr, size_t size);
901 /*! \brief A wrapper around strdup().
903 * Like strdup(), but lets libpwmd keep track of the pointer.
905 * \param str The string to duplicate.
906 * \return A newly allocated character pointer or NULL if there wasn't
907 * enough memory.
908 * \see strdup(3), pwmd_free()
910 LIBPWMD_API char *pwmd_strdup (const char *str);
913 /*! \brief Duplicate a formatted string.
915 * Like \ref asprintf(3), but lets libpwmd keep track of the pointer.
917 * \param fmt The formatted string and any following arguments.
918 * \return A newly allocated character pointer or NULL if there wasn't
919 * enough memory.
920 * \see pwmd_free()
922 LIBPWMD_API char *pwmd_strdup_printf (const char *fmt, ...);
924 /*! \brief Convenience declaration.
926 * This allows an application wanting both a TLS connection and libpwmd secure
927 * memory management in GnuTLS, not needing to have the GnuTLS development
928 * files installed. This function should be called before \ref pwmd_init().
930 * It is not done in \ref pwmd_init() itself since the application may have
931 * already initialized GnuTLS by some other means.
933 extern void gnutls_global_set_mem_functions (
934 // gnutls_alloc_function
935 void *(*)(size_t),
936 // gnutls_alloc_function (secure)
937 void *(*)(size_t),
938 // gnutls_is_secure_function
939 int (*)(const void *),
940 // gnutls_realloc_function
941 void *(*)(void *, size_t),
942 // gnutls_free_function
943 void (*)(void *));
945 #ifdef __cplusplus
947 #endif
949 #endif