Whamcloud - gitweb
LU-17744 ldiskfs: mballoc stats fixes
[fs/lustre-release.git] / lustre / ptlrpc / gss / gss_null_mech.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (C) 2013, 2015, Trustees of Indiana University
24  *
25  * Copyright (c) 2014, Intel Corporation.
26  *
27  * Author: Jeremy Filizetti <jfilizet@iu.edu>
28  * Author: Andrew Korty <ajk@iu.edu>
29  */
30
31 #define DEBUG_SUBSYSTEM S_SEC
32 #include <linux/init.h>
33 #include <linux/module.h>
34 #include <linux/slab.h>
35 #include <linux/crypto.h>
36 #include <linux/mutex.h>
37
38 #include <obd.h>
39 #include <obd_class.h>
40 #include <obd_support.h>
41
42 #include "gss_err.h"
43 #include "gss_internal.h"
44 #include "gss_api.h"
45 #include "gss_asn1.h"
46
47 struct null_ctx {
48         __u64 nc_token;
49 };
50
51 static
52 __u32 gss_import_sec_context_null(rawobj_t *inbuf, struct gss_ctx *gss_context)
53 {
54         struct null_ctx *null_context;
55
56         if (inbuf == NULL || inbuf->data == NULL ||
57             inbuf->len != sizeof(*null_context)) {
58                 CDEBUG(D_SEC, "Invalid input buffer for null context\n");
59                 return GSS_S_FAILURE;
60         }
61
62         OBD_ALLOC_PTR(null_context);
63         if (null_context == NULL)
64                 return GSS_S_FAILURE;
65
66         memcpy(&null_context->nc_token, inbuf->data, inbuf->len);
67
68         gss_context->internal_ctx_id = null_context;
69         CDEBUG(D_SEC, "successfully imported null context\n");
70
71         return GSS_S_COMPLETE;
72 }
73
74 static
75 __u32 gss_copy_reverse_context_null(struct gss_ctx *gss_context_old,
76                                     struct gss_ctx *gss_context_new)
77 {
78         struct null_ctx *null_context_old;
79         struct null_ctx *null_context_new;
80
81         OBD_ALLOC_PTR(null_context_new);
82         if (null_context_new == NULL)
83                 return GSS_S_FAILURE;
84
85         null_context_old = gss_context_old->internal_ctx_id;
86         memcpy(null_context_new, null_context_old, sizeof(*null_context_new));
87         gss_context_new->internal_ctx_id = null_context_new;
88         CDEBUG(D_SEC, "successfully copied reverse null context\n");
89
90         return GSS_S_COMPLETE;
91 }
92
93 static
94 __u32 gss_inquire_context_null(struct gss_ctx *gss_context,
95                                time64_t *endtime)
96 {
97         /* quick timeout for testing purposes */
98         *endtime = ktime_get_real_seconds() + 60;
99         return GSS_S_COMPLETE;
100 }
101
102 static
103 __u32 gss_wrap_null(struct gss_ctx *gss_context, rawobj_t *gss_header,
104                     rawobj_t *message, int message_buffer_length,
105                     rawobj_t *token)
106 {
107         return GSS_S_COMPLETE;
108 }
109
110 static
111 __u32 gss_unwrap_null(struct gss_ctx *gss_context, rawobj_t *gss_header,
112                       rawobj_t *token, rawobj_t *message)
113 {
114         return GSS_S_COMPLETE;
115 }
116
117 static
118 __u32 gss_prep_bulk_null(struct gss_ctx *gss_context,
119                          struct ptlrpc_bulk_desc *desc)
120 {
121         return GSS_S_COMPLETE;
122 }
123
124 static
125 __u32 gss_wrap_bulk_null(struct gss_ctx *gss_context,
126                          struct ptlrpc_bulk_desc *desc, rawobj_t *token,
127                          int adj_nob)
128 {
129         return GSS_S_COMPLETE;
130 }
131
132 static
133 __u32 gss_unwrap_bulk_null(struct gss_ctx *gss_context,
134                            struct ptlrpc_bulk_desc *desc,
135                            rawobj_t *token, int adj_nob)
136 {
137         return GSS_S_COMPLETE;
138 }
139
140 static
141 void gss_delete_sec_context_null(void *internal_context)
142 {
143         struct null_ctx *null_context = internal_context;
144
145         OBD_FREE_PTR(null_context);
146 }
147
148 static
149 int gss_display_null(struct gss_ctx *gss_context, char *buf, int bufsize)
150 {
151         return scnprintf(buf, bufsize, "null");
152 }
153
154 static
155 __u32 gss_get_mic_null(struct gss_ctx *gss_context, int message_count,
156                        rawobj_t *messages, int iov_count, struct bio_vec *iovs,
157                        rawobj_t *token)
158 {
159         return GSS_S_COMPLETE;
160 }
161
162 static
163 __u32 gss_verify_mic_null(struct gss_ctx *gss_context, int message_count,
164                           rawobj_t *messages, int iov_count,
165                           struct bio_vec *iovs,
166                           rawobj_t *token)
167 {
168         return GSS_S_COMPLETE;
169 }
170
171 static struct gss_api_ops gss_null_ops = {
172         .gss_import_sec_context     = gss_import_sec_context_null,
173         .gss_copy_reverse_context   = gss_copy_reverse_context_null,
174         .gss_inquire_context        = gss_inquire_context_null,
175         .gss_get_mic                = gss_get_mic_null,
176         .gss_verify_mic             = gss_verify_mic_null,
177         .gss_wrap                   = gss_wrap_null,
178         .gss_unwrap                 = gss_unwrap_null,
179         .gss_prep_bulk              = gss_prep_bulk_null,
180         .gss_wrap_bulk              = gss_wrap_bulk_null,
181         .gss_unwrap_bulk            = gss_unwrap_bulk_null,
182         .gss_delete_sec_context     = gss_delete_sec_context_null,
183         .gss_display                = gss_display_null,
184 };
185
186 static struct subflavor_desc gss_null_sfs[] = {
187         {
188                 .sf_subflavor   = SPTLRPC_SUBFLVR_GSSNULL,
189                 .sf_qop         = 0,
190                 .sf_service     = SPTLRPC_SVC_NULL,
191                 .sf_name        = "gssnull"
192         },
193 };
194
195 static struct gss_api_mech gss_null_mech = {
196         /* .gm_owner uses default NULL value for THIS_MODULE */
197         .gm_name        = "gssnull",
198         .gm_oid         = (rawobj_t) {
199                 12,
200                 "\053\006\001\004\001\311\146\215\126\001\000\000"
201         },
202         .gm_ops         = &gss_null_ops,
203         .gm_sf_num      = 1,
204         .gm_sfs         = gss_null_sfs,
205 };
206
207 int __init init_null_module(void)
208 {
209         int status;
210
211         status = lgss_mech_register(&gss_null_mech);
212         if (status)
213                 CERROR("Failed to register null gss mechanism!\n");
214
215         return status;
216 }
217
218 void cleanup_null_module(void)
219 {
220         lgss_mech_unregister(&gss_null_mech);
221 }