Whamcloud - gitweb
land b_hd_sec_client_oss onto HEAD.
[fs/lustre-release.git] / lustre / sec / gss / sec_gss.c
index d3cf0d1..13293db 100644 (file)
@@ -92,6 +92,7 @@ struct rpc_clnt;
 
 static int secinit_compose_request(struct obd_import *imp,
                                    char *buf, int bufsize,
+                                   int lustre_srv,
                                    uid_t uid, gid_t gid,
                                    long token_size,
                                    char __user *token)
@@ -115,7 +116,7 @@ static int secinit_compose_request(struct obd_import *imp,
         hdr->flavor  = cpu_to_le32(PTLRPC_SEC_GSS);
         hdr->sectype = cpu_to_le32(PTLRPC_SEC_TYPE_NONE);
         hdr->msg_len = cpu_to_le32(lmsg_size);
-        hdr->sec_len = cpu_to_le32(7 * 4 + token_size);
+        hdr->sec_len = cpu_to_le32(8 * 4 + token_size);
 
         /* lustre message & secdesc */
         lmsg = buf_to_lustre_msg(buf);
@@ -142,6 +143,9 @@ static int secinit_compose_request(struct obd_import *imp,
         *p++ = cpu_to_le32(PTLRPC_GSS_SVC_NONE);        /* service */
         *p++ = cpu_to_le32(0);                          /* context handle */
 
+        /* plus lustre svc type */
+        *p++ = cpu_to_le32(lustre_srv);
+
         /* now the token part */
         *p++ = cpu_to_le32((__u32) token_size);
         LASSERT(((char *)p - buf) + token_size <= bufsize);
@@ -245,6 +249,7 @@ static int secinit_parse_reply(char *repbuf, int replen,
 struct lgssd_ioctl_param {
         int             version;        /* in   */
         char           *uuid;           /* in   */
+        int             lustre_svc;     /* in   */
         uid_t           uid;            /* in   */
         gid_t           gid;            /* in   */
         long            send_token_size;/* in   */
@@ -258,6 +263,7 @@ struct lgssd_ioctl_param {
 static int gss_send_secinit_rpc(__user char *buffer, unsigned long count)
 {
         struct obd_import        *imp;
+        struct ptlrpc_request    *request = NULL;
         struct lgssd_ioctl_param  param;
         const int                 reqbuf_size = 1024;
         const int                 repbuf_size = 1024;
@@ -268,11 +274,14 @@ static int gss_send_secinit_rpc(__user char *buffer, unsigned long count)
         int                       rc, reqlen, replen;
 
         if (count != sizeof(param)) {
-                CERROR("partial write\n");
+                CERROR("ioctl size %lu, expect %d, please check lgssd version\n",
+                        count, sizeof(param));
                 RETURN(-EINVAL);
         }
-        if (copy_from_user(&param, buffer, sizeof(param)))
+        if (copy_from_user(&param, buffer, sizeof(param))) {
+                CERROR("failed copy data from lgssd\n");
                 RETURN(-EFAULT);
+        }
 
         if (param.version != GSSD_INTERFACE_VERSION) {
                 CERROR("gssd interface version %d (expect %d)\n",
@@ -292,11 +301,6 @@ static int gss_send_secinit_rpc(__user char *buffer, unsigned long count)
                 CERROR("no such obd %s\n", obdname);
                 RETURN(-EINVAL);
         }
-        if (strcmp(obd->obd_type->typ_name, "mdc") &&
-            strcmp(obd->obd_type->typ_name, "osc")) {
-                CERROR("%s not a mdc/osc device\n", obdname);
-                RETURN(-EINVAL);
-        }
 
         imp = class_import_get(obd->u.cli.cl_import);
 
@@ -311,6 +315,7 @@ static int gss_send_secinit_rpc(__user char *buffer, unsigned long count)
 
         /* get token */
         reqlen = secinit_compose_request(imp, reqbuf, reqbuf_size,
+                                         param.lustre_svc,
                                          param.uid, param.gid,
                                          param.send_token_size,
                                          param.send_token);
@@ -319,10 +324,10 @@ static int gss_send_secinit_rpc(__user char *buffer, unsigned long count)
                 goto out_copy;
         }
 
-        replen = repbuf_size;
-        rc = ptlrpc_do_rawrpc(imp, reqbuf, reqlen,
-                              repbuf, &replen, SECINIT_RPC_TIMEOUT);
-        if (rc) {
+        request = ptl_do_rawrpc(imp, reqbuf, reqbuf_size, reqlen,
+                                repbuf, repbuf_size, &replen,
+                                SECINIT_RPC_TIMEOUT, &rc);
+        if (request == NULL || rc) {
                 param.status = rc;
                 goto out_copy;
         }
@@ -351,32 +356,15 @@ out_copy:
                 rc = 0;
 
         class_import_put(imp);
-        if (repbuf)
-                OBD_FREE(repbuf, repbuf_size);
-        if (reqbuf)
-                OBD_FREE(reqbuf, reqbuf_size);
-        RETURN(rc);
-}
-
-static int gss_send_secfini_rpc(struct obd_import *imp,
-                                char *reqbuf, int reqlen)
-{
-        const int repbuf_size = 1024;
-        char *repbuf;
-        int replen = repbuf_size;
-        int rc;
-
-        OBD_ALLOC(repbuf, repbuf_size);
-        if (!repbuf) {
-                CERROR("Out of memory\n");
-                return -ENOMEM;
+        if (request == NULL) {
+                if (repbuf)
+                        OBD_FREE(repbuf, repbuf_size);
+                if (reqbuf)
+                        OBD_FREE(reqbuf, reqbuf_size);
+        } else {
+                rawrpc_req_finished(request);
         }
-
-        rc = ptlrpc_do_rawrpc(imp, reqbuf, reqlen, repbuf, &replen,
-                              SECFINI_RPC_TIMEOUT);
-
-        OBD_FREE(repbuf, repbuf_size);
-        return rc;
+        RETURN(rc);
 }
 
 /**********************************************
@@ -748,9 +736,9 @@ static int gss_cred_refresh(struct ptlrpc_cred *cred)
 
         obdtype = import->imp_obd->obd_type->typ_name;
         if (!strcmp(obdtype, "mdc"))
-                gmd.gum_svc = 0;
+                gmd.gum_svc = LUSTRE_GSS_SVC_MDS;
         else if (!strcmp(obdtype, "osc"))
-                gmd.gum_svc = 1;
+                gmd.gum_svc = LUSTRE_GSS_SVC_OSS;
         else {
                 CERROR("gss on %s?\n", obdtype);
                 RETURN(-EINVAL);
@@ -1313,6 +1301,10 @@ static void destroy_gss_context(struct ptlrpc_cred *cred)
         struct ptlrpc_request    req;
         struct obd_import       *imp;
         __u32                   *vp, lmsg_size;
+        struct ptlrpc_request   *raw_req = NULL;
+        const int                repbuf_len = 256;
+        char                    *repbuf;
+        int                      replen, rc;
         ENTRY;
 
         /* cred's refcount is 0, steal one */
@@ -1379,10 +1371,21 @@ static void destroy_gss_context(struct ptlrpc_cred *cred)
         }
         atomic_dec(&cred->pc_refcount);
 
-        /* send out */
-        gss_send_secfini_rpc(imp, req.rq_reqbuf, req.rq_reqdata_len);
+        OBD_ALLOC(repbuf, repbuf_len);
+        if (!repbuf)
+                goto exit;
+
+        raw_req = ptl_do_rawrpc(imp, req.rq_reqbuf, req.rq_reqbuf_len,
+                                req.rq_reqdata_len, repbuf, repbuf_len, &replen,
+                                SECFINI_RPC_TIMEOUT, &rc);
+        if (!raw_req)
+                OBD_FREE(repbuf, repbuf_len);
+
 exit:
-        OBD_FREE(req.rq_reqbuf, req.rq_reqbuf_len);
+        if (raw_req == NULL)
+                OBD_FREE(req.rq_reqbuf, req.rq_reqbuf_len);
+        else
+                rawrpc_req_finished(raw_req);
         EXIT;
 }