2 * Copyright (c) 2001 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
26 * Routines for interacting with the user to get credentials
27 * (workgroup/domain, username, password, etc.)
38 #include <netsmb/smb_lib.h>
45 smb_tty_prompt(char *prmpt
,
46 char *buf
, size_t buflen
)
52 memset(temp
, 0, sizeof (temp
));
54 fprintf(stderr
, "%s", prmpt
);
56 while ((ch
= getc(stdin
)) != EOF
) {
57 if (ch
== '\n' || ch
== '\r')
59 if (isspace(ch
) || iscntrl(ch
))
62 if (cp
== &temp
[MAXLINE
])
66 /* If input empty, accept default. */
70 /* Use input as new value. */
71 strncpy(buf
, temp
, buflen
);
76 * Prompt for a new password after auth. failure.
77 * (and maybe new user+domain, but not yet)
80 smb_get_authentication(struct smb_ctx
*ctx
)
86 * If we're getting a password, we must be doing
87 * some kind of NTLM, possibly after a failure to
88 * authenticate using Kerberos. Turn off krb5.
90 ctx
->ct_authflags
&= ~SMB_AT_KRB5
;
92 if (ctx
->ct_flags
& SMBCF_KCFOUND
) {
93 /* Tried a keychain hash and failed. */
94 /* XXX: delete the KC entry? */
95 ctx
->ct_flags
|= SMBCF_KCBAD
;
98 if (ctx
->ct_flags
& SMBCF_NOPWD
)
101 if (isatty(STDIN_FILENO
)) {
103 /* Need command-line prompting. */
104 npw
= getpassphrase(dgettext(TEXT_DOMAIN
, "Password:"));
107 memset(ctx
->ct_password
, 0, sizeof (ctx
->ct_password
));
108 strlcpy(ctx
->ct_password
, npw
, sizeof (ctx
->ct_password
));
112 * XXX: Ask the user for help, possibly via
113 * GNOME dbus or some such... (todo).
115 smb_error(dgettext(TEXT_DOMAIN
,
116 "Cannot prompt for a password when input is redirected."), 0);
121 * Recompute the password hashes.
123 if (ctx
->ct_password
[0]) {
124 err
= ntlm_compute_lm_hash(ctx
->ct_lmhash
, ctx
->ct_password
);
127 err
= ntlm_compute_nt_hash(ctx
->ct_nthash
, ctx
->ct_password
);
137 smb_browse(struct smb_ctx
*ctx
, int anon
)
140 * Let user pick a share.