[asterisk-commits] dlee: branch dlee/ari-authn r392954 - in /team/dlee/ari-authn: ./ include/ast...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jun 26 09:51:12 CDT 2013


Author: dlee
Date: Wed Jun 26 09:51:10 2013
New Revision: 392954

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392954
Log:
Configure checking for crypt

Modified:
    team/dlee/ari-authn/configure
    team/dlee/ari-authn/configure.ac
    team/dlee/ari-authn/include/asterisk/autoconfig.h.in
    team/dlee/ari-authn/include/asterisk/utils.h
    team/dlee/ari-authn/main/Makefile
    team/dlee/ari-authn/main/utils.c
    team/dlee/ari-authn/makeopts.in
    team/dlee/ari-authn/res/stasis_http/config.c

Modified: team/dlee/ari-authn/configure.ac
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-authn/configure.ac?view=diff&rev=392954&r1=392953&r2=392954
==============================================================================
--- team/dlee/ari-authn/configure.ac (original)
+++ team/dlee/ari-authn/configure.ac Wed Jun 26 09:51:10 2013
@@ -388,6 +388,7 @@
 AST_EXT_LIB_SETUP([COROSYNC], [Corosync], [cpg])
 AST_EXT_LIB_SETUP_OPTIONAL([COROSYNC_CFG_STATE_TRACK], [A callback only in corosync 1.x], [COROSYNC], [cfg])
 AST_EXT_LIB_SETUP([CURSES], [curses], [curses])
+AST_EXT_LIB_SETUP([CRYPT], [password and data encryption], [crypt])
 AST_EXT_LIB_SETUP([CRYPTO], [OpenSSL Cryptography], [crypto])
 AST_EXT_LIB_SETUP_OPTIONAL([OPENSSL_SRTP], [OpenSSL SRTP Extension Support], [CRYPTO], [crypto])
 AST_EXT_LIB_SETUP([DAHDI], [DAHDI], [dahdi])
@@ -2148,6 +2149,26 @@
 	exit 1
 fi
 
+# Find crypt support
+# * -lcrypt on *NIX
+# * in libsystem on OS X
+AST_EXT_LIB_CHECK([LIBCRYPT], [crypt], [crypt], [crypt.h])
+AC_CHECK_FUNCS([crypt], [SYSCRYPT=true], [SYSCRYPT=""])
+
+if test "x$LIBCRYPT" != "x" ; then
+    CRYPT_LIB="$LIBCRYPT_LIB"
+elif test "x$SYSCRYPT" != "x" ; then
+    CRYPT_LIB=""
+fi
+
+AC_SUBST(CRYPT_LIB)
+
+# Check for crypt_r support
+save_LIBS="$LIBS"
+LIBS="$CRYPT_LIB $LIBS"
+AC_CHECK_FUNCS([crypt_r])
+LIBS="$save_LIBS"
+
 AST_EXT_LIB_CHECK([CRYPTO], [crypto], [AES_encrypt], [openssl/aes.h])
 
 if test "$PBX_CRYPTO" = "1";

Modified: team/dlee/ari-authn/include/asterisk/autoconfig.h.in
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-authn/include/asterisk/autoconfig.h.in?view=diff&rev=392954&r1=392953&r2=392954
==============================================================================
--- team/dlee/ari-authn/include/asterisk/autoconfig.h.in (original)
+++ team/dlee/ari-authn/include/asterisk/autoconfig.h.in Wed Jun 26 09:51:10 2013
@@ -149,8 +149,14 @@
 /* Define to 1 if you have the `cosl' function. */
 #undef HAVE_COSL
 
+/* Define to 1 if you have the `crypt' function. */
+#undef HAVE_CRYPT
+
 /* Define to 1 if you have the OpenSSL Cryptography library. */
 #undef HAVE_CRYPTO
+
+/* Define to 1 if you have the `crypt_r' function. */
+#undef HAVE_CRYPT_R
 
 /* Define to 1 if you have a functional curl library. */
 #undef HAVE_CURL

Modified: team/dlee/ari-authn/include/asterisk/utils.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-authn/include/asterisk/utils.h?view=diff&rev=392954&r1=392953&r2=392954
==============================================================================
--- team/dlee/ari-authn/include/asterisk/utils.h (original)
+++ team/dlee/ari-authn/include/asterisk/utils.h Wed Jun 26 09:51:10 2013
@@ -938,4 +938,25 @@
     void _dtor_ ## varname (vartype * v) { dtor(*v); } \
     vartype varname __attribute__((cleanup(_dtor_ ## varname))) = (initval)
 
+/*
+ * \brief Asterisk wrapper around crypt(3) for encrypting passwords.
+ *
+ * This function will generate a random salt and encrypt the given password.
+ *
+ * \param key User's password to crypt.
+ * \return Crypted password.
+ * \return \c NULL on error.
+ */
+char *ast_crypt_encrypt(const char *key);
+
+/*
+ * \brief Asterisk wrapper around crypt(3) for validating passwords.
+ *
+ * \param key User's password to validate.
+ * \param expected Expected result from crypt.
+ * \return True (non-zero) if key matches crypted.
+ * \return False (zero) if key doesn't match.
+ */
+int ast_crypt_validate(const char *key, const char *expected);
+
 #endif /* _ASTERISK_UTILS_H */

Modified: team/dlee/ari-authn/main/Makefile
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-authn/main/Makefile?view=diff&rev=392954&r1=392953&r2=392954
==============================================================================
--- team/dlee/ari-authn/main/Makefile (original)
+++ team/dlee/ari-authn/main/Makefile Wed Jun 26 09:51:10 2013
@@ -37,6 +37,7 @@
 AST_LIBS+=$(ASTSSL_LIBS)
 AST_LIBS+=$(JANSSON_LIB)
 AST_LIBS+=$(UUID_LIB)
+AST_LIBS+=$(CRYPT_LIB)
 
 ifneq ($(findstring $(OSARCH), linux-gnu uclinux linux-uclibc kfreebsd-gnu),)
   ifneq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)

Modified: team/dlee/ari-authn/main/utils.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-authn/main/utils.c?view=diff&rev=392954&r1=392953&r2=392954
==============================================================================
--- team/dlee/ari-authn/main/utils.c (original)
+++ team/dlee/ari-authn/main/utils.c Wed Jun 26 09:51:10 2013
@@ -32,12 +32,11 @@
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include <ctype.h>
+#include <fcntl.h>
 #include <sys/stat.h>
 #include <sys/stat.h>
-
-#include <fcntl.h>
-
 #include <sys/syscall.h>
+#include <unistd.h>
 #if defined(__APPLE__)
 #include <mach/mach.h>
 #elif defined(HAVE_SYS_THR_H)
@@ -2271,6 +2270,40 @@
 	return ret;
 }
 
+char *ast_crypt_encrypt(const char *key)
+{
+	return NULL;
+}
+
+#if defined(HAVE_CRYPT_R)
+
+int ast_crypt_validate(const char *key, const char *expected)
+{
+	struct crypt_data data = {};
+	return strcmp(expected, crypt_r(key, expected, &data)) == 0;
+}
+
+#elif defined(HAVE_CRYPT)
+
+AST_MUTEX_DEFINE_STATIC(crypt_mutex);
+
+int ast_crypt_validate(const char *key, const char *expected)
+{
+	/* crypt is not reentrant. A global mutex is neither ideal nor
+	 * perfect, but good enough if crypt_r support is unavailable */
+	SCOPED_MUTEX(lock, &crypt_mutex);
+	return strcmp(expected, crypt(key, expected)) == 0;
+}
+
+#else /* No crypt support */
+
+int ast_crypt_validate(const char *key, const char *expected)
+{
+	return 0;
+}
+
+#endif  /* No crypt support */
+
 char *ast_utils_which(const char *binary, char *fullpath, size_t fullpath_size)
 {
 	const char *envPATH = getenv("PATH");

Modified: team/dlee/ari-authn/makeopts.in
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-authn/makeopts.in?view=diff&rev=392954&r1=392953&r2=392954
==============================================================================
--- team/dlee/ari-authn/makeopts.in (original)
+++ team/dlee/ari-authn/makeopts.in Wed Jun 26 09:51:10 2013
@@ -281,6 +281,9 @@
 OPENSSL_INCLUDE=@OPENSSL_INCLUDE@
 OPENSSL_LIB=@OPENSSL_LIB@
 
+CRYPT_INCLUDE=@CRYPT_INCLUDE@
+CRYPT_LIB=@CRYPT_LIB@
+
 CRYPTO_INCLUDE=@CRYPTO_INCLUDE@
 CRYPTO_LIB=@CRYPTO_LIB@
 

Modified: team/dlee/ari-authn/res/stasis_http/config.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-authn/res/stasis_http/config.c?view=diff&rev=392954&r1=392953&r2=392954
==============================================================================
--- team/dlee/ari-authn/res/stasis_http/config.c (original)
+++ team/dlee/ari-authn/res/stasis_http/config.c Wed Jun 26 09:51:10 2013
@@ -192,14 +192,6 @@
 	return ao2_global_obj_ref(confs);
 }
 
-AST_MUTEX_DEFINE_STATIC(crypt_mutex);
-
-static int ari_crypt_validate(const char *password, const char *expected)
-{
-	SCOPED_MUTEX(lock, &crypt_mutex);
-	return strcmp(expected, crypt(password, expected)) == 0;
-}
-
 struct ari_conf_user *ari_config_validate_user(const char *username,
 	const char *password)
 {
@@ -229,7 +221,7 @@
 		is_valid = strcmp(password, user->password) == 0;
 		break;
 	case ARI_PASSWORD_FORMAT_CRYPT:
-		is_valid = ari_crypt_validate(password, user->password);
+		is_valid = ast_crypt_validate(password, user->password);
 		break;
 	}
 




More information about the asterisk-commits mailing list