Convert /proc/device-tree/ to seq_file
[safe/jmp/linux-2.6] / fs / cifs / cifs_spnego.c
index 1529d2b..8ec7736 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/string.h>
 #include <keys/user-type.h>
 #include <linux/key-type.h>
+#include <linux/inet.h>
 #include "cifsglob.h"
 #include "cifs_spnego.h"
 #include "cifs_debug.h"
@@ -41,7 +42,7 @@ cifs_spnego_key_instantiate(struct key *key, const void *data, size_t datalen)
 
        /* attach the data */
        memcpy(payload, data, datalen);
-       rcu_assign_pointer(key->payload.data, payload);
+       key->payload.data = payload;
        ret = 0;
 
 error:
@@ -66,11 +67,28 @@ struct key_type cifs_spnego_key_type = {
        .describe       = user_describe,
 };
 
-#define MAX_VER_STR_LEN   9 /* length of longest version string e.g.
-                               strlen(";ver=0xFF") */
-#define MAX_MECH_STR_LEN 13 /* length of longest security mechanism name, eg
-                              in future could have strlen(";sec=ntlmsspi") */
-#define MAX_IPV6_ADDR_LEN 42 /* eg FEDC:BA98:7654:3210:FEDC:BA98:7654:3210/60 */
+/* length of longest version string e.g.  strlen("ver=0xFF") */
+#define MAX_VER_STR_LEN                8
+
+/* length of longest security mechanism name, eg in future could have
+ * strlen(";sec=ntlmsspi") */
+#define MAX_MECH_STR_LEN       13
+
+/* strlen of "host=" */
+#define HOST_KEY_LEN           5
+
+/* strlen of ";ip4=" or ";ip6=" */
+#define IP_KEY_LEN             5
+
+/* strlen of ";uid=0x" */
+#define UID_KEY_LEN            7
+
+/* strlen of ";user=" */
+#define USER_KEY_LEN           6
+
+/* strlen of ";pid=0x" */
+#define PID_KEY_LEN            7
+
 /* get a key struct with a SPNEGO security blob, suitable for session setup */
 struct key *
 cifs_get_spnego_key(struct cifsSesInfo *sesInfo)
@@ -81,11 +99,16 @@ cifs_get_spnego_key(struct cifsSesInfo *sesInfo)
        struct key *spnego_key;
        const char *hostname = server->hostname;
 
-       /* BB: come up with better scheme for determining length */
-       /* length of fields (with semicolons): ver=0xyz ipv4= ipaddress host=
-          hostname sec=mechanism uid=0x uid */
-       desc_len = MAX_VER_STR_LEN + 5 + MAX_IPV6_ADDR_LEN + 1 + 6 +
-                 strlen(hostname) + MAX_MECH_STR_LEN + 8 + (sizeof(uid_t) * 2);
+       /* length of fields (with semicolons): ver=0xyz ip4=ipaddress
+          host=hostname sec=mechanism uid=0xFF user=username */
+       desc_len = MAX_VER_STR_LEN +
+                  HOST_KEY_LEN + strlen(hostname) +
+                  IP_KEY_LEN + INET6_ADDRSTRLEN +
+                  MAX_MECH_STR_LEN +
+                  UID_KEY_LEN + (sizeof(uid_t) * 2) +
+                  USER_KEY_LEN + strlen(sesInfo->userName) +
+                  PID_KEY_LEN + (sizeof(pid_t) * 2) + 1;
+
        spnego_key = ERR_PTR(-ENOMEM);
        description = kzalloc(desc_len, GFP_KERNEL);
        if (description == NULL)
@@ -100,33 +123,41 @@ cifs_get_spnego_key(struct cifsSesInfo *sesInfo)
 
        /* add the server address */
        if (server->addr.sockAddr.sin_family == AF_INET)
-               sprintf(dp, "ip4=" NIPQUAD_FMT,
-                       NIPQUAD(server->addr.sockAddr.sin_addr));
+               sprintf(dp, "ip4=%pI4", &server->addr.sockAddr.sin_addr);
        else if (server->addr.sockAddr.sin_family == AF_INET6)
-               sprintf(dp, "ip6=" NIP6_SEQFMT,
-                       NIP6(server->addr.sockAddr6.sin6_addr));
+               sprintf(dp, "ip6=%pI6", &server->addr.sockAddr6.sin6_addr);
        else
                goto out;
 
        dp = description + strlen(description);
 
-       /* for now, only sec=krb5 is valid */
+       /* for now, only sec=krb5 and sec=mskrb5 are valid */
        if (server->secType == Kerberos)
                sprintf(dp, ";sec=krb5");
+       else if (server->secType == MSKerberos)
+               sprintf(dp, ";sec=mskrb5");
        else
                goto out;
 
        dp = description + strlen(description);
        sprintf(dp, ";uid=0x%x", sesInfo->linux_uid);
 
+       dp = description + strlen(description);
+       sprintf(dp, ";user=%s", sesInfo->userName);
+
+       dp = description + strlen(description);
+       sprintf(dp, ";pid=0x%x", current->pid);
+
        cFYI(1, ("key description = %s", description));
        spnego_key = request_key(&cifs_spnego_key_type, description, "");
 
+#ifdef CONFIG_CIFS_DEBUG2
        if (cifsFYI && !IS_ERR(spnego_key)) {
                struct cifs_spnego_msg *msg = spnego_key->payload.data;
-               cifs_dump_mem("SPNEGO reply blob:", msg->data,
-                               msg->secblob_len + msg->sesskey_len);
+               cifs_dump_mem("SPNEGO reply blob:", msg->data, min(1024U,
+                               msg->secblob_len + msg->sesskey_len));
        }
+#endif /* CONFIG_CIFS_DEBUG2 */
 
 out:
        kfree(description);