Commit | Line | Data |
---|---|---|
059ec3d9 PH |
1 | /* |
2 | * Copyright (c) 2000-2002 | |
3 | * Chris Adams <cmadams@iruntheinter.net> | |
4 | * written for HiWAAY Internet Services | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
19 | * USA | |
20 | */ | |
21 | ||
22 | /* | |
23 | * Adapted for Exim by Tamas TEVESZ <ice@extreme.hu> | |
24 | * Further adapted by Philip Hazel to cut out this function for operating | |
25 | * systems that have a built-in version. | |
26 | */ | |
27 | ||
28 | /* The OS has a built-in crypt16(). Some compilers don't like compiling empty | |
29 | modules, so keep them happy with a dummy when skipping the rest. */ | |
30 | ||
31 | #include "config.h" | |
32 | ||
33 | #ifdef HAVE_CRYPT16 | |
34 | static void dummy(int x) { dummy(x-1); } | |
35 | #else | |
36 | ||
37 | /* The OS doesn't have a built-in crypt16(). Compile this one. */ | |
38 | ||
39 | #include <unistd.h> | |
40 | #include <string.h> | |
41 | #include "os.h" | |
42 | ||
43 | #ifdef CRYPT_H | |
44 | #include <crypt.h> | |
45 | #endif | |
46 | ||
47 | char *crypt16(char *key, char *salt) | |
48 | { | |
49 | static char res[25]; | |
50 | static char s2[3]; | |
51 | char *p; | |
52 | ||
53 | /* Clear the string of any previous data */ | |
54 | memset (res, 0, sizeof (res)); | |
55 | ||
56 | /* crypt the first part */ | |
57 | p = crypt (key, salt); | |
58 | strncpy (res, p, 13); | |
59 | ||
60 | if (strlen (key) > 8) | |
61 | { | |
62 | /* crypt the rest | |
63 | * the first two characters of the first block (not counting | |
64 | * the salt) make up the new salt */ | |
65 | strncpy (s2, &(res[2]), 2); | |
66 | p = crypt (&(key[8]), s2); | |
67 | strncpy (&(res[13]), &(p[2]), 11); | |
68 | memset (s2, 0, sizeof (s2)); | |
69 | } | |
70 | ||
71 | return (res); | |
72 | } | |
73 | #endif | |
74 | ||
75 | /* End of crypt16.c */ |