Get rid of warnings about undefined crypt() and assignment in if().
[ircu2.10.12-pk.git] / ircd / ircd_crypt_native.c
1 /*
2  * IRC - Internet Relay Chat, ircd/ircd_xopen.c
3  * Copyright (C) 1990, 1991 Armin Gruner
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 1, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  * $Id$
20  */
21 #define _XOPEN_SOURCE
22 #define _XOPEN_VERSION 4
23
24 #include "config.h"
25 #include "ircd_crypt.h"
26 #include "ircd_crypt_native.h"
27 #include "s_debug.h"
28 #include "ircd_alloc.h"
29
30 #include <assert.h>
31 #include <unistd.h>
32 #ifdef HAVE_CRYPT_H
33 #include <crypt.h>
34 #endif
35
36 /* well this bit is (kinda) intact :) -- hikari */
37 const char* ircd_crypt_native(const char* key, const char* salt)
38 {
39  assert(NULL != key);
40  assert(NULL != salt);
41
42  Debug((DEBUG_DEBUG, "ircd_crypt_native: key is %s", key));
43  Debug((DEBUG_DEBUG, "ircd_crypt_native: salt is %s", salt));
44
45  return (const char*)crypt(key, salt);
46 }
47
48 /* register ourself with the list of crypt mechanisms -- hikari */
49 void ircd_register_crypt_native(void)
50 {
51 crypt_mech_t* crypt_mech;
52
53  if ((crypt_mech = (crypt_mech_t*)MyMalloc(sizeof(crypt_mech_t))) == NULL)
54  {
55   Debug((DEBUG_MALLOC, "Could not allocate space for crypt_native"));
56   return;
57  }
58
59  crypt_mech->mechname = "native";
60  crypt_mech->shortname = "crypt_native";
61  crypt_mech->description = "System native crypt() function mechanism.";
62  crypt_mech->crypt_function = &ircd_crypt_native;
63  crypt_mech->crypt_token = "$CRYPT$";
64  crypt_mech->crypt_token_size = 7;
65
66  ircd_crypt_register_mech(crypt_mech);
67  
68 return;
69 }