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/>.
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
;
32 name
= cli_credentials_get_unparsed_name(creds
, frame
);
36 label
= talloc_asprintf(frame
, "Password for [%s]:", name
);
40 rc
= samba_getpass(label
, pwd
, sizeof(pwd
), false, false);
44 ret
= talloc_strdup(creds
, pwd
);
48 talloc_set_name_const(ret
, __location__
);
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
71 return cli_credentials_set_password_callback(cred
,
72 cmdline_get_userpassword
);