From patchwork Wed Sep 29 14:39: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: 217392 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 o8TEiEH1008470 for ; Wed, 29 Sep 2010 14:44:16 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752482Ab0I2OoK (ORCPT ); Wed, 29 Sep 2010 10:44:10 -0400 Received: from mail-qy0-f174.google.com ([209.85.216.174]:37336 "EHLO mail-qy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751974Ab0I2OoJ (ORCPT ); Wed, 29 Sep 2010 10:44:09 -0400 Received: by mail-qy0-f174.google.com with SMTP id 36so1119990qyk.19 for ; Wed, 29 Sep 2010 07:44:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer; bh=gugP73BuvDqL2OChnsed7UgfGCX+d6pJb1gTnImkt34=; b=pYbl/dO4+HW+IcuimbU8GPJ73XfHcpG9EgGlAgu9hrhkpa3yaySrU+cQwLFyS3f6kj 05ceJUmoBQm4mpTY+QmvTypZqmSemoOap/Fg2xeCvJ1owr/Skrkg47mbJ3uf2S/LRE7Q K+8NrH+6X/Z23ikBQpUcocRlZE0gDv34h5dNI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=hZEfhSLmcuz3Kxrej6iZ40TcDrbR2KZ9pijKznuYPUsMvOT8JgsZUlkxErdl+bdKPB NjtweG07kiFatIFAm86Fl6H+LkzIx3Hq9EbWsRLRMbq2dGh+PKMwPrqO8odvmUdY1McA 9fy/6hci2+4bD0BI2wp1kPkMptQyXqDMwlJkU= Received: by 10.224.29.3 with SMTP id o3mr1228719qac.215.1285771446376; Wed, 29 Sep 2010 07:44:06 -0700 (PDT) Received: from localhost ([32.97.110.58]) by mx.google.com with ESMTPS id f15sm9522586qcr.37.2010.09.29.07.44.04 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 29 Sep 2010 07:44:05 -0700 (PDT) From: shirishpargaonkar@gmail.com To: smfrench@gmail.com Cc: linux-cifs@vger.kernel.org, Shirish Pargaonkar Subject: [PATCH 2/7 cifs] ntlm authentication and signing - Build a proper av/ti pair blob for ntlmv2 without extended security authentication Date: Wed, 29 Sep 2010 09:39:04 -0500 Message-Id: <1285771144-23099-1-git-send-email-shirishpargaonkar@gmail.com> X-Mailer: git-send-email 1.6.0.2 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]); Wed, 29 Sep 2010 14:44:16 +0000 (UTC) diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c index 730038a..7ca9c80 100644 --- a/fs/cifs/cifsencrypt.c +++ b/fs/cifs/cifsencrypt.c @@ -263,27 +263,88 @@ void calc_lanman_hash(const char *password, const char *cryptkey, bool encrypt, } #endif /* CIFS_WEAK_PW_HASH */ -/* This is just a filler for ntlmv2 type of security mechanisms. - * Older servers are not very particular about the contents of av pairs - * in the blob and for sec mechs like ntlmv2, there is no negotiation - * as in ntlmssp, so unless domain and server netbios and dns names - * are specified, there is no way to obtain name. In case of ntlmssp, - * server provides that info in type 2 challenge packet +/* Build a proper attribute value/target info pairs blob. + * Fill in netbios and dns domain name and workstation name + * and client time (total five av pairs and + one end of fields indicator. + * Allocate domain name which gets freed when session struct is deallocated. */ static int -build_avpair_blob(struct cifsSesInfo *ses) +build_avpair_blob(struct cifsSesInfo *ses, const struct nls_table *nls_cp) { + unsigned int dlen; + unsigned int wlen; + unsigned int size = 6 * sizeof(struct ntlmssp2_name); + __le64 curtime; + char *defdmname = "WORKGROUP"; + unsigned char *blobptr; struct ntlmssp2_name *attrptr; - ses->tilen = 2 * sizeof(struct ntlmssp2_name); + if (ses->domainName) + dlen = strlen(ses->domainName); + else { + dlen = strlen(defdmname); + ses->domainName = kmalloc(dlen + 1, GFP_KERNEL); + if (!ses->domainName) + return -ENOMEM; + strcpy(ses->domainName, defdmname); + } + + wlen = strlen(ses->server->hostname); + + ses->tilen = size + 2 * (2 * dlen) + 2 * (2 * wlen) + 8; ses->tiblob = kzalloc(ses->tilen, GFP_KERNEL); if (!ses->tiblob) { ses->tilen = 0; cERROR(1, "Challenge target info allocation failure"); return -ENOMEM; } - attrptr = (struct ntlmssp2_name *) ses->tiblob; - attrptr->type = cpu_to_le16(NTLMSSP_DOMAIN_TYPE); + + blobptr = ses->tiblob; + attrptr = (struct ntlmssp2_name *) blobptr; + + attrptr->type = cpu_to_le16(NTLMSSP_AV_NB_DOMAIN_NAME); + attrptr->length = cpu_to_le16(2 * dlen); + blobptr = (unsigned char *)attrptr + sizeof(struct ntlmssp2_name); + if (ses->domainName) + cifs_strtoUCS((__le16 *)blobptr, ses->domainName, dlen, nls_cp); + else + cifs_strtoUCS((__le16 *)blobptr, defdmname, dlen, nls_cp); + + blobptr += 2 * dlen; + attrptr = (struct ntlmssp2_name *) blobptr; + + attrptr->type = cpu_to_le16(NTLMSSP_AV_NB_COMPUTER_NAME); + attrptr->length = cpu_to_le16(2 * wlen); + blobptr = (unsigned char *)attrptr + sizeof(struct ntlmssp2_name); + cifs_strtoUCS((__le16 *)blobptr, ses->server->hostname, wlen, nls_cp); + + blobptr += 2 * wlen; + attrptr = (struct ntlmssp2_name *) blobptr; + + attrptr->type = cpu_to_le16(NTLMSSP_AV_DNS_DOMAIN_NAME); + attrptr->length = cpu_to_le16(2 * dlen); + blobptr = (unsigned char *)attrptr + sizeof(struct ntlmssp2_name); + if (ses->domainName) + cifs_strtoUCS((__le16 *)blobptr, ses->domainName, dlen, nls_cp); + else + cifs_strtoUCS((__le16 *)blobptr, defdmname, dlen, nls_cp); + + blobptr += 2 * dlen; + attrptr = (struct ntlmssp2_name *) blobptr; + + attrptr->type = cpu_to_le16(NTLMSSP_AV_DNS_COMPUTER_NAME); + attrptr->length = cpu_to_le16(2 * wlen); + blobptr = (unsigned char *)attrptr + sizeof(struct ntlmssp2_name); + cifs_strtoUCS((__le16 *)blobptr, ses->server->hostname, wlen, nls_cp); + + blobptr += 2 * wlen; + attrptr = (struct ntlmssp2_name *) blobptr; + + attrptr->type = cpu_to_le16(NTLMSSP_AV_TIMESTAMP); + attrptr->length = cpu_to_le16(sizeof(__le64)); + blobptr = (unsigned char *)attrptr + sizeof(struct ntlmssp2_name); + curtime = cpu_to_le64(cifs_UnixTimeToNT(CURRENT_TIME)); + memcpy(blobptr, &curtime, sizeof(__le64)); return 0; } @@ -426,7 +487,7 @@ setup_ntlmv2_rsp(struct cifsSesInfo *ses, char *resp_buf, } } } else { - rc = build_avpair_blob(ses); + rc = build_avpair_blob(ses, nls_cp); if (rc) { cERROR(1, "error %d building av pair blob", rc); return rc;