"Fossies" - the Fresh Open Source Software Archive 
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /* mod_ntlm file: $Id: smbencrypt.inc.c,v 1.2 2003/02/21 01:55:14 casz Exp $ */
2
3 /*
4 * Unix SMB/Netbios implementation. Version 1.9. SMB parameters and
5 * setup Copyright (C) Andrew Tridgell 1992-1997 Modified by Jeremy
6 * Allison 1995. This program is free software; you can redistribute
7 * it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details. You should have received
14 * a copy of the GNU General Public License along with this program;
15 * if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
16 * Cambridge, MA 02139, USA. */
17
18 #include <string.h>
19 #include <arpa/inet.h>
20 #include <dirent.h>
21 #include <string.h>
22 #include <sys/vfs.h>
23 #include <netinet/in.h>
24
25 #include "smblib-priv.h"
26 #define uchar unsigned char
27
28 #include "byteorder.h"
29
30 static char *StrnCpy(char *dest, char *src, int n);
31 static void strupper(char *s);
32
33 /*
34 * This implements the X/Open SMB password encryption It takes a password,
35 * a 8 byte "crypt key" and puts 24 bytes of encrypted password into p24 */
36 static void
37 SMBencrypt(uchar * passwd, uchar * c8, uchar * p24)
38 {
39 uchar p14[15], p21[21];
40
41 memset(p21, '\0', 21);
42 memset(p14, '\0', 14);
43 StrnCpy((char *) p14, (char *) passwd, 14);
44
45 strupper((char *) p14);
46 E_P16(p14, p21);
47 E_P24(p21, c8, p24);
48 }
49
50 /****************************************************************************
51 line strncpy but always null terminates. Make sure there is room!
52 ****************************************************************************/
53 static char *
54 StrnCpy(char *dest, char *src, int n)
55 {
56 char *d = dest;
57 if (!dest)
58 return (NULL);
59 if (!src) {
60 *dest = 0;
61 return (dest);
62 }
63 while (n-- && (*d++ = *src++)) ;
64 *d = 0;
65 return (dest);
66 }
67
68 static void
69 strupper(char *s)
70 {
71 while (*s) {
72 if (islower((int) *s))
73 *s = toupper(*s);
74 s++;
75 }
76 }