1/*
2   check lanman password
3
4   This program is written to cooperate with the Unix SMB/CIFS implementation.
5
6   Copyright (C) Broadcom Corporation              2005
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2 of the License, or
11   (at your option) any later version.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18   You should have received a copy of the GNU General Public License
19   along with this program; if not, write to the Free Software
20   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21*/
22
23#define _XOPEN_SOURCE
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <stddef.h>
28
29#define uchar unsigned char
30
31
32/*
33 */
34
35int
36main(int argc, char **argv)
37{
38	const char * lanman_password;
39	const char * plaintext_password;
40	char old_lanman_password[36];
41	char new_lanman_password[36]; /*need 32 bytes*/
42	int i;
43	int result = 0;
44
45	uchar new_lanman_p16[16];
46	uchar junk[16];
47
48
49	/*
50		Validate input.
51	 */
52	if (argc != 3)
53	{
54		fprintf(stderr, "Usage: %s\t<lanman_password> <plaintext_password>\n", argv[0]);
55		exit( 3 );
56	}
57	lanman_password = argv[1];
58	plaintext_password = argv[2];
59	if (strspn(lanman_password, "0123456789ABCDEFabcdef") != 32)
60	{
61		fprintf(stderr, "ERROR: Lanman password parameter is invalid.\n");
62		exit( 2 );
63	}
64
65
66	/*
67		Convert old lanman password to upper case.
68	 */
69	for (i=0; i<32; i++)
70	{
71		old_lanman_password[i] = toupper(lanman_password[i]);
72	}
73	old_lanman_password[32] = '\0';
74
75
76	/*
77		Find hash for plaintext password and convert to string.
78	 */
79	nt_lm_owf_gen(plaintext_password, junk, new_lanman_p16);
80 	for (i=0; i<16; i++)
81	{
82		sprintf(&new_lanman_password[i*2], "%02X", new_lanman_p16[i]);
83	}
84	new_lanman_password[32] = '\0';
85
86
87	/*
88		Check for equality.
89	 */
90 	if (strcmp(old_lanman_password, new_lanman_password) != 0)
91		result = 1;
92	return result;
93}
94
95
96