1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2004 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 # define EXPORT_SYMTAB
25 #define DEBUG_SUBSYSTEM S_SEC
27 #include <linux/init.h>
28 #include <linux/module.h>
29 #include <linux/slab.h>
30 #include <linux/crypto.h>
32 #include <liblustre.h>
35 #include <libcfs/kp30.h>
36 #include <linux/obd.h>
37 #include <linux/obd_class.h>
38 #include <linux/obd_support.h>
39 #include <linux/lustre_idl.h>
40 #include <linux/lustre_sec.h>
42 #include "gss_internal.h"
44 int rawobj_alloc(rawobj_t *obj, char *buf, int len)
51 OBD_ALLOC(obj->data, len);
56 memcpy(obj->data, buf, len);
62 void rawobj_free(rawobj_t *obj)
68 OBD_FREE(obj->data, obj->len);
75 int rawobj_equal(rawobj_t *a, rawobj_t *b)
79 return (a->len == b->len &&
80 (!a->len || !memcmp(a->data, b->data, a->len)));
83 int rawobj_dup(rawobj_t *dest, rawobj_t *src)
89 OBD_ALLOC(dest->data, dest->len);
94 memcpy(dest->data, src->data, dest->len);
100 int rawobj_serialize(rawobj_t *obj, __u32 **buf, __u32 *buflen)
108 len = size_round4(obj->len);
110 if (*buflen < 4 + len) {
111 CERROR("buflen %u < %u\n", *buflen, 4 + len);
115 *(*buf)++ = cpu_to_le32(obj->len);
116 memcpy(*buf, obj->data, obj->len);
118 *buflen -= (4 + len);
123 static int __rawobj_extract(rawobj_t *obj, __u32 **buf, __u32 *buflen,
124 int alloc, int local)
128 if (*buflen < sizeof(__u32)) {
129 CERROR("buflen %u\n", *buflen);
133 obj->len = *(*buf)++;
135 obj->len = le32_to_cpu(obj->len);
136 *buflen -= sizeof(__u32);
143 len = local ? obj->len : size_round4(obj->len);
145 CERROR("buflen %u < %u\n", *buflen, len);
150 obj->data = (__u8 *) *buf;
152 OBD_ALLOC(obj->data, obj->len);
154 CERROR("fail to alloc %u bytes\n", obj->len);
157 memcpy(obj->data, *buf, obj->len);
160 *((char **)buf) += len;
166 int rawobj_extract(rawobj_t *obj, __u32 **buf, __u32 *buflen)
168 return __rawobj_extract(obj, buf, buflen, 0, 0);
171 int rawobj_extract_alloc(rawobj_t *obj, __u32 **buf, __u32 *buflen)
173 return __rawobj_extract(obj, buf, buflen, 1, 0);
176 int rawobj_extract_local(rawobj_t *obj, __u32 **buf, __u32 *buflen)
178 return __rawobj_extract(obj, buf, buflen, 0, 1);