nbdkit_read_password(3)

✨ NAME ✨

nbdkit_read_password β€” read passwords and other secrets for nbdkit πŸ’–

(okay so this whole page lives in the NBDKIT manual, bestie, and it's all about one lil function that grabs secrets for you πŸŽ€)


✨ SYNOPSIS ✨

#include <nbdkit-plugin.h>

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

✨ DESCRIPTION ✨

So like, nbdkit_read_password is this utility function you can use to read passwords out of config parameters. That's it, that's the job 🫢

Heads up tho β€” the password result string is allocated by malloc, so you may need to free it yourself. She's giving you the keys, not a cleanup crew. πŸ’…

🌸 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 🌸

You can just slap a password right on the command line, like:

nbdkit myplugin password=mostsecret
🚨 But this is insecure, no cap. Any user on the same machine can see the command line. Everyone's nosy, bestie, they're all in your business. 😭

Also important: a - and a + at the beginning of the value have a special meaning (peep below πŸ‘€). So if your plaintext password literally starts with a - or + character, then it must be passed in a file. No exceptions, periodt.

🌸 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. Like genuinely bad. Don't do it. πŸ™ˆ

🌸 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. slay ✨
  • 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. πŸ“œ (throwback fr fr)


✨ 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 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.

okay that's the whole thing bestie, ily, go read your passwords safely πŸ’œβœ¨ this was nbdkit-1.48.1 from 2026-08-29, mwah πŸŽ€

πŸ“¦ where this page comes from