2 exec nbdkit cc
"$0" "$@" EXTRA_CFLAGS
="-I.. -I${SRCDIR:-.}/../include"
5 * Copyright (C) 2013-2020 Red Hat Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * * Neither the name of Red Hat nor the names of its contributors may be
19 * used to endorse or promote products derived from this software without
20 * specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
26 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
29 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 /* See test-read-password.sh and test-read-password-interactive.sh */
44 #define NBDKIT_API_VERSION 2
45 #include <nbdkit-plugin.h>
47 static char *password
;
51 password_unload (void)
58 password_config (const char *key
, const char *value
)
60 if (strcmp (key
, "password") == 0) {
61 if (nbdkit_read_password (value
, &password
) == -1)
64 else if (strcmp (key
, "file") == 0) {
65 file
= nbdkit_absolute_path (value
);
70 nbdkit_error ("unknown parameter: %s", key
);
77 password_config_complete (void)
81 if (!file
|| !password
) {
82 nbdkit_error ("file and password parameters are required");
85 fp
= fopen (file
, "w");
87 nbdkit_error ("%s: %m", file
);
90 fprintf (fp
, "%s", password
);
96 password_get_ready (void)
98 /* This plugin is for testing, so it never serves any data. */
104 password_open (int readonly
)
110 password_get_size (void *handle
)
115 #define THREAD_MODEL NBDKIT_THREAD_MODEL_PARALLEL
118 password_pread (void *handle
, void *buf
, uint32_t count
, uint64_t offset
,
124 static struct nbdkit_plugin plugin
= {
126 .version
= PACKAGE_VERSION
,
127 .unload
= password_unload
,
128 .config
= password_config
,
129 .config_complete
= password_config_complete
,
130 .get_ready
= password_get_ready
,
131 .open
= password_open
,
132 .get_size
= password_get_size
,
133 .pread
= password_pread
,
136 NBDKIT_REGISTER_PLUGIN(plugin
)