Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Sep 1998 21:37:51 +0400
From:      "Vladimir B. Grebenschikov" <vova@plugcom.ru>
To:        stefan@asterix.webaffairs.net
Cc:        ports@FreeBSD.ORG
Subject:   FreeBSD Port: apache-php3.0.3-1.3.0
Message-ID:  <35F95FEF.F6A7C7B5@plugcom.ru>

next in thread | raw e-mail | index | archive | help
php function CRYPT() need patch for propertly work with FreeBSD MD5
passwords:


--- php-3.0.3.orig/functions/crypt.c	Fri Sep 11 21:28:00 1998
+++ php-3.0.3.orig/functions/crypt.c	Fri Sep 11 20:55:25 1998
@@ -66,9 +66,30 @@
 	"Crypt", crypt_functions, NULL, NULL, NULL, NULL, NULL,
STANDARD_MODULE_PROPERTIES
 };
 
+#ifdef __FreeBSD__
+static unsigned char itoa64[] =         /* 0 ... 63 => ascii - 64 */
+       
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+
+void
+to64(s, v, n)
+        char *s;
+        long v;
+        int n;
+{
+        while (--n >= 0) {
+                *s++ = itoa64[v&0x3f];
+                v >>= 6;
+        }
+}
+#endif
+
 void php3_crypt(INTERNAL_FUNCTION_PARAMETERS)
 {
+#ifdef __FreeBSD__
+        char salt[10];
+#else
 	char salt[4];
+#endif
 	int arg_count = ARG_COUNT(ht);
 	pval *arg1, *arg2;
 	static char seedchars[] =
@@ -83,14 +104,39 @@
 	salt[0] = '\0';
 	if (arg_count == 2) {
 		convert_to_string(arg2);
+#ifdef __FreeBSD__              
+                strncpy(salt, arg2->value.str.val, 9);
+#else                   
 		strncpy(salt, arg2->value.str.val, 2);
+#endif
 	}
 	if (!salt[0]) {
+#ifdef __FreeBSD__
+# ifdef NEWSALT
+		salt[0] = '_';
+                (void)srandom((int)time((time_t *)NULL));
+                to64(&salt[1], random(), 4);
+                to64(&salt[5], random(), 4);
+# else
+		struct timeval tv;
+		gettimeofday(&tv,0);
+                /* MD5 Salt */
+            	strncpy(&salt[0], "$1$", 3);
+            	to64(&salt[3], random(), 3);
+            	to64(&salt[6], tv.tv_usec, 3);
+            	salt[8] = '\0';
+#endif
+#else   
 		srand(time(0) * getpid());
 		salt[0] = seedchars[rand() % 64];
 		salt[1] = seedchars[rand() % 64];
+#endif
 	}
+#ifdef __FreeBSD__
+	salt[9] = '\0';
+#else
 	salt[2] = '\0';
+#endif
 
 	return_value->value.str.val = (char *) crypt(arg1->value.str.val,
salt);
 	return_value->value.str.len = strlen(return_value->value.str.val);	/*
can be optimized away to 13? */

-- 

Plug Communication ISP, Moscow
Vladimir B. Grebenschikov, vova@plugcom.ru, 2:5020/302@fidonet.org

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?35F95FEF.F6A7C7B5>