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=-FDcannot be used with stdin, stdout or stderr (ie.password=-0,password=-1orpassword=-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-soption 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-soption. πͺ
β¨ RETURN VALUE β¨
The function returns 0 on success. π
If there is an error it calls nbdkit_error(3) and returns -1. π
β¨ LANGUAGE BINDINGS β¨
NBDKit.read_password : string -> string
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 β¨
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
- fedora 44: nbdkit-devel 1.48.1-1.fc44 Β· BSD-3-Clause
- fedora 44: nbdkit-devel 1.48.1-1.fc44 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms