Whamcloud - gitweb
LU-3289 gss: Add userspace support for GSS null and sk
[fs/lustre-release.git] / lustre / utils / gss / lgss_null_utils.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) 2015, Trustees of Indiana University
24  *
25  * Author: Jeremy Filizetti <jfilizet@iu.edu>
26  */
27
28 #include <string.h>
29 #include <time.h>
30 #include <libcfs/byteorder.h>
31 #include "lgss_utils.h"
32
33 static int lgss_null_prepare_cred(struct lgss_cred *cred)
34 {
35         uint64_t tmp;
36
37         cred->lc_mech_token.value = malloc(sizeof(uint64_t));
38         if (!cred->lc_mech_token.value)
39                 return -1;
40         cred->lc_mech_token.length = sizeof(uint64_t);
41
42         /* random token so it's not cached by the other side */
43         tmp = random();
44         tmp <<= 32;
45
46         /* Sec part flags needed on the other end */
47         tmp |= cred->lc_root_flags;
48
49         /* big-endian for the wire */
50         tmp = cpu_to_be64(tmp);
51         memcpy(cred->lc_mech_token.value, &tmp, cred->lc_mech_token.length);
52
53         return 0;
54 }
55
56 static void lgss_null_release_cred(struct lgss_cred *cred)
57 {
58         free(cred->lc_mech_token.value);
59 }
60
61 static int lgss_null_validate_cred(struct lgss_cred *cred,
62                                    gss_buffer_desc *token,
63                                    gss_buffer_desc *ctx_token)
64 {
65         if (token->length <= 0)
66                 return -1;
67
68         ctx_token->length = token->length;
69         ctx_token->value = malloc(ctx_token->length);
70         memcpy(ctx_token->value, token->value, ctx_token->length);
71
72         return 0;
73 }
74 struct lgss_mech_type lgss_mech_null = {
75         .lmt_name               = "gssnull",
76         .lmt_mech_n             = LGSS_MECH_NULL,
77         .lmt_prepare_cred       = lgss_null_prepare_cred,
78         .lmt_release_cred       = lgss_null_release_cred,
79         .lmt_validate_cred      = lgss_null_validate_cred,
80 };