Whamcloud - gitweb
land lustre part of b_hd_sec on HEAD.
[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(hdr->flavor == PTLRPC_SEC_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_reqmsg = (struct lustre_msg *)(hdr + 1);
55         req->rq_reqlen = hdr->msg_len;
56         *res = PTLRPCS_OK;
57         CDEBUG(D_SEC, "req %p: set reqmsg at %p, len %d\n",
58                req, req->rq_reqmsg, req->rq_reqlen);
59         RETURN(SVC_OK);
60 }
61
62 static
63 int null_svcsec_authorize(struct ptlrpc_request *req)
64 {
65         struct ptlrpc_reply_state *rs = req->rq_reply_state;
66         struct ptlrpcs_wire_hdr *hdr;
67         ENTRY;
68
69         LASSERT(rs);
70         LASSERT(rs->rs_repbuf_len >= 4 * 4);
71
72         hdr = buf_to_sec_hdr(rs->rs_repbuf);
73         hdr->flavor = cpu_to_le32(PTLRPC_SEC_NULL);
74         hdr->sectype = cpu_to_le32(PTLRPC_SEC_TYPE_AUTH);
75         hdr->msg_len = cpu_to_le32(req->rq_replen);
76         hdr->sec_len = cpu_to_le32(0);
77
78         CDEBUG(D_SEC, "fill in datasize %d\n", rs->rs_repdata_len);
79         RETURN(0);
80 }
81
82 static struct ptlrpc_svcsec null_svcsec = {
83         .pss_owner      = THIS_MODULE,
84         .pss_name       = "NULL_SVCSEC",
85         .pss_flavor     = {PTLRPC_SEC_NULL, 0},
86         .accept         = null_svcsec_accept,
87         .authorize      = null_svcsec_authorize,
88 };
89
90 int svcsec_null_init()
91 {
92         int rc;
93
94         rc = svcsec_register(&null_svcsec);
95         if (rc)
96                 CERROR("failed to register SVCNULL security: %d\n", rc);
97
98         return rc;
99 }
100
101 int svcsec_null_exit()
102 {
103         int rc;
104
105         rc = svcsec_unregister(&null_svcsec);
106         if (rc)
107                 CERROR("cannot unregister SVCNULL security: %d\n", rc);
108
109         return rc;
110 }
111