16007Sthurlow /* 26007Sthurlow * Copyright (c) 2001 Apple Computer, Inc. All rights reserved. 36007Sthurlow * 46007Sthurlow * @APPLE_LICENSE_HEADER_START@ 56007Sthurlow * 66007Sthurlow * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights 76007Sthurlow * Reserved. This file contains Original Code and/or Modifications of 86007Sthurlow * Original Code as defined in and that are subject to the Apple Public 96007Sthurlow * Source License Version 1.0 (the 'License'). You may not use this file 106007Sthurlow * except in compliance with the License. Please obtain a copy of the 116007Sthurlow * License at http://www.apple.com/publicsource and read it before using 126007Sthurlow * this file. 136007Sthurlow * 146007Sthurlow * The Original Code and all software distributed under the License are 156007Sthurlow * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 166007Sthurlow * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 176007Sthurlow * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 186007Sthurlow * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the 196007Sthurlow * License for the specific language governing rights and limitations 206007Sthurlow * under the License." 216007Sthurlow * 226007Sthurlow * @APPLE_LICENSE_HEADER_END@ 236007Sthurlow */ 246007Sthurlow 256007Sthurlow /* 266007Sthurlow * Routines for interacting with the user to get credentials 276007Sthurlow * (workgroup/domain, username, password, etc.) 286007Sthurlow */ 296007Sthurlow 306007Sthurlow #include <stdlib.h> 316007Sthurlow #include <stdio.h> 326007Sthurlow #include <string.h> 336007Sthurlow #include <errno.h> 346007Sthurlow #include <unistd.h> 356007Sthurlow #include <libintl.h> 366007Sthurlow #include <ctype.h> 376007Sthurlow 386007Sthurlow #include <netsmb/smb_lib.h> 39*10023SGordon.Ross@Sun.COM #include "private.h" 40*10023SGordon.Ross@Sun.COM #include "ntlm.h" 416007Sthurlow 42*10023SGordon.Ross@Sun.COM #if 0 /* not yet */ 436007Sthurlow #define MAXLINE 127 446007Sthurlow static void 456007Sthurlow smb_tty_prompt(char *prmpt, 466007Sthurlow char *buf, size_t buflen) 476007Sthurlow { 486007Sthurlow char temp[MAXLINE+1]; 496007Sthurlow char *cp; 506007Sthurlow int ch; 516007Sthurlow 526007Sthurlow memset(temp, 0, sizeof (temp)); 536007Sthurlow 546007Sthurlow fprintf(stderr, "%s", prmpt); 556007Sthurlow cp = temp; 566007Sthurlow while ((ch = getc(stdin)) != EOF) { 576007Sthurlow if (ch == '\n' || ch == '\r') 586007Sthurlow break; 596007Sthurlow if (isspace(ch) || iscntrl(ch)) 606007Sthurlow continue; 616007Sthurlow *cp++ = ch; 626007Sthurlow if (cp == &temp[MAXLINE]) 636007Sthurlow break; 646007Sthurlow } 656007Sthurlow 666007Sthurlow /* If input empty, accept default. */ 676007Sthurlow if (cp == temp) 686007Sthurlow return; 696007Sthurlow 706007Sthurlow /* Use input as new value. */ 716007Sthurlow strncpy(buf, temp, buflen); 726007Sthurlow } 73*10023SGordon.Ross@Sun.COM #endif /* not yet */ 746007Sthurlow 75*10023SGordon.Ross@Sun.COM /* 76*10023SGordon.Ross@Sun.COM * Prompt for a new password after auth. failure. 77*10023SGordon.Ross@Sun.COM * (and maybe new user+domain, but not yet) 78*10023SGordon.Ross@Sun.COM */ 796007Sthurlow int 80*10023SGordon.Ross@Sun.COM smb_get_authentication(struct smb_ctx *ctx) 816007Sthurlow { 826007Sthurlow char *npw; 83*10023SGordon.Ross@Sun.COM int err; 84*10023SGordon.Ross@Sun.COM 85*10023SGordon.Ross@Sun.COM /* 86*10023SGordon.Ross@Sun.COM * If we're getting a password, we must be doing 87*10023SGordon.Ross@Sun.COM * some kind of NTLM, possibly after a failure to 88*10023SGordon.Ross@Sun.COM * authenticate using Kerberos. Turn off krb5. 89*10023SGordon.Ross@Sun.COM */ 90*10023SGordon.Ross@Sun.COM ctx->ct_authflags &= ~SMB_AT_KRB5; 916007Sthurlow 92*10023SGordon.Ross@Sun.COM if (ctx->ct_flags & SMBCF_KCFOUND) { 93*10023SGordon.Ross@Sun.COM /* Tried a keychain hash and failed. */ 94*10023SGordon.Ross@Sun.COM /* XXX: delete the KC entry? */ 95*10023SGordon.Ross@Sun.COM ctx->ct_flags |= SMBCF_KCBAD; 96*10023SGordon.Ross@Sun.COM } 97*10023SGordon.Ross@Sun.COM 98*10023SGordon.Ross@Sun.COM if (ctx->ct_flags & SMBCF_NOPWD) 99*10023SGordon.Ross@Sun.COM return (ENOTTY); 100*10023SGordon.Ross@Sun.COM 101*10023SGordon.Ross@Sun.COM if (isatty(STDIN_FILENO)) { 102*10023SGordon.Ross@Sun.COM 103*10023SGordon.Ross@Sun.COM /* Need command-line prompting. */ 104*10023SGordon.Ross@Sun.COM npw = getpassphrase(dgettext(TEXT_DOMAIN, "Password:")); 105*10023SGordon.Ross@Sun.COM if (npw == NULL) 106*10023SGordon.Ross@Sun.COM return (EINTR); 107*10023SGordon.Ross@Sun.COM memset(ctx->ct_password, 0, sizeof (ctx->ct_password)); 108*10023SGordon.Ross@Sun.COM strlcpy(ctx->ct_password, npw, sizeof (ctx->ct_password)); 1096007Sthurlow } else { 1106007Sthurlow 1116007Sthurlow /* 112*10023SGordon.Ross@Sun.COM * XXX: Ask the user for help, possibly via 113*10023SGordon.Ross@Sun.COM * GNOME dbus or some such... (todo). 1146007Sthurlow */ 115*10023SGordon.Ross@Sun.COM smb_error(dgettext(TEXT_DOMAIN, 116*10023SGordon.Ross@Sun.COM "Cannot prompt for a password when input is redirected."), 0); 117*10023SGordon.Ross@Sun.COM return (ENOTTY); 1186007Sthurlow } 1196007Sthurlow 1206007Sthurlow /* 121*10023SGordon.Ross@Sun.COM * Recompute the password hashes. 1226007Sthurlow */ 123*10023SGordon.Ross@Sun.COM if (ctx->ct_password[0]) { 124*10023SGordon.Ross@Sun.COM err = ntlm_compute_lm_hash(ctx->ct_lmhash, ctx->ct_password); 125*10023SGordon.Ross@Sun.COM if (err != 0) 126*10023SGordon.Ross@Sun.COM return (err); 127*10023SGordon.Ross@Sun.COM err = ntlm_compute_nt_hash(ctx->ct_nthash, ctx->ct_password); 128*10023SGordon.Ross@Sun.COM if (err != 0) 129*10023SGordon.Ross@Sun.COM return (err); 130*10023SGordon.Ross@Sun.COM } 1316007Sthurlow 132*10023SGordon.Ross@Sun.COM return (0); 1336007Sthurlow } 1346007Sthurlow 135*10023SGordon.Ross@Sun.COM /*ARGSUSED*/ 1366007Sthurlow int 1376007Sthurlow smb_browse(struct smb_ctx *ctx, int anon) 1386007Sthurlow { 1396007Sthurlow /* 1406007Sthurlow * Let user pick a share. 1416007Sthurlow * Not supported. 1426007Sthurlow */ 1436007Sthurlow return (EINTR); 1446007Sthurlow } 145