2
* Unix SMB/Netbios implementation.
4
* SMB parameters and setup
5
* Copyright (C) Andrew Tridgell 1992-1997
6
* Modified by Jeremy Allison 1995.
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.
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.
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.
23
#include "std-includes.h"
28
#include <netinet/in.h>
29
#include <arpa/inet.h>
31
#include "smblib-priv.h"
34
#define uchar unsigned char
35
extern int DEBUGLEVEL;
37
#include "byteorder.h"
39
char *StrnCpy(char *dest, char *src, int n);
40
void strupper(char *s);
43
* This implements the X/Open SMB password encryption
44
* It takes a password, a 8 byte "crypt key" and puts 24 bytes of
45
* encrypted password into p24 */
47
SMBencrypt(uchar * passwd, uchar * c8, uchar * p24)
49
uchar p14[15], p21[21];
51
memset(p21, '\0', 21);
52
memset(p14, '\0', 14);
53
StrnCpy((char *) p14, (char *) passwd, 14);
55
strupper((char *) p14);
60
/* Routines for Windows NT MD4 Hash functions. */
62
_my_wcslen(int16 * str)
71
* Convert a string into an NT UNICODE string.
72
* Note that regardless of processor type
73
* this must be in intel (little-endian)
78
_my_mbstowcs(int16 * dst, uchar * src, int len)
83
for (i = 0; i < len; i++) {
95
* Creates the MD4 Hash of the users password in NT UNICODE.
99
E_md4hash(uchar * passwd, uchar * p16)
104
/* Password cannot be longer than 128 characters */
105
len = strlen((char *) passwd);
108
/* Password must be converted to NT unicode */
109
_my_mbstowcs(wpwd, passwd, len);
110
wpwd[len] = 0; /* Ensure string is null terminated */
111
/* Calculate length in bytes */
112
len = _my_wcslen(wpwd) * sizeof(int16);
114
mdfour(p16, (unsigned char *) wpwd, len);
117
/* Does the NT MD4 hash then des encryption. */
120
SMBNTencrypt(uchar * passwd, uchar * c8, uchar * p24)
124
memset(p21, '\0', 21);
126
E_md4hash(passwd, p21);
130
/* Does both the NT and LM owfs of a user's password */
133
nt_lm_owf_gen(char *pwd, char *nt_p16, char *p16)
136
StrnCpy(passwd, pwd, sizeof(passwd) - 1);
138
/* Calculate the MD4 hash (NT compatible) of the password */
139
memset(nt_p16, '\0', 16);
140
E_md4hash((uchar *) passwd, (uchar *) nt_p16);
142
/* Mangle the passwords into Lanman format */
146
/* Calculate the SMB (lanman) hash functions of the password */
148
memset(p16, '\0', 16);
149
E_P16((uchar *) passwd, (uchar *) p16);
151
/* clear out local copy of user's password (just being paranoid). */
152
memset(passwd, 0, sizeof(passwd));
155
/****************************************************************************
156
line strncpy but always null terminates. Make sure there is room!
157
****************************************************************************/
159
StrnCpy(char *dest, char *src, int n)
168
while (n-- && (*d++ = *src++));
178
* #if !defined(KANJI_WIN95_COMPATIBILITY)
179
* if(lp_client_code_page() == KANJI_CODEPAGE)
182
* if (is_shift_jis (*s))
184
* if (is_sj_lower (s[0], s[1]))
185
* s[1] = sj_toupper2 (s[1]);
188
* else if (is_kana (*s))
200
* #endif *//* KANJI_WIN95_COMPATIBILITY */
202
if (islower((int)(unsigned char)*s))