1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2004 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
23 # define EXPORT_SYMTAB
25 #define DEBUG_SUBSYSTEM S_SEC
27 #include <linux/init.h>
28 #include <linux/module.h>
29 #include <linux/slab.h>
31 #include <liblustre.h>
34 #include <libcfs/kp30.h>
35 #include <linux/obd_support.h>
36 #include <linux/lustre_net.h>
37 #include <linux/lustre_sec.h>
39 static int null_cred_refresh(struct ptlrpc_cred *cred)
42 LASSERT(cred->pc_flags & PTLRPC_CRED_UPTODATE);
46 static int null_cred_match(struct ptlrpc_cred *cred,
47 struct vfs_cred *vcred)
53 static int null_cred_sign(struct ptlrpc_cred *cred,
54 struct ptlrpc_request *req)
56 struct ptlrpcs_wire_hdr *hdr = buf_to_sec_hdr(req->rq_reqbuf);
59 hdr->sec_len = cpu_to_le32(0);
64 static int null_cred_verify(struct ptlrpc_cred *cred,
65 struct ptlrpc_request *req)
67 struct ptlrpcs_wire_hdr *hdr = buf_to_sec_hdr(req->rq_repbuf);
69 if (hdr->sec_len != 0) {
70 CERROR("security payload %u not zero\n", hdr->sec_len);
74 req->rq_repmsg = (struct lustre_msg *)(hdr + 1);
75 req->rq_replen = hdr->msg_len;
76 CDEBUG(D_SEC, "set repmsg at %p, len %d\n",
77 req->rq_repmsg, req->rq_replen);
82 static void null_cred_destroy(struct ptlrpc_cred *cred)
84 LASSERT(!atomic_read(&cred->pc_refcount));
86 CDEBUG(D_SEC, "NULL_SEC: destroy cred %p\n", cred);
87 OBD_FREE(cred, sizeof(*cred));
90 static struct ptlrpc_credops null_credops = {
91 .refresh = null_cred_refresh,
92 .match = null_cred_match,
93 .sign = null_cred_sign,
94 .verify = null_cred_verify,
95 .destroy = null_cred_destroy,
99 struct ptlrpc_sec* null_create_sec(ptlrpcs_flavor_t *flavor,
100 const char *pipe_dir,
103 struct ptlrpc_sec *sec;
106 LASSERT(flavor->flavor == PTLRPC_SEC_NULL);
108 OBD_ALLOC(sec, sizeof(*sec));
110 RETURN(ERR_PTR(-ENOMEM));
112 sec->ps_sectype = PTLRPC_SEC_TYPE_NONE;
113 sec->ps_expire = (-1UL >> 1); /* never expire */
114 sec->ps_nextgc = (-1UL >> 1);
117 CDEBUG(D_SEC, "Create NULL security module at %p\n", sec);
122 void null_destroy_sec(struct ptlrpc_sec *sec)
126 CDEBUG(D_SEC, "Destroy NULL security module at %p\n", sec);
128 LASSERT(!atomic_read(&sec->ps_refcount));
129 OBD_FREE(sec, sizeof(*sec));
134 struct ptlrpc_cred* null_create_cred(struct ptlrpc_sec *sec,
135 struct vfs_cred *vcred)
137 struct ptlrpc_cred *cred;
140 OBD_ALLOC(cred, sizeof(*cred));
144 INIT_LIST_HEAD(&cred->pc_hash);
145 atomic_set(&cred->pc_refcount, 0);
147 cred->pc_ops = &null_credops;
148 cred->pc_expire = (-1UL >> 1); /* never expire */
149 cred->pc_flags = PTLRPC_CRED_UPTODATE;
150 cred->pc_pag = vcred->vc_pag;
151 cred->pc_uid = vcred->vc_uid;
152 CDEBUG(D_SEC, "create a null cred at %p("LPU64"/%u)\n",
153 cred, vcred->vc_pag, vcred->vc_uid);
158 static struct ptlrpc_secops null_secops = {
159 .create_sec = null_create_sec,
160 .destroy_sec = null_destroy_sec,
161 .create_cred = null_create_cred,
164 static struct ptlrpc_sec_type null_type = {
165 .pst_owner = THIS_MODULE,
166 .pst_name = "NULL_SEC",
167 .pst_inst = ATOMIC_INIT(0),
168 .pst_flavor = {PTLRPC_SEC_NULL, 0},
169 .pst_ops = &null_secops,
172 int ptlrpcs_null_init(void)
176 rc = ptlrpcs_register(&null_type);
178 CERROR("failed to register NULL security: %d\n", rc);
183 int ptlrpcs_null_exit(void)
187 rc = ptlrpcs_unregister(&null_type);
189 CERROR("cannot unregister NULL security: %d\n", rc);