Whamcloud - gitweb
land b_hd_sec on HEAD. various security fixes.
[fs/lustre-release.git] / lustre / sec / svcsec_null.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2004 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #ifndef EXPORT_SYMTAB
23 # define EXPORT_SYMTAB
24 #endif
25 #define DEBUG_SUBSYSTEM S_SEC
26 #ifdef __KERNEL__
27 #include <linux/init.h>
28 #include <linux/module.h>
29 #include <linux/slab.h>
30 #else
31 #include <liblustre.h>
32 #endif
33
34 #include <libcfs/kp30.h>
35 #include <linux/obd_support.h>
36 #include <linux/lustre_idl.h>
37 #include <linux/lustre_net.h>
38 #include <linux/lustre_sec.h>
39
40 static
41 int null_svcsec_accept(struct ptlrpc_request *req, enum ptlrpcs_error *res)
42 {
43         struct ptlrpcs_wire_hdr *hdr = buf_to_sec_hdr(req->rq_reqbuf);
44         ENTRY;
45
46         LASSERT(SEC_FLAVOR_MAJOR(hdr->flavor) == PTLRPCS_FLVR_MAJOR_NULL);
47
48         if (hdr->sec_len != 0) {
49                 CERROR("security payload %d not zero\n", hdr->sec_len);
50                 *res = PTLRPCS_REJECTEDCRED;
51                 RETURN(SVC_DROP);
52         }
53
54         req->rq_req_secflvr = PTLRPCS_FLVR_NULL;
55
56         req->rq_reqmsg = (struct lustre_msg *)(hdr + 1);
57         req->rq_reqlen = hdr->msg_len;
58         *res = PTLRPCS_OK;
59         CDEBUG(D_SEC, "req %p: set reqmsg at %p, len %d\n",
60                req, req->rq_reqmsg, req->rq_reqlen);
61         RETURN(SVC_OK);
62 }
63
64 static
65 int null_svcsec_authorize(struct ptlrpc_request *req)
66 {
67         struct ptlrpc_reply_state *rs = req->rq_reply_state;
68         struct ptlrpcs_wire_hdr *hdr;
69         ENTRY;
70
71         LASSERT(rs);
72         LASSERT(rs->rs_repbuf_len >= 4 * 4);
73
74         hdr = buf_to_sec_hdr(rs->rs_repbuf);
75         hdr->flavor = cpu_to_le32(PTLRPCS_FLVR_NULL);
76         hdr->msg_len = cpu_to_le32(req->rq_replen);
77         hdr->sec_len = cpu_to_le32(0);
78
79         CDEBUG(D_SEC, "fill in datasize %d\n", rs->rs_repdata_len);
80         RETURN(0);
81 }
82
83 static struct ptlrpc_svcsec null_svcsec = {
84         .pss_owner      = THIS_MODULE,
85         .pss_name       = "svcsec.null",
86         .pss_flavor     = PTLRPCS_FLVR_MAJOR_NULL,
87         .accept         = null_svcsec_accept,
88         .authorize      = null_svcsec_authorize,
89 };
90
91 int svcsec_null_init()
92 {
93         int rc;
94
95         rc = svcsec_register(&null_svcsec);
96         if (rc)
97                 CERROR("failed to register SVCNULL security: %d\n", rc);
98
99         return rc;
100 }
101
102 int svcsec_null_exit()
103 {
104         int rc;
105
106         rc = svcsec_unregister(&null_svcsec);
107         if (rc)
108                 CERROR("cannot unregister SVCNULL security: %d\n", rc);
109
110         return rc;
111 }
112