2 * crypt.c A thread-safe crypt wrapper
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 * Copyright 2000 The FreeRADIUS server project
34 * No pthreads, no mutex.
36 static int lrad_crypt_init = 0;
37 static pthread_mutex_t lrad_crypt_mutex;
40 #include "libradius.h"
43 * performs a crypt password check in an thread-safe way.
45 * returns: 0 -- check succeeded
46 * -1 -- failed to crypt
49 int lrad_crypt_check(const char *key, const char *crypted)
56 * Ensure we're thread-safe, as crypt() isn't.
58 if (lrad_crypt_init == 0) {
59 pthread_mutex_init(&lrad_crypt_mutex, NULL);
63 pthread_mutex_lock(&lrad_crypt_mutex);
66 passwd = crypt(key, crypted);
69 * Got something, check it within the lock. This is
70 * faster than copying it to a local buffer, and the
71 * time spent within the lock is critical.
74 cmp = strcmp(crypted, passwd);
78 pthread_mutex_unlock(&lrad_crypt_mutex);