Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / ptlrpc / gss / sec_gss.c
index a777e9b..f3aae3f 100644 (file)
@@ -2,8 +2,9 @@
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
  * Modifications for Lustre
- * Copyright 2004 - 2007, Cluster File Systems, Inc.
- * All rights reserved
+ *
+ * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ *
  * Author: Eric Mei <ericm@clusterfs.com>
  */
 
@@ -734,7 +735,7 @@ int gss_cli_ctx_verify(struct ptlrpc_cli_ctx *ctx,
         struct gss_header      *ghdr, *reqhdr;
         struct lustre_msg      *msg = req->rq_repdata;
         __u32                   major;
-        int                     pack_bulk, early = 0, rc = 0;
+        int                     pack_bulk, rc = 0;
         ENTRY;
 
         LASSERT(req->rq_cli_ctx == ctx);
@@ -742,13 +743,9 @@ int gss_cli_ctx_verify(struct ptlrpc_cli_ctx *ctx,
 
         gctx = container_of(ctx, struct gss_cli_ctx, gc_base);
 
-        if ((char *) msg < req->rq_repbuf ||
-            (char *) msg >= req->rq_repbuf + req->rq_repbuf_len)
-                early = 1;
-
         /* special case for context negotiation, rq_repmsg/rq_replen actually
          * are not used currently. but early reply always be treated normally */
-        if (req->rq_ctx_init && !early) {
+        if (req->rq_ctx_init && !req->rq_early) {
                 req->rq_repmsg = lustre_msg_buf(msg, 1, 0);
                 req->rq_replen = msg->lm_buflens[1];
                 RETURN(0);
@@ -779,7 +776,7 @@ int gss_cli_ctx_verify(struct ptlrpc_cli_ctx *ctx,
         case PTLRPC_GSS_PROC_DATA:
                 pack_bulk = ghdr->gh_flags & LUSTRE_GSS_PACK_BULK;
 
-                if (!early && !equi(req->rq_pack_bulk == 1, pack_bulk)) {
+                if (!req->rq_early && !equi(req->rq_pack_bulk == 1, pack_bulk)){
                         CERROR("%s bulk flag in reply\n",
                                req->rq_pack_bulk ? "missing" : "unexpected");
                         RETURN(-EPROTO);
@@ -804,7 +801,7 @@ int gss_cli_ctx_verify(struct ptlrpc_cli_ctx *ctx,
                 if (major != GSS_S_COMPLETE)
                         RETURN(-EPERM);
 
-                if (early && reqhdr->gh_svc == SPTLRPC_SVC_NULL) {
+                if (req->rq_early && reqhdr->gh_svc == SPTLRPC_SVC_NULL) {
                         __u32 cksum;
 
                         cksum = crc32_le(!(__u32) 0,
@@ -836,7 +833,7 @@ int gss_cli_ctx_verify(struct ptlrpc_cli_ctx *ctx,
                 req->rq_replen = msg->lm_buflens[1];
                 break;
         case PTLRPC_GSS_PROC_ERR:
-                if (early) {
+                if (req->rq_early) {
                         CERROR("server return error with early reply\n");
                         rc = -EPROTO;
                 } else {
@@ -857,8 +854,8 @@ int gss_cli_ctx_seal(struct ptlrpc_cli_ctx *ctx,
         struct gss_cli_ctx      *gctx;
         rawobj_t                 hdrobj, msgobj, token;
         struct gss_header       *ghdr;
-        int                      buflens[2], wiresize, rc;
-        __u32                    major;
+        __u32                    buflens[2], major;
+        int                      wiresize, rc;
         ENTRY;
 
         LASSERT(req->rq_clrbuf);
@@ -956,7 +953,7 @@ int gss_cli_ctx_unseal(struct ptlrpc_cli_ctx *ctx,
         struct gss_cli_ctx      *gctx;
         struct gss_header       *ghdr;
         struct lustre_msg       *msg = req->rq_repdata;
-        int                      msglen, pack_bulk, early = 0, rc;
+        int                      msglen, pack_bulk, rc;
         __u32                    major;
         ENTRY;
 
@@ -966,10 +963,6 @@ int gss_cli_ctx_unseal(struct ptlrpc_cli_ctx *ctx,
 
         gctx = container_of(ctx, struct gss_cli_ctx, gc_base);
 
-        if ((char *) msg < req->rq_repbuf ||
-            (char *) msg >= req->rq_repbuf + req->rq_repbuf_len)
-                early = 1;
-
         ghdr = gss_swab_header(msg, 0);
         if (ghdr == NULL) {
                 CERROR("can't decode gss header\n");
@@ -987,7 +980,7 @@ int gss_cli_ctx_unseal(struct ptlrpc_cli_ctx *ctx,
         case PTLRPC_GSS_PROC_DATA:
                 pack_bulk = ghdr->gh_flags & LUSTRE_GSS_PACK_BULK;
 
-                if (!early && !equi(req->rq_pack_bulk == 1, pack_bulk)) {
+                if (!req->rq_early && !equi(req->rq_pack_bulk == 1, pack_bulk)){
                         CERROR("%s bulk flag in reply\n",
                                req->rq_pack_bulk ? "missing" : "unexpected");
                         RETURN(-EPROTO);
@@ -1035,7 +1028,12 @@ int gss_cli_ctx_unseal(struct ptlrpc_cli_ctx *ctx,
                 rc = 0;
                 break;
         case PTLRPC_GSS_PROC_ERR:
-                rc = gss_cli_ctx_handle_err_notify(ctx, req, ghdr);
+                if (req->rq_early) {
+                        CERROR("server return error with early reply\n");
+                        rc = -EPROTO;
+                } else {
+                        rc = gss_cli_ctx_handle_err_notify(ctx, req, ghdr);
+                }
                 break;
         default:
                 CERROR("unexpected proc %d\n", ghdr->gh_proc);
@@ -1089,7 +1087,7 @@ int gss_sec_create_common(struct gss_sec *gsec,
         sec->ps_id = sptlrpc_get_next_secid();
         sec->ps_flvr = *sf;
         sec->ps_import = class_import_get(imp);
-        sec->ps_lock = SPIN_LOCK_UNLOCKED;
+        spin_lock_init(&sec->ps_lock);
         CFS_INIT_LIST_HEAD(&sec->ps_gc_list);
 
         if (!svcctx) {
@@ -1215,7 +1213,8 @@ int gss_alloc_reqbuf_intg(struct ptlrpc_sec *sec,
                           int svc, int msgsize)
 {
         int                       bufsize, txtsize;
-        int                       buflens[5], bufcnt = 2;
+        int                       bufcnt = 2;
+        __u32                     buflens[5];
         ENTRY;
 
         /*
@@ -1295,8 +1294,8 @@ int gss_alloc_reqbuf_priv(struct ptlrpc_sec *sec,
                           struct ptlrpc_request *req,
                           int msgsize)
 {
-        int                       ibuflens[3], ibufcnt;
-        int                       wbuflens[2];
+        __u32                     ibuflens[3], wbuflens[2];
+        int                       ibufcnt;
         int                       clearsize, wiresize;
         ENTRY;
 
@@ -1452,7 +1451,8 @@ int gss_alloc_repbuf_intg(struct ptlrpc_sec *sec,
                           int svc, int msgsize)
 {
         int             txtsize;
-        int             buflens[4], bufcnt = 2;
+        __u32           buflens[4];
+        int             bufcnt = 2;
         int             alloc_size;
 
         /*
@@ -1504,7 +1504,8 @@ int gss_alloc_repbuf_priv(struct ptlrpc_sec *sec,
                           int msgsize)
 {
         int             txtsize;
-        int             buflens[2], bufcnt;
+        __u32           buflens[2];
+        int             bufcnt;
         int             alloc_size;
 
         /* inner buffers */
@@ -1684,7 +1685,7 @@ int gss_enlarge_reqbuf_priv(struct ptlrpc_sec *sec,
 {
         struct lustre_msg      *newclrbuf;
         int                     newmsg_size, newclrbuf_size, newcipbuf_size;
-        int                     buflens[3];
+        __u32                   buflens[3];
 
         /*
          * embedded msg is at seg 0 of clear buffer;
@@ -1868,7 +1869,10 @@ int gss_svc_sign(struct ptlrpc_request *req,
         rs->rs_repdata_len = rc;
 
         if (likely(req->rq_packed_final)) {
-                req->rq_reply_off = gss_at_reply_off_integ;
+                if (lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT)
+                        req->rq_reply_off = gss_at_reply_off_integ;
+                else
+                        req->rq_reply_off = 0;
         } else {
                 if (svc == SPTLRPC_SVC_NULL)
                         rs->rs_repbuf->lm_cksum = crc32_le(!(__u32) 0,
@@ -2406,8 +2410,8 @@ int gss_svc_alloc_rs(struct ptlrpc_request *req, int msglen)
         struct gss_svc_reqctx       *grctx;
         struct ptlrpc_reply_state   *rs;
         int                          early, privacy, svc, bsd_off = 0;
-        int                          ibuflens[2], ibufcnt = 0;
-        int                          buflens[4], bufcnt;
+        __u32                        ibuflens[2], buflens[4];
+        int                          ibufcnt = 0, bufcnt;
         int                          txtsize, wmsg_size, rs_size;
         ENTRY;
 
@@ -2527,9 +2531,9 @@ static int gss_svc_seal(struct ptlrpc_request *req,
         rawobj_t                 hdrobj, msgobj, token;
         struct gss_header       *ghdr;
         __u8                    *token_buf;
-        int                      token_buflen, buflens[2];
+        int                      token_buflen; 
+        __u32                    buflens[2], major;
         int                      msglen, rc;
-        __u32                    major;
         ENTRY;
 
         /* get clear data length. note embedded lustre_msg might
@@ -2600,7 +2604,8 @@ static int gss_svc_seal(struct ptlrpc_request *req,
         memcpy(lustre_msg_buf(rs->rs_repbuf, 1, 0), token.data, token.len);
 
         /* reply offset */
-        if (likely(req->rq_packed_final))
+        if (req->rq_packed_final &&
+            (lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT))
                 req->rq_reply_off = gss_at_reply_off_priv;
         else
                 req->rq_reply_off = 0;
@@ -2737,7 +2742,8 @@ err_out:
 
 static void gss_init_at_reply_offset(void)
 {
-        int buflens[3], clearsize;
+        __u32 buflens[3];
+        int clearsize;
 
         buflens[0] = PTLRPC_GSS_HEADER_SIZE;
         buflens[1] = lustre_msg_early_size();
@@ -2817,7 +2823,7 @@ static void __exit sptlrpc_gss_exit(void)
         gss_exit_lproc();
 }
 
-MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
+MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
 MODULE_DESCRIPTION("GSS security policy for Lustre");
 MODULE_LICENSE("GPL");