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