nbdkit_read_password3
Read passwords and other secrets for nbdkit
Usage
#include <nbdkit-plugin.h>int nbdkit_read_password (const char *value, char **password);
Overview
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 intmyplugin_config (const char *key, const char *value){..if (strcmp (key, "password") == 0) {free (password);if (nbdkit_read_password (value, &password) == -1)return -1;}..}
Password formats
This function recognizes several password formats. A password may be used directly on the command line, eg:
nbdkit myplugin password=mostsecret
But more securely this function can also read a password interactively:
nbdkit myplugin password=-
or from a file:
nbdkit myplugin password=+/tmp/secret
or from a file descriptor inherited by nbdkit:
nbdkit myplugin password=-99
Notes on reading passwords
If the password begins with a "-" or "+" character then it must be passed in a file.
"password=-" can only be used when stdin is a terminal.
"password=-FD" cannot be used with stdin, stdout or stderr (ie. -0, -1 or -2). The reason is that after reading the password the file descriptor is closed, which causes bad stuff to happen.
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
import nbdkitpassword = nbdkit.parse_size(value)