summaryrefslogtreecommitdiffstats
path: root/source3/winbindd/winbindd_pam.c
diff options
context:
space:
mode:
authorKai Blin <kai@samba.org>2008-11-07 09:13:26 +0100
committerKai Blin <kai@samba.org>2008-11-10 12:50:02 +0100
commit7d8787c915b97f44851d2ca4c854c5f3aca8a3c6 (patch)
tree7a696cb4201569821f52091f851cc6b234b9220c /source3/winbindd/winbindd_pam.c
parentd64caaf593201ca02ab9eac86e98c5adab3faf72 (diff)
downloadsamba-7d8787c915b97f44851d2ca4c854c5f3aca8a3c6.tar.gz
samba-7d8787c915b97f44851d2ca4c854c5f3aca8a3c6.tar.xz
samba-7d8787c915b97f44851d2ca4c854c5f3aca8a3c6.zip
ntlm_auth: Put huge NTLMv2 blobs into extra_data on CRAP auth.
This fixes bug #5865
Diffstat (limited to 'source3/winbindd/winbindd_pam.c')
-rw-r--r--source3/winbindd/winbindd_pam.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/source3/winbindd/winbindd_pam.c b/source3/winbindd/winbindd_pam.c
index 9ff38996618..7de28b08a92 100644
--- a/source3/winbindd/winbindd_pam.c
+++ b/source3/winbindd/winbindd_pam.c
@@ -1854,17 +1854,28 @@ enum winbindd_result winbindd_dual_pam_auth_crap(struct winbindd_domain *domain,
if (state->request.data.auth_crap.lm_resp_len > sizeof(state->request.data.auth_crap.lm_resp)
|| state->request.data.auth_crap.nt_resp_len > sizeof(state->request.data.auth_crap.nt_resp)) {
- DEBUG(0, ("winbindd_pam_auth_crap: invalid password length %u/%u\n",
- state->request.data.auth_crap.lm_resp_len,
- state->request.data.auth_crap.nt_resp_len));
- result = NT_STATUS_INVALID_PARAMETER;
- goto done;
+ if (!state->request.flags & WBFLAG_BIG_NTLMV2_BLOB ||
+ state->request.extra_len != state->request.data.auth_crap.nt_resp_len) {
+ DEBUG(0, ("winbindd_pam_auth_crap: invalid password length %u/%u\n",
+ state->request.data.auth_crap.lm_resp_len,
+ state->request.data.auth_crap.nt_resp_len));
+ result = NT_STATUS_INVALID_PARAMETER;
+ goto done;
+ }
}
lm_resp = data_blob_talloc(state->mem_ctx, state->request.data.auth_crap.lm_resp,
state->request.data.auth_crap.lm_resp_len);
- nt_resp = data_blob_talloc(state->mem_ctx, state->request.data.auth_crap.nt_resp,
- state->request.data.auth_crap.nt_resp_len);
+
+ if (state->request.flags & WBFLAG_BIG_NTLMV2_BLOB) {
+ nt_resp = data_blob_talloc(state->mem_ctx,
+ state->request.extra_data.data,
+ state->request.data.auth_crap.nt_resp_len);
+ } else {
+ nt_resp = data_blob_talloc(state->mem_ctx,
+ state->request.data.auth_crap.nt_resp,
+ state->request.data.auth_crap.nt_resp_len);
+ }
/* what domain should we contact? */
21' href='#n221'>221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
/*
 * Implementation of the extensible bitmap type.
 *
 * Author : Stephen Smalley, <sds@epoch.ncsc.mil>
 */
/*
 * Updated: Hewlett-Packard <paul.moore@hp.com>
 *
 *      Added ebitmap_export() and ebitmap_import()
 *
 * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
 */

#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/errno.h>
#include "ebitmap.h"
#include "policydb.h"

int ebitmap_cmp(struct ebitmap *e1, struct ebitmap *e2)
{
	struct ebitmap_node *n1, *n2;

	if (e1->highbit != e2->highbit)
		return 0;

	n1 = e1->node;
	n2 = e2->node;
	while (n1 && n2 &&
	       (n1->startbit == n2->startbit) &&
	       (n1->map == n2->map)) {
		n1 = n1->next;
		n2 = n2->next;
	}

	if (n1 || n2)
		return 0;

	return 1;
}

int ebitmap_cpy(struct ebitmap *dst, struct ebitmap *src)
{
	struct ebitmap_node *n, *new, *prev;

	ebitmap_init(dst);
	n = src->node;
	prev = NULL;
	while (n) {
		new = kzalloc(sizeof(*new), GFP_ATOMIC);
		if (!new) {
			ebitmap_destroy(dst);
			return -ENOMEM;
		}
		new->startbit = n->startbit;
		new->map = n->map;
		new->next = NULL;
		if (prev)
			prev->next = new;
		else
			dst->node = new;
		prev = new;
		n = n->next;
	}

	dst->highbit = src->highbit;
	return 0;
}

/**
 * ebitmap_export - Export an ebitmap to a unsigned char bitmap string
 * @src: the ebitmap to export
 * @dst: the resulting bitmap string
 * @dst_len: length of dst in bytes
 *
 * Description:
 * Allocate a buffer at least src->highbit bits long and export the extensible
 * bitmap into the buffer.  The bitmap string will be in little endian format,
 * i.e. LSB first.  The value returned in dst_len may not the true size of the
 * buffer as the length of the buffer is rounded up to a multiple of MAPTYPE.
 * The caller must free the buffer when finished. Returns zero on success,
 * negative values on failure.
 *
 */
int ebitmap_export(const struct ebitmap *src,
		   unsigned char **dst,
		   size_t *dst_len)
{
	size_t bitmap_len;
	unsigned char *bitmap;
	struct ebitmap_node *iter_node;
	MAPTYPE node_val;
	size_t bitmap_byte;
	unsigned char bitmask;

	if (src->highbit == 0) {
		*dst = NULL;
		*dst_len = 0;
		return 0;
	}

	bitmap_len = src->highbit / 8;
	if (src->highbit % 7)
		bitmap_len += 1;

	bitmap = kzalloc((bitmap_len & ~(sizeof(MAPTYPE) - 1)) +
			 sizeof(MAPTYPE),
			 GFP_ATOMIC);
	if (bitmap == NULL)
		return -ENOMEM;

	iter_node = src->node;
	do {
		bitmap_byte = iter_node->startbit / 8;
		bitmask = 0x80;
		node_val = iter_node->map;
		do {
			if (bitmask == 0) {
				bitmap_byte++;
				bitmask = 0x80;
			}
			if (node_val & (MAPTYPE)0x01)
				bitmap[bitmap_byte] |= bitmask;
			node_val >>= 1;
			bitmask >>= 1;
		} while (node_val > 0);
		iter_node = iter_node->next;
	} while (iter_node);

	*dst = bitmap;
	*dst_len = bitmap_len;
	return 0;
}

/**
 * ebitmap_import - Import an unsigned char bitmap string into an ebitmap
 * @src: the bitmap string
 * @src_len: the bitmap length in bytes
 * @dst: the empty ebitmap
 *
 * Description:
 * This function takes a little endian bitmap string in src and imports it into
 * the ebitmap pointed to by dst.  Returns zero on success, negative values on
 * failure.
 *
 */
int ebitmap_import(const unsigned char *src,
		   size_t src_len,
		   struct ebitmap *dst)
{
	size_t src_off = 0;
	size_t node_limit;
	struct ebitmap_node *node_new;
	struct ebitmap_node *node_last = NULL;
	u32 i_byte;
	u32 i_bit;
	unsigned char src_byte;

	while (src_off < src_len) {
		if (src_len - src_off >= sizeof(MAPTYPE)) {
			if (*(MAPTYPE *)&src[src_off] == 0) {
				src_off += sizeof(MAPTYPE);
				continue;
			}
			node_limit = sizeof(MAPTYPE);
		} else {
			for (src_byte = 0, i_byte = src_off;
			     i_byte < src_len && src_byte == 0;
			     i_byte++)
				src_byte |= src[i_byte];
			if (src_byte == 0)
				break;
			node_limit = src_len - src_off;
		}

		node_new = kzalloc(sizeof(*node_new), GFP_ATOMIC);
		if (unlikely(node_new == NULL)) {
			ebitmap_destroy(dst);
			return -ENOMEM;
		}
		node_new->startbit = src_off * 8;
		for (i_byte = 0; i_byte < node_limit; i_byte++) {
			src_byte = src[src_off++];
			for (i_bit = i_byte * 8; src_byte != 0; i_bit++) {
				if (src_byte & 0x80)
					node_new->map |= MAPBIT << i_bit;
				src_byte <<= 1;
			}
		}

		if (node_last != NULL)
			node_last->next = node_new;
		else
			dst->node = node_new;
		node_last = node_new;
	}

	if (likely(node_last != NULL))
		dst->highbit = node_last->startbit + MAPSIZE;
	else
		ebitmap_init(dst);

	return 0;
}

int ebitmap_contains(struct ebitmap *e1, struct ebitmap *e2)
{
	struct ebitmap_node *n1, *n2;

	if (e1->highbit < e2->highbit)
		return 0;

	n1 = e1->node;
	n2 = e2->node;
	while (n1 && n2 && (n1->startbit <= n2->startbit)) {
		if (n1->startbit < n2->startbit) {
			n1 = n1->next;
			continue;
		}
		if ((n1->map & n2->map) != n2->map)
			return 0;

		n1 = n1->next;
		n2 = n2->next;
	}

	if (n2)
		return 0;

	return 1;
}

int ebitmap_get_bit(struct ebitmap *e, unsigned long bit)
{
	struct ebitmap_node *n;

	if (e->highbit < bit)
		return 0;

	n = e->node;
	while (n && (n->startbit <= bit)) {
		if ((n->startbit + MAPSIZE) > bit) {
			if (n->map & (MAPBIT << (bit - n->startbit)))
				return 1;
			else
				return 0;
		}
		n = n->next;
	}

	return 0;
}

int ebitmap_set_bit(struct ebitmap *e, unsigned long bit, int value)
{
	struct ebitmap_node *n, *prev, *new;

	prev = NULL;
	n = e->node;
	while (n && n->startbit <= bit) {
		if ((n->startbit + MAPSIZE) > bit) {
			if (value) {
				n->map |= (MAPBIT << (bit - n->startbit));
			} else {
				n->map &= ~(MAPBIT << (bit - n->startbit));
				if (!n->map) {
					/* drop this node from the bitmap */

					if (!n->next) {
						/*
						 * this was the highest map
						 * within the bitmap
						 */
						if (prev)
							e->highbit = prev->startbit + MAPSIZE;
						else
							e->highbit = 0;
					}
					if (prev)
						prev->next = n->next;
					else
						e->node = n->next;

					kfree(n);
				}
			}
			return 0;
		}
		prev = n;
		n = n->next;
	}

	if (!value)
		return 0;

	new = kzalloc(sizeof(*new), GFP_ATOMIC);
	if (!new)
		return -ENOMEM;

	new->startbit = bit & ~(MAPSIZE - 1);
	new->map = (MAPBIT << (bit - new->startbit));

	if (!n)
		/* this node will be the highest map within the bitmap */
		e->highbit = new->startbit + MAPSIZE;

	if (prev) {
		new->next = prev->next;
		prev->next = new;
	} else {
		new->next = e->node;
		e->node = new;
	}

	return 0;
}

void ebitmap_destroy(struct ebitmap *e)
{
	struct ebitmap_node *n, *temp;

	if (!e)
		return;

	n = e->node;
	while (n) {
		temp = n;
		n = n->next;
		kfree(temp);
	}

	e->highbit = 0;
	e->node = NULL;
	return;
}

int ebitmap_read(struct ebitmap *e, void *fp)
{
	int rc;
	struct ebitmap_node *n, *l;
	__le32 buf[3];
	u32 mapsize, count, i;
	__le64 map;

	ebitmap_init(e);

	rc = next_entry(buf, fp, sizeof buf);
	if (rc < 0)
		goto out;

	mapsize = le32_to_cpu(buf[0]);
	e->highbit = le32_to_cpu(buf[1]);
	count = le32_to_cpu(buf[2]);

	if (mapsize != MAPSIZE) {
		printk(KERN_ERR "security: ebitmap: map size %u does not "
		       "match my size %Zd (high bit was %d)\n", mapsize,
		       MAPSIZE, e->highbit);
		goto bad;
	}
	if (!e->highbit) {
		e->node = NULL;
		goto ok;
	}
	if (e->highbit & (MAPSIZE - 1)) {
		printk(KERN_ERR "security: ebitmap: high bit (%d) is not a "
		       "multiple of the map size (%Zd)\n", e->highbit, MAPSIZE);
		goto bad;
	}
	l = NULL;
	for (i = 0; i < count; i++) {
		rc = next_entry(buf, fp, sizeof(u32));
		if (rc < 0) {
			printk(KERN_ERR "security: ebitmap: truncated map\n");
			goto bad;
		}
		n = kzalloc(sizeof(*n), GFP_KERNEL);
		if (!n) {
			printk(KERN_ERR "security: ebitmap: out of memory\n");
			rc = -ENOMEM;
			goto bad;
		}

		n->startbit = le32_to_cpu(buf[0]);

		if (n->startbit & (MAPSIZE - 1)) {
			printk(KERN_ERR "security: ebitmap start bit (%d) is "
			       "not a multiple of the map size (%Zd)\n",
			       n->startbit, MAPSIZE);
			goto bad_free;
		}
		if (n->startbit > (e->highbit - MAPSIZE)) {
			printk(KERN_ERR "security: ebitmap start bit (%d) is "
			       "beyond the end of the bitmap (%Zd)\n",
			       n->startbit, (e->highbit - MAPSIZE));
			goto bad_free;
		}
		rc = next_entry(&map, fp, sizeof(u64));
		if (rc < 0) {
			printk(KERN_ERR "security: ebitmap: truncated map\n");
			goto bad_free;
		}
		n->map = le64_to_cpu(map);

		if (!n->map) {
			printk(KERN_ERR "security: ebitmap: null map in "
			       "ebitmap (startbit %d)\n", n->startbit);
			goto bad_free;
		}
		if (l) {
			if (n->startbit <= l->startbit) {
				printk(KERN_ERR "security: ebitmap: start "
				       "bit %d comes after start bit %d\n",
				       n->startbit, l->startbit);
				goto bad_free;
			}
			l->next = n;
		} else
			e->node = n;

		l = n;
	}

ok:
	rc = 0;
out:
	return rc;
bad_free:
	kfree(n);
bad:
	if (!rc)
		rc = -EINVAL;
	ebitmap_destroy(e);
	goto out;
}