s3: smbd: Now we have proved hardlink_internals() doesn't use src_dirfsp and dst_dirf...
[Samba.git] / auth / credentials / credentials_cmdline.c
blobc8c7c183c2213eb1f21984289ac76eca5c3c2d5c
1 /*
2 * Copyright (c) 2005 Jelmer Vernooij <jelmer@samba.org>
3 * Copyright (c) 2016 Stefan Metzmacher <metze@samba.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "includes.h"
20 #include "system/filesys.h"
21 #include "auth/credentials/credentials.h"
23 static const char *cmdline_get_userpassword(struct cli_credentials *creds)
25 TALLOC_CTX *frame = talloc_stackframe();
26 const char *name = NULL;
27 char *label = NULL;
28 char *ret = NULL;
29 char pwd[256] = {0};
30 int rc;
32 name = cli_credentials_get_unparsed_name(creds, frame);
33 if (name == NULL) {
34 goto fail;
36 label = talloc_asprintf(frame, "Password for [%s]:", name);
37 if (label == NULL) {
38 goto fail;
40 rc = samba_getpass(label, pwd, sizeof(pwd), false, false);
41 if (rc != 0) {
42 goto fail;
44 ret = talloc_strdup(creds, pwd);
45 if (ret == NULL) {
46 goto fail;
48 talloc_set_name_const(ret, __location__);
49 fail:
50 ZERO_STRUCT(pwd);
51 TALLOC_FREE(frame);
52 return ret;
55 /**
56 * @brief Set the command line password callback.
58 * This will set the callback to get the password from the command prompt or
59 * read it from 'stdin'.
61 * @param[in] cred The credential context.
63 * @return On success true, false otherwise.
65 bool cli_credentials_set_cmdline_callbacks(struct cli_credentials *cred)
68 * If there is no tty, we will try to read the password from
69 * stdin.
71 return cli_credentials_set_password_callback(cred,
72 cmdline_get_userpassword);