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);
54 memcpy(obj->data, buf, len);
60 void rawobj_free(rawobj_t *obj)
66 OBD_FREE(obj->data, obj->len);
73 int rawobj_equal(rawobj_t *a, rawobj_t *b)
77 return (a->len == b->len &&
78 !memcmp(a->data, b->data, a->len));
81 int rawobj_dup(rawobj_t *dest, rawobj_t *src)
87 OBD_ALLOC(dest->data, dest->len);
90 memcpy(dest->data, src->data, dest->len);
96 int rawobj_serialize(rawobj_t *obj, __u32 **buf, __u32 *buflen)
104 len = size_round4(obj->len);
106 if (*buflen < 4 + len) {
107 CERROR("buflen %u < %u\n", *buflen, 4 + len);
111 *(*buf)++ = cpu_to_le32(obj->len);
112 memcpy(*buf, obj->data, obj->len);
114 *buflen -= (4 + len);
119 static int __rawobj_extract(rawobj_t *obj, __u32 **buf, __u32 *buflen,
120 int alloc, int local)
124 if (*buflen < sizeof(__u32)) {
125 CERROR("buflen %u\n", *buflen);
129 obj->len = *(*buf)++;
131 obj->len = le32_to_cpu(obj->len);
132 *buflen -= sizeof(__u32);
139 len = local ? obj->len : size_round4(obj->len);
141 CERROR("buflen %u < %u\n", *buflen, len);
146 obj->data = (__u8 *) *buf;
148 OBD_ALLOC(obj->data, obj->len);
150 CERROR("fail to alloc %u bytes\n", obj->len);
153 memcpy(obj->data, *buf, obj->len);
156 *((char **)buf) += len;
162 int rawobj_extract(rawobj_t *obj, __u32 **buf, __u32 *buflen)
164 return __rawobj_extract(obj, buf, buflen, 0, 0);
167 int rawobj_extract_local(rawobj_t *obj, __u32 **buf, __u32 *buflen)
169 return __rawobj_extract(obj, buf, buflen, 0, 1);