Whamcloud - gitweb
LU-8769 lnet: removal of obsolete LNDs
[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 "lgss_utils.h"
31
32 static int lgss_null_prepare_cred(struct lgss_cred *cred)
33 {
34         uint64_t tmp;
35
36         cred->lc_mech_token.value = malloc(sizeof(uint64_t));
37         if (!cred->lc_mech_token.value)
38                 return -1;
39         cred->lc_mech_token.length = sizeof(uint64_t);
40
41         /* random token so it's not cached by the other side */
42         tmp = random();
43         tmp <<= 32;
44
45         /* Sec part flags needed on the other end */
46         tmp |= cred->lc_root_flags;
47
48         /* big-endian for the wire */
49         tmp = htobe64(tmp);
50         memcpy(cred->lc_mech_token.value, &tmp, cred->lc_mech_token.length);
51
52         return 0;
53 }
54
55 static void lgss_null_release_cred(struct lgss_cred *cred)
56 {
57         free(cred->lc_mech_token.value);
58 }
59
60 static int lgss_null_validate_cred(struct lgss_cred *cred,
61                                    gss_buffer_desc *token,
62                                    gss_buffer_desc *ctx_token)
63 {
64         if (token->length <= 0)
65                 return -1;
66
67         ctx_token->length = token->length;
68         ctx_token->value = malloc(ctx_token->length);
69         memcpy(ctx_token->value, token->value, ctx_token->length);
70
71         return 0;
72 }
73 struct lgss_mech_type lgss_mech_null = {
74         .lmt_name               = "gssnull",
75         .lmt_mech_n             = LGSS_MECH_NULL,
76         .lmt_prepare_cred       = lgss_null_prepare_cred,
77         .lmt_release_cred       = lgss_null_release_cred,
78         .lmt_validate_cred      = lgss_null_validate_cred,
79 };