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