From 27a1327b49210e342741cf8fb11576983cbcc36d Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 22 Nov 2012 15:22:40 +0100 Subject: util: Add a UNIX platform independent samba_getpass(). Reviewed-by: Jelmer Vernooij --- lib/util/samba_util.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'lib/util/samba_util.h') diff --git a/lib/util/samba_util.h b/lib/util/samba_util.h index 4a6dd3bc80..e553ec1342 100644 --- a/lib/util/samba_util.h +++ b/lib/util/samba_util.h @@ -816,6 +816,46 @@ _PUBLIC_ void close_low_fds(bool stdin_too, bool stdout_too, bool stderr_too); **/ _PUBLIC_ void become_daemon(bool do_fork, bool no_process_group, bool log_stdout); +/** + * @brief Get a password from the console. + * + * You should make sure that the buffer is an empty string! + * + * You can also use this function to ask for a username. Then you can fill the + * buffer with the username and it is shows to the users. If the users just + * presses enter the buffer will be untouched. + * + * @code + * char username[128]; + * + * snprintf(username, sizeof(username), "john"); + * + * smb_getpass("Username:", username, sizeof(username), 1, 0); + * @endcode + * + * The prompt will look like this: + * + * Username: [john] + * + * If you press enter then john is used as the username, or you can type it in + * to change it. + * + * @param[in] prompt The prompt to show to ask for the password. + * + * @param[out] buf The buffer the password should be stored. It NEEDS to be + * empty or filled out. + * + * @param[in] len The length of the buffer. + * + * @param[in] echo Should we echo what you type. + * + * @param[in] verify Should we ask for the password twice. + * + * @return 0 on success, -1 on error. + */ +_PUBLIC_ int samba_getpass(const char *prompt, char *buf, size_t len, + bool echo, bool verify); + /** * Load a ini-style file. */ -- cgit