From patchwork Mon Sep 13 16:46:04 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shirish Pargaonkar X-Patchwork-Id: 174992 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o8DGk8s1023473 for ; Mon, 13 Sep 2010 16:46:09 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753204Ab0IMQqH (ORCPT ); Mon, 13 Sep 2010 12:46:07 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:46225 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752867Ab0IMQqH convert rfc822-to-8bit (ORCPT ); Mon, 13 Sep 2010 12:46:07 -0400 Received: by wyf22 with SMTP id 22so6393340wyf.19 for ; Mon, 13 Sep 2010 09:46:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=tQdjEzTW1iPV0sNmU/fcaDB+Tb5gGeAYqRSox8CX2Mg=; b=GB/WtVIVk+KC/Hzor4XF3XU2pIbF6Azb7emNbr+FKkwe0uk41HLzJqY7cuUf9xRVpJ i75cFFH4RlXB5hdW0rRIB5DEJG6j12/6C742YAc08pFgzJ9lndyGOqCFJ4TRypki5479 GUQMegmAG817qMwO4GkXuY4QbFm7PMBXiI+no= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=vsK0TWO4TjqSyj0gRcbI8YruHpvJlDAgUqH4uHGNIJOT7MX2qLqFifB9PMuBHmwA4h aEuyTrw+48FjuyCQ/WODF3tg6Cex2TeVbLq0mZ8eSuKI6hJzM4FjQb1k+pQig3HO1WRl TX/wfoAuipsRHBvcSwa1XQqvMXm/k4JjWkW9g= MIME-Version: 1.0 Received: by 10.216.90.140 with SMTP id e12mr4623158wef.9.1284396364329; Mon, 13 Sep 2010 09:46:04 -0700 (PDT) Received: by 10.216.201.105 with HTTP; Mon, 13 Sep 2010 09:46:04 -0700 (PDT) In-Reply-To: <20100912084639.5c1bf654@tlielax.poochiereds.net> References: <1284055939-767-1-git-send-email-shirishpargaonkar@gmail.com> <20100912084639.5c1bf654@tlielax.poochiereds.net> Date: Mon, 13 Sep 2010 11:46:04 -0500 Message-ID: Subject: Re: [PATCH -v2 1/6] functions to either extract or create av_ pair/ti_info blob From: Shirish Pargaonkar To: Jeff Layton Cc: smfrench@gmail.com, linux-cifs@vger.kernel.org Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Mon, 13 Sep 2010 16:46:09 +0000 (UTC) diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c index a547d24..82cf8e3 100644 --- a/fs/cifs/cifsencrypt.c +++ b/fs/cifs/cifsencrypt.c @@ -293,47 +293,55 @@ build_avpair_blob(struct cifsSesInfo *ses) * We parse that blob here to find netbios domain name to be used * as part of ntlmv2 authentication (in Target String), if not already * specified on the command line. + * If this function returns without any error but without fetching + * domain name, authentication may fail against some server but + * may not fail against other (those who are not very particular + * about target string i.e. for some, just user name might suffice. */ static int find_domain_name(struct cifsSesInfo *ses) { - int rc = 0; unsigned int attrsize; unsigned int type; unsigned char *blobptr; unsigned char *blobend; struct ntlmssp2_name *attrptr; - if (ses->tiblob) { - blobend = ses->tiblob + ses->tilen; - blobptr = ses->tiblob; - attrptr = (struct ntlmssp2_name *) blobptr; + if (!ses->tilen || !ses->tiblob) + return 0; + + if (ses->tilen < sizeof(struct ntlmssp2_name)) + return 0; - while (blobptr <= blobend && - (type = attrptr->type) != NTLMSSP_AV_EOL) { - blobptr += 2; /* advance attr type */ - attrsize = attrptr->length; - blobptr += 2; /* advance attr size */ - if (type == NTLMSSP_AV_NB_DOMAIN_NAME) { - if (!ses->domainName) { - ses->domainName = - kmalloc(attrptr->length + 1, - GFP_KERNEL); - if (!ses->domainName) - return -ENOMEM; - cifs_from_ucs2(ses->domainName, - (__le16 *)blobptr, - attrptr->length, - attrptr->length, - load_nls_default(), false); - } + blobend = ses->tiblob + ses->tilen; + blobptr = ses->tiblob; + attrptr = (struct ntlmssp2_name *) blobptr; + + while (blobptr <= blobend) { + type = le16_to_cpu(attrptr->type); + if (type == NTLMSSP_AV_EOL) + break; + blobptr += 2; /* advance attr type */ + attrsize = le16_to_cpu(attrptr->length); + blobptr += 2; /* advance attr size */ + if (type == NTLMSSP_AV_NB_DOMAIN_NAME) { + if (!ses->domainName) { + ses->domainName = + kmalloc(attrsize+ 1, GFP_KERNEL); + if (!ses->domainName) + return -ENOMEM; + cifs_from_ucs2(ses->domainName, + (__le16 *)blobptr, + attrptr->length, + attrptr->length, + load_nls_default(), false); } - blobptr += attrsize; /* advance attr value */ - attrptr = (struct ntlmssp2_name *) blobptr; } + blobptr += attrsize; /* advance attr value */ + attrptr = (struct ntlmssp2_name *) blobptr; } - return rc; + return 0; } static int calc_ntlmv2_hash(struct cifsSesInfo *ses,