nbdkit_read_password(3)

NAME
nbdkit_read_password - read passwords and other secrets for nbdkit

SYNOPSIS
 #include <nbdkit-plugin.h>

 int nbdkit_read_password (const char *value, char **password);

DESCRIPTION
The "nbdkit_read_password" utility function can be used to read passwords from config parameters.

The "password" result string is allocated by malloc, and so you may need to free it.

  Example
 char *password = NULL;

 static void
 myplugin_unload (void)
 {
   /* Free password when the plugin is unloaded. */
   free (password);
 }

 static int
 myplugin_config (const char *key, const char *value)
 {
   ..
   if (strcmp (key, "password") == 0) {
     free (password);
     if (nbdkit_read_password (value, &password) == -1)
       return -1;
   }
   ..
 }

  Password directly on the command line
A password may be used directly on the command line, eg:

 nbdkit myplugin password=mostsecret

This is insecure since any user on the same machine can see the command line.

"-" and "+" at the beginning of the value have a special meaning (see below). Therefore if the plaintext password begins with a "-" or "+" character then it must be passed in a file.

  Password from a file
Use "+FILENAME" to read from a file:

 nbdkit myplugin password=+/tmp/secret

  Password from a file descriptor
Use "-FD" to read the password from a file descriptor inherited by nbdkit (fd=99 in this example):

 nbdkit myplugin password=-99

"password=-FD" cannot be used with stdin, stdout or stderr (ie. "password=-0", "password=-1" or "password=-2"). The reason is that after reading the password the file descriptor is closed, which causes bad stuff to happen.

  Read password interactively
To read a password interactively:

 nbdkit myplugin password=-

In nbdkit ≤ 1.46, "password=-" read the password from stdin and did not work with the nbdkit -s option.

In nbdkit ≥ 1.48:

•   Except on Windows, "password=-" opens /dev/tty. This works with the -s option or if stdin is redirected.

•   On Windows, "password=-" still reads from the standard input handle and so behaves the same as in earlier versions, including being incompatible with the -s option.

RETURN VALUE
The function returns 0 on success.

If there is an error it calls nbdkit_error(3) and returns -1.

LANGUAGE BINDINGS
In nbdkit-ocaml-plugin(3):

 NBDKit.read_password : string -> string

In nbdkit-python-plugin(3):

 import nbdkit
 password = nbdkit.read_password(value)

HISTORY
"nbdkit_read_password" was added in nbdkit 1.12.

SEE ALSO
nbdkit(1), nbdkit_stdio_safe(3), nbdkit-plugin(3), nbdkit-filter(3), nbdkit-luks-filter(1), readpassphrase(3).

AUTHORS
Richard W.M. Jones

COPYRIGHT
Copyright Red Hat

LICENSE
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

•   Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

•   Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

•   Neither the name of Red Hat nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.