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
28 #include <obd_class.h>
29 #include <obd_support.h>
30 #include <lustre_sec.h>
32 #include "gss_internal.h"
34 int rawobj_alloc(rawobj_t *obj, char *buf, int len)
41 OBD_ALLOC(obj->data, len);
46 memcpy(obj->data, buf, len);
52 void rawobj_free(rawobj_t *obj)
58 OBD_FREE(obj->data, obj->len);
65 int rawobj_equal(rawobj_t *a, rawobj_t *b)
69 return (a->len == b->len &&
70 (!a->len || !memcmp(a->data, b->data, a->len)));
73 int rawobj_dup(rawobj_t *dest, rawobj_t *src)
79 OBD_ALLOC(dest->data, dest->len);
84 memcpy(dest->data, src->data, dest->len);
90 int rawobj_serialize(rawobj_t *obj, __u32 **buf, __u32 *buflen)
98 len = size_round4(obj->len);
100 if (*buflen < 4 + len) {
101 CERROR("buflen %u < %u\n", *buflen, 4 + len);
105 *(*buf)++ = cpu_to_le32(obj->len);
106 memcpy(*buf, obj->data, obj->len);
108 *buflen -= (4 + len);
113 static int __rawobj_extract(rawobj_t *obj, __u32 **buf, __u32 *buflen,
114 int alloc, int local)
118 if (*buflen < sizeof(__u32)) {
119 CERROR("buflen %u\n", *buflen);
123 obj->len = *(*buf)++;
125 obj->len = le32_to_cpu(obj->len);
126 *buflen -= sizeof(__u32);
133 len = local ? obj->len : size_round4(obj->len);
135 CERROR("buflen %u < %u\n", *buflen, len);
141 obj->data = (__u8 *) *buf;
143 OBD_ALLOC(obj->data, obj->len);
145 CERROR("fail to alloc %u bytes\n", obj->len);
149 memcpy(obj->data, *buf, obj->len);
152 *((char **)buf) += len;
158 int rawobj_extract(rawobj_t *obj, __u32 **buf, __u32 *buflen)
160 return __rawobj_extract(obj, buf, buflen, 0, 0);
163 int rawobj_extract_alloc(rawobj_t *obj, __u32 **buf, __u32 *buflen)
165 return __rawobj_extract(obj, buf, buflen, 1, 0);
168 int rawobj_extract_local(rawobj_t *obj, __u32 **buf, __u32 *buflen)
170 return __rawobj_extract(obj, buf, buflen, 0, 1);
173 int rawobj_from_netobj(rawobj_t *rawobj, netobj_t *netobj)
175 rawobj->len = netobj->len;
176 rawobj->data = netobj->data;
180 int rawobj_from_netobj_alloc(rawobj_t *rawobj, netobj_t *netobj)
185 if (netobj->len == 0)
188 OBD_ALLOC(rawobj->data, netobj->len);
189 if (rawobj->data == NULL)
192 rawobj->len = netobj->len;
193 memcpy(rawobj->data, netobj->data, netobj->len);