changeset 12937:12cf927830ab

6955216 Negotiate Protocol fails with latest NetApp server 6962072 Tree connect may fail if addr-to-name lookup fails 6962091 Log messages like: ... smb_maperr32: no direct map for... 6962125 Tree connect failed with latest Isilon server 6972321 improve some error messages
author Gordon Ross <Gordon.Ross@Sun.COM>
date Tue, 27 Jul 2010 17:15:36 -0700
parents bef00af5d4ab
children 599476a18982
files usr/src/cmd/fs.d/smbclnt/smbutil/view.c usr/src/lib/libsmbfs/smb/ctx.c usr/src/lib/libsmbfs/smb/getaddr.c usr/src/lib/libsmbfs/smb/negprot.c usr/src/uts/common/fs/smbclnt/netsmb/smb_smb.c usr/src/uts/common/fs/smbclnt/netsmb/smb_subrs.c
diffstat 6 files changed, 61 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/fs.d/smbclnt/smbutil/view.c	Wed Jul 28 08:00:21 2010 +0800
+++ b/usr/src/cmd/fs.d/smbclnt/smbutil/view.c	Tue Jul 27 17:15:36 2010 -0700
@@ -33,8 +33,7 @@
  */
 
 /*
- * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  */
 
 #include <sys/types.h>
@@ -131,12 +130,11 @@
 
 	/*
 	 * Have IPC$ tcon, now list shares.
+	 * This prints its own errors.
 	 */
 	error = enum_shares(ctx);
-	if (error) {
-		smb_error("cannot list shares", error);
+	if (error)
 		return (error);
-	}
 
 	smb_ctx_free(ctx);
 	return (0);
@@ -172,7 +170,8 @@
 	 */
 	error = smb_netshareenum(ctx, &entries, &total, &share_info);
 	if (error) {
-		smb_error(gettext("unable to list resources"), error);
+		smb_error(gettext("//%s failed to list shares"),
+		    error, ctx->ct_fullserver);
 		return (error);
 	}
 	print_shares(entries, total, share_info);
--- a/usr/src/lib/libsmbfs/smb/ctx.c	Wed Jul 28 08:00:21 2010 +0800
+++ b/usr/src/lib/libsmbfs/smb/ctx.c	Tue Jul 27 17:15:36 2010 -0700
@@ -1101,7 +1101,8 @@
 	if (error) {
 		const char *ais = gai_strerror(error);
 		smb_error(dgettext(TEXT_DOMAIN,
-		    "can't get server address, %s"), 0, ais);
+		    "can't resolve name\"%s\", %s"),
+		    0, ctx->ct_fullserver, ais);
 		return (ENODATA);
 	}
 	assert(ctx->ct_addrinfo != NULL);
--- a/usr/src/lib/libsmbfs/smb/getaddr.c	Wed Jul 28 08:00:21 2010 +0800
+++ b/usr/src/lib/libsmbfs/smb/getaddr.c	Tue Jul 27 17:15:36 2010 -0700
@@ -20,8 +20,7 @@
  */
 
 /*
- * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  */
 
 /*
@@ -142,8 +141,6 @@
 	/*
 	 * Default the server name we'll use in the
 	 * protocol (i.e. NTLM, tree connect).
-	 * If we get a canonical name, we'll
-	 * overwrite this below.
 	 */
 	strlcpy(ctx->ct_srvname, ctx->ct_fullserver,
 	    sizeof (ctx->ct_srvname));
@@ -159,25 +156,6 @@
 	hints.ai_socktype = SOCK_STREAM;
 	gaierr = getaddrinfo(srvaddr_str, NULL, &hints, &res);
 	if (gaierr == 0) {
-#if 1
-		/*
-		 * XXX Temporarily work-around CR 6831339:
-		 * getaddrinfo() sets ai_canonname incorrectly
-		 */
-		char tmphost[256];
-		gaierr2 = getnameinfo(res->ai_addr, res->ai_addrlen,
-		    tmphost, sizeof (tmphost),
-		    NULL, 0, NI_NAMEREQD);
-		if (gaierr2 == 0) {
-			DPRINT("cname: %s", tmphost);
-			strlcpy(ctx->ct_srvname, tmphost,
-			    sizeof (ctx->ct_srvname));
-		}
-#else
-		if (res->ai_canonname)
-			strlcpy(ctx->ct_srvname, res->ai_canonname,
-			    sizeof (ctx->ct_srvname));
-#endif
 		ctx->ct_addrinfo = res;
 		return (0);
 	}
@@ -186,9 +164,6 @@
 	 * If regular IP name lookup failed, try NetBIOS,
 	 * but only if given a valid NetBIOS name and if
 	 * NetBIOS name lookup is enabled.
-	 *
-	 * Note: we only have ssn_srvname if the full name
-	 * was also a valid NetBIOS name.
 	 */
 	if (nbc->nb_flags & NBCF_NS_ENABLE) {
 		gaierr2 = nbns_getaddrinfo(ctx->ct_fullserver, nbc, &res);
--- a/usr/src/lib/libsmbfs/smb/negprot.c	Wed Jul 28 08:00:21 2010 +0800
+++ b/usr/src/lib/libsmbfs/smb/negprot.c	Tue Jul 27 17:15:36 2010 -0700
@@ -31,8 +31,7 @@
  */
 
 /*
- * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  */
 
 /*
@@ -111,13 +110,17 @@
 	/*
 	 * Initialize: vc_hflags and vc_hflags2.
 	 * Note: ctx->ct_hflags* are copied into the
-	 * (per request) rqp->rq_hflags* by smb_rq_init,
-	 * so changing them after that call will not
-	 * affect THIS request.
+	 * (per request) rqp->rq_hflags* by smb_rq_init.
+	 *
+	 * Like Windows, set FLAGS2_UNICODE in our first request,
+	 * even though technically we don't yet know whether the
+	 * server supports Unicode.  Will clear this flag below
+	 * if we find out it doesn't.  Need to do this because
+	 * some servers reject all non-Unicode requests.
 	 */
 	ctx->ct_hflags = SMB_FLAGS_CASELESS;
-	ctx->ct_hflags2 = (SMB_FLAGS2_ERR_STATUS |
-	    SMB_FLAGS2_KNOWS_LONG_NAMES);
+	ctx->ct_hflags2 = SMB_FLAGS2_KNOWS_LONG_NAMES |
+	    SMB_FLAGS2_ERR_STATUS | SMB_FLAGS2_UNICODE;
 
 	/*
 	 * Sould we offer extended security?
@@ -276,11 +279,12 @@
 	}
 	DPRINT("Security signatures: %d", will_sign);
 
-	if (sv->sv_caps & SMB_CAP_UNICODE) {
+	/* See comment above re. FLAGS2_UNICODE */
+	if (sv->sv_caps & SMB_CAP_UNICODE)
 		ctx->ct_vcflags |= SMBV_UNICODE;
-		ctx->ct_hflags2 |= SMB_FLAGS2_UNICODE;
+	else
+		ctx->ct_hflags2 &= ~SMB_FLAGS2_UNICODE;
 
-	}
 	if ((sv->sv_caps & SMB_CAP_STATUS32) == 0) {
 		/*
 		 * They don't do NT error codes.
--- a/usr/src/uts/common/fs/smbclnt/netsmb/smb_smb.c	Wed Jul 28 08:00:21 2010 +0800
+++ b/usr/src/uts/common/fs/smbclnt/netsmb/smb_smb.c	Tue Jul 27 17:15:36 2010 -0700
@@ -33,8 +33,7 @@
  */
 
 /*
- * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  */
 
 /*
@@ -126,6 +125,7 @@
 	unc_name = kmem_alloc(unc_len, KM_SLEEP);
 	(void) snprintf(unc_name, unc_len, "\\\\%s\\%s",
 	    vcp->vc_srvname, ssp->ss_name);
+	SMBSDEBUG("unc_name: \"%s\"", unc_name);
 
 	/*
 	 * The password is now pre-computed in the
@@ -178,21 +178,33 @@
 	rqp->sr_flags |= SMBR_NOINTR_RECV;
 	error = smb_rq_simple(rqp);
 	SMBSDEBUG("%d\n", error);
-	if (error)
+	if (error) {
+		/*
+		 * If we get the server name wrong, i.e. due to
+		 * mis-configured name services, this will be
+		 * NT_STATUS_DUPLICATE_NAME.  Log this error.
+		 */
+		SMBERROR("(%s) failed, status=0x%x",
+		    unc_name, rqp->sr_error);
 		goto out;
+	}
 
 	/*
 	 * Parse the TCON response
 	 */
 	smb_rq_getreply(rqp, &mdp);
 	md_get_uint8(mdp, &wc);
-	if (wc != 3) {
+	if (wc != 3 && wc != 7) {
 		error = EBADRPC;
 		goto out;
 	}
 	md_get_uint16le(mdp, NULL);		/* AndX cmd */
 	md_get_uint16le(mdp, NULL);		/* AndX off */
 	md_get_uint16le(mdp, &options);		/* option bits (DFS, search) */
+	if (wc == 7) {
+		md_get_uint32le(mdp, NULL);	/* MaximalShareAccessRights */
+		md_get_uint32le(mdp, NULL);	/* GuestMaximalShareAcc... */
+	}
 	error = md_get_uint16le(mdp, &bcnt);	/* byte count */
 	if (error)
 		goto out;
--- a/usr/src/uts/common/fs/smbclnt/netsmb/smb_subrs.c	Wed Jul 28 08:00:21 2010 +0800
+++ b/usr/src/uts/common/fs/smbclnt/netsmb/smb_subrs.c	Tue Jul 27 17:15:36 2010 -0700
@@ -191,6 +191,19 @@
 #define	ETIME ETIMEDOUT
 #endif
 
+/*
+ * Log any un-handled NT or DOS errors we encounter.
+ * Make these log NOTICE in a debug build to ensure
+ * they get noticed during tests.  In the field these
+ * are unimportant, so just fire a Dtrace probe.
+ */
+static int unknown_err_logpri =
+#ifdef	DEBUG
+	CE_NOTE;
+#else
+	CE_CONT;
+#endif
+
 typedef struct nt2errno {
 	unsigned int nterr;
 	int errno;
@@ -219,6 +232,7 @@
 	{NT_STATUS_DIRECTORY_NOT_EMPTY,		ENOTEMPTY},
 	{NT_STATUS_DISK_FULL,			ENOSPC},
 	{NT_STATUS_DLL_NOT_FOUND,		ELIBACC},
+	{NT_STATUS_DUPLICATE_NAME,		EINVAL},
 	{NT_STATUS_END_OF_FILE,			ENODATA},
 	{NT_STATUS_FILE_IS_A_DIRECTORY,		EISDIR},
 	{NT_STATUS_FILE_LOCK_CONFLICT,		EAGAIN},
@@ -255,9 +269,9 @@
 	{NT_STATUS_NONEXISTENT_SECTOR,		ESPIPE},
 	{NT_STATUS_NONE_MAPPED,			EINVAL},
 	{NT_STATUS_NOT_A_DIRECTORY,		ENOTDIR},
-	{NT_STATUS_NOT_IMPLEMENTED,		ENOSYS},
+	{NT_STATUS_NOT_IMPLEMENTED,		ENOTSUP},
 	{NT_STATUS_NOT_MAPPED_VIEW,		EINVAL},
-	{NT_STATUS_NOT_SUPPORTED,		ENOSYS},
+	{NT_STATUS_NOT_SUPPORTED,		ENOTSUP},
 	{NT_STATUS_NO_MEDIA,			ENOMEDIUM},
 	{NT_STATUS_NO_MEDIA_IN_DEVICE,		ENOMEDIUM},
 	{NT_STATUS_NO_MEMORY,			ENOMEM},
@@ -277,7 +291,7 @@
 	{NT_STATUS_PIPE_BUSY,			EPIPE},
 	{NT_STATUS_PIPE_CONNECTED,		EISCONN},
 	{NT_STATUS_PIPE_DISCONNECTED,		EPIPE},
-	{NT_STATUS_PIPE_NOT_AVAILABLE,		ENOSYS},
+	{NT_STATUS_PIPE_NOT_AVAILABLE,		EBUSY},
 	{NT_STATUS_PORT_CONNECTION_REFUSED,	ECONNREFUSED},
 	{NT_STATUS_PORT_MESSAGE_TOO_LONG,	EMSGSIZE},
 	{NT_STATUS_PORT_UNREACHABLE,		EHOSTUNREACH},
@@ -844,7 +858,8 @@
 	for (nt2e = nt2errno; nt2e->errno; nt2e++)
 		if (nt2e->nterr == nterr)
 			return (nt2e->errno);
-	SMBERROR("no direct map for 32 bit server error (0x%x)\n", nterr);
+	smb_errmsg(unknown_err_logpri, "smb_maperr32",
+	    "No direct map for 32 bit server error (0x%x)\n", nterr);
 
 	/* ok, then try mapping to dos to unix */
 	for (nt2d = nt2doserr; nt2d->nterr; nt2d++)
@@ -973,13 +988,12 @@
 		case ERRdata:
 		case ERRgeneral:
 			return (EIO);
-		default:
-			SMBERROR("Unmapped DOS error %d:%d\n", eclass, eno);
-			return (EIO);
 		}
 	}
-	SMBERROR("Unmapped DOS error %d:%d\n", eclass, eno);
-	return (EBADRPC);
+
+	smb_errmsg(unknown_err_logpri, "smb_maperror",
+	    "Unknown DOS error %d/%d\n", eclass, eno);
+	return (EIO);
 }
 
 #if defined(NOICONVSUPPORT) || defined(lint)