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