Whamcloud - gitweb
LU-3289 gss: gssnull security flavor
[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, Trustees of Indiana University
24  * Author: Andrew Korty <ajk@iu.edu>
25  */
26
27 #define DEBUG_SUBSYSTEM S_SEC
28 #ifdef __KERNEL__
29 #include <linux/init.h>
30 #include <linux/module.h>
31 #include <linux/slab.h>
32 #include <linux/crypto.h>
33 #include <linux/mutex.h>
34 #else
35 #include <liblustre.h>
36 #endif
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 };
49
50 static
51 __u32 gss_import_sec_context_null(rawobj_t *inbuf, struct gss_ctx *gss_context)
52 {
53         struct null_ctx *null_context;
54
55         if (inbuf == NULL || inbuf->data == NULL)
56                 return GSS_S_FAILURE;
57
58         OBD_ALLOC_PTR(null_context);
59         if (null_context == NULL)
60                 return GSS_S_FAILURE;
61
62         gss_context->internal_ctx_id = null_context;
63         CDEBUG(D_SEC, "succesfully imported null context\n");
64
65         return GSS_S_COMPLETE;
66 }
67
68 static
69 __u32 gss_copy_reverse_context_null(struct gss_ctx *gss_context_old,
70                                     struct gss_ctx *gss_context_new)
71 {
72         struct null_ctx *null_context_old;
73         struct null_ctx *null_context_new;
74
75         OBD_ALLOC_PTR(null_context_new);
76         if (null_context_new == NULL)
77                 return GSS_S_FAILURE;
78
79         null_context_old = gss_context_old->internal_ctx_id;
80         memcpy(null_context_new, null_context_old, sizeof *null_context_new);
81         gss_context_new->internal_ctx_id = null_context_new;
82         CDEBUG(D_SEC, "succesfully copied reverse null context\n");
83
84         return GSS_S_COMPLETE;
85 }
86
87 static
88 __u32 gss_inquire_context_null(struct gss_ctx *gss_context,
89                                unsigned long *endtime)
90 {
91         *endtime = 0;
92         return GSS_S_COMPLETE;
93 }
94
95 static
96 __u32 gss_wrap_null(struct gss_ctx *gss_context, rawobj_t *gss_header,
97                     rawobj_t *message, int message_buffer_length,
98                     rawobj_t *token)
99 {
100         return GSS_S_COMPLETE;
101 }
102
103 static
104 __u32 gss_unwrap_null(struct gss_ctx *gss_context, rawobj_t *gss_header,
105                       rawobj_t *token, rawobj_t *message)
106 {
107         return GSS_S_COMPLETE;
108 }
109
110 static
111 __u32 gss_prep_bulk_null(struct gss_ctx *gss_context,
112                          struct ptlrpc_bulk_desc *desc)
113 {
114         return GSS_S_COMPLETE;
115 }
116
117 static
118 __u32 gss_wrap_bulk_null(struct gss_ctx *gss_context,
119                          struct ptlrpc_bulk_desc *desc, rawobj_t *token,
120                          int adj_nob)
121 {
122         return GSS_S_COMPLETE;
123 }
124
125 static
126 __u32 gss_unwrap_bulk_null(struct gss_ctx *gss_context,
127                            struct ptlrpc_bulk_desc *desc,
128                            rawobj_t *token, int adj_nob)
129 {
130         return GSS_S_COMPLETE;
131 }
132
133 static
134 void gss_delete_sec_context_null(void *internal_context)
135 {
136         struct null_ctx *null_context = internal_context;
137
138         OBD_FREE_PTR(null_context);
139 }
140
141 int gss_display_null(struct gss_ctx *gss_context, char *buf, int bufsize)
142 {
143         return snprintf(buf, bufsize, "null");
144 }
145
146 static struct gss_api_ops gss_null_ops = {
147         .gss_import_sec_context     = gss_import_sec_context_null,
148         .gss_copy_reverse_context   = gss_copy_reverse_context_null,
149         .gss_inquire_context        = gss_inquire_context_null,
150         .gss_get_mic                = NULL,
151         .gss_verify_mic             = NULL,
152         .gss_wrap                   = gss_wrap_null,
153         .gss_unwrap                 = gss_unwrap_null,
154         .gss_prep_bulk              = gss_prep_bulk_null,
155         .gss_wrap_bulk              = gss_wrap_bulk_null,
156         .gss_unwrap_bulk            = gss_unwrap_bulk_null,
157         .gss_delete_sec_context     = gss_delete_sec_context_null,
158         .gss_display                = gss_display_null,
159 };
160
161 static struct subflavor_desc gss_null_sfs[] = {
162         {
163                 .sf_subflavor   = SPTLRPC_SUBFLVR_GSSNULL,
164                 .sf_qop         = 0,
165                 .sf_service     = SPTLRPC_SVC_NULL,
166                 .sf_name        = "gssnull"
167         },
168 };
169
170 /*
171  * currently we leave module owner NULL
172  */
173 static struct gss_api_mech gss_null_mech = {
174         .gm_owner       = NULL, /*THIS_MODULE, */
175         .gm_name        = "gssnull",
176         .gm_oid         = (rawobj_t) {
177                 12,
178                 "\053\006\001\004\001\311\146\215\126\001\000\000"
179         },
180         .gm_ops         = &gss_null_ops,
181         .gm_sf_num      = 1,
182         .gm_sfs         = gss_null_sfs,
183 };
184
185 int __init init_null_module(void)
186 {
187         int status;
188
189         status = lgss_mech_register(&gss_null_mech);
190         if (status)
191                 CERROR("Failed to register null gss mechanism!\n");
192
193         return status;
194 }
195
196 void cleanup_null_module(void)
197 {
198         lgss_mech_unregister(&gss_null_mech);
199 }