diff mbox

[-v2,1/6] functions to either extract or create av_ pair/ti_info blob

Message ID AANLkTi=PjqK78VubpC2hh29fR3hLa59rcVsPimcoofpo@mail.gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Shirish Pargaonkar Sept. 13, 2010, 4:46 p.m. UTC
None
diff mbox

Patch

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,