r9772: Make credentials callbacks more consistant with the abstraction
[samba.git] / source / lib / cmdline / credentials.c
index d827baed76a02254c2b82d136e411a956bc48f2d..f46a03b23652f160952cae35106673dd34155fde 100644 (file)
@@ -29,21 +29,27 @@ static const char *cmdline_get_userpassword(struct cli_credentials *credentials)
 {
        char *prompt;
        char *ret;
-
-       prompt = talloc_asprintf(NULL, "Password for [%s\\%s]:", 
-                                cli_credentials_get_domain(credentials),
-                                cli_credentials_get_username(credentials));
+       const char *domain;
+       const char *username;
+       TALLOC_CTX *mem_ctx = talloc_new(NULL);
+
+       domain = cli_credentials_get_domain(credentials);
+       username = cli_credentials_get_username(credentials, mem_ctx);
+       if (domain && domain[0]) {
+               prompt = talloc_asprintf(mem_ctx, "Password for [%s\\%s]:", 
+                                        domain, username);
+       } else {
+               prompt = talloc_asprintf(mem_ctx, "Password for [%s]:", 
+                                        username);
+       }
 
        ret = getpass(prompt);
 
-       talloc_free(prompt);
+       talloc_free(mem_ctx);
        return ret;
 }
 
 void cli_credentials_set_cmdline_callbacks(struct cli_credentials *cred)
 {
-       if (cred->password_obtained <= CRED_CALLBACK) {
-               cred->password_cb = cmdline_get_userpassword;
-               cred->password_obtained = CRED_CALLBACK;
-       }
+       cli_credentials_set_password_callback(cred, cmdline_get_userpassword);
 }