14bff34e3Sthurlow /* 24bff34e3Sthurlow * Copyright (c) 2001 Apple Computer, Inc. All rights reserved. 34bff34e3Sthurlow * 44bff34e3Sthurlow * @APPLE_LICENSE_HEADER_START@ 54bff34e3Sthurlow * 64bff34e3Sthurlow * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights 74bff34e3Sthurlow * Reserved. This file contains Original Code and/or Modifications of 84bff34e3Sthurlow * Original Code as defined in and that are subject to the Apple Public 94bff34e3Sthurlow * Source License Version 1.0 (the 'License'). You may not use this file 104bff34e3Sthurlow * except in compliance with the License. Please obtain a copy of the 114bff34e3Sthurlow * License at http://www.apple.com/publicsource and read it before using 124bff34e3Sthurlow * this file. 134bff34e3Sthurlow * 144bff34e3Sthurlow * The Original Code and all software distributed under the License are 154bff34e3Sthurlow * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 164bff34e3Sthurlow * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 174bff34e3Sthurlow * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 184bff34e3Sthurlow * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the 194bff34e3Sthurlow * License for the specific language governing rights and limitations 204bff34e3Sthurlow * under the License." 214bff34e3Sthurlow * 224bff34e3Sthurlow * @APPLE_LICENSE_HEADER_END@ 234bff34e3Sthurlow */ 244bff34e3Sthurlow 254bff34e3Sthurlow /* 264bff34e3Sthurlow * Routines for interacting with the user to get credentials 274bff34e3Sthurlow * (workgroup/domain, username, password, etc.) 284bff34e3Sthurlow */ 294bff34e3Sthurlow 304bff34e3Sthurlow #include <stdlib.h> 314bff34e3Sthurlow #include <stdio.h> 324bff34e3Sthurlow #include <string.h> 334bff34e3Sthurlow #include <errno.h> 344bff34e3Sthurlow #include <unistd.h> 354bff34e3Sthurlow #include <libintl.h> 364bff34e3Sthurlow #include <ctype.h> 374bff34e3Sthurlow 384bff34e3Sthurlow #include <netsmb/smb_lib.h> 39*613a2f6bSGordon Ross #include "private.h" 40*613a2f6bSGordon Ross #include "ntlm.h" 414bff34e3Sthurlow 42*613a2f6bSGordon Ross #if 0 /* not yet */ 434bff34e3Sthurlow #define MAXLINE 127 444bff34e3Sthurlow static void 454bff34e3Sthurlow smb_tty_prompt(char *prmpt, 464bff34e3Sthurlow char *buf, size_t buflen) 474bff34e3Sthurlow { 484bff34e3Sthurlow char temp[MAXLINE+1]; 494bff34e3Sthurlow char *cp; 504bff34e3Sthurlow int ch; 514bff34e3Sthurlow 524bff34e3Sthurlow memset(temp, 0, sizeof (temp)); 534bff34e3Sthurlow 544bff34e3Sthurlow fprintf(stderr, "%s", prmpt); 554bff34e3Sthurlow cp = temp; 564bff34e3Sthurlow while ((ch = getc(stdin)) != EOF) { 574bff34e3Sthurlow if (ch == '\n' || ch == '\r') 584bff34e3Sthurlow break; 594bff34e3Sthurlow if (isspace(ch) || iscntrl(ch)) 604bff34e3Sthurlow continue; 614bff34e3Sthurlow *cp++ = ch; 624bff34e3Sthurlow if (cp == &temp[MAXLINE]) 634bff34e3Sthurlow break; 644bff34e3Sthurlow } 654bff34e3Sthurlow 664bff34e3Sthurlow /* If input empty, accept default. */ 674bff34e3Sthurlow if (cp == temp) 684bff34e3Sthurlow return; 694bff34e3Sthurlow 704bff34e3Sthurlow /* Use input as new value. */ 714bff34e3Sthurlow strncpy(buf, temp, buflen); 724bff34e3Sthurlow } 73*613a2f6bSGordon Ross #endif /* not yet */ 744bff34e3Sthurlow 75*613a2f6bSGordon Ross /* 76*613a2f6bSGordon Ross * Prompt for a new password after auth. failure. 77*613a2f6bSGordon Ross * (and maybe new user+domain, but not yet) 78*613a2f6bSGordon Ross */ 794bff34e3Sthurlow int 80*613a2f6bSGordon Ross smb_get_authentication(struct smb_ctx *ctx) 814bff34e3Sthurlow { 824bff34e3Sthurlow char *npw; 83*613a2f6bSGordon Ross int err; 844bff34e3Sthurlow 854bff34e3Sthurlow /* 86*613a2f6bSGordon Ross * If we're getting a password, we must be doing 87*613a2f6bSGordon Ross * some kind of NTLM, possibly after a failure to 88*613a2f6bSGordon Ross * authenticate using Kerberos. Turn off krb5. 894bff34e3Sthurlow */ 90*613a2f6bSGordon Ross ctx->ct_authflags &= ~SMB_AT_KRB5; 91*613a2f6bSGordon Ross 92*613a2f6bSGordon Ross if (ctx->ct_flags & SMBCF_KCFOUND) { 93*613a2f6bSGordon Ross /* Tried a keychain hash and failed. */ 94*613a2f6bSGordon Ross /* XXX: delete the KC entry? */ 95*613a2f6bSGordon Ross ctx->ct_flags |= SMBCF_KCBAD; 964bff34e3Sthurlow } 974bff34e3Sthurlow 98*613a2f6bSGordon Ross if (ctx->ct_flags & SMBCF_NOPWD) 99*613a2f6bSGordon Ross return (ENOTTY); 1004bff34e3Sthurlow 101*613a2f6bSGordon Ross if (isatty(STDIN_FILENO)) { 102*613a2f6bSGordon Ross 103*613a2f6bSGordon Ross /* Need command-line prompting. */ 1044bff34e3Sthurlow npw = getpassphrase(dgettext(TEXT_DOMAIN, "Password:")); 105*613a2f6bSGordon Ross if (npw == NULL) 106*613a2f6bSGordon Ross return (EINTR); 107*613a2f6bSGordon Ross memset(ctx->ct_password, 0, sizeof (ctx->ct_password)); 108*613a2f6bSGordon Ross strlcpy(ctx->ct_password, npw, sizeof (ctx->ct_password)); 109*613a2f6bSGordon Ross } else { 1104bff34e3Sthurlow 1114bff34e3Sthurlow /* 1124bff34e3Sthurlow * XXX: Ask the user for help, possibly via 1134bff34e3Sthurlow * GNOME dbus or some such... (todo). 1144bff34e3Sthurlow */ 1154bff34e3Sthurlow smb_error(dgettext(TEXT_DOMAIN, 1164bff34e3Sthurlow "Cannot prompt for a password when input is redirected."), 0); 1174bff34e3Sthurlow return (ENOTTY); 1184bff34e3Sthurlow } 1194bff34e3Sthurlow 120*613a2f6bSGordon Ross /* 121*613a2f6bSGordon Ross * Recompute the password hashes. 122*613a2f6bSGordon Ross */ 123*613a2f6bSGordon Ross if (ctx->ct_password[0]) { 124*613a2f6bSGordon Ross err = ntlm_compute_lm_hash(ctx->ct_lmhash, ctx->ct_password); 125*613a2f6bSGordon Ross if (err != 0) 126*613a2f6bSGordon Ross return (err); 127*613a2f6bSGordon Ross err = ntlm_compute_nt_hash(ctx->ct_nthash, ctx->ct_password); 128*613a2f6bSGordon Ross if (err != 0) 129*613a2f6bSGordon Ross return (err); 130*613a2f6bSGordon Ross } 131*613a2f6bSGordon Ross 132*613a2f6bSGordon Ross return (0); 133*613a2f6bSGordon Ross } 134*613a2f6bSGordon Ross 135*613a2f6bSGordon Ross /*ARGSUSED*/ 1364bff34e3Sthurlow int 1374bff34e3Sthurlow smb_browse(struct smb_ctx *ctx, int anon) 1384bff34e3Sthurlow { 1394bff34e3Sthurlow /* 1404bff34e3Sthurlow * Let user pick a share. 1414bff34e3Sthurlow * Not supported. 1424bff34e3Sthurlow */ 1434bff34e3Sthurlow return (EINTR); 1444bff34e3Sthurlow } 145