add php 5.2 slot ebuild
Hanno Böck

Hanno Böck commited on 2010-07-30 00:16:43
Zeige 19 geänderte Dateien mit 3162 Einfügungen und 0 Löschungen.

... ...
@@ -0,0 +1,21 @@
1
+AUX 20php5-envd 145 RMD160 8c81fb7dc1d1ddf16fd956d748514db3bcb27603 SHA1 f1cef57c0def8e2c5422aaf136f40b4ff47801d2 SHA256 efaae9e6ae5f7010e073c2ab6d8a9dda009f0707c7d7b0c027e142c94f7041a4
2
+AUX 70_mod_php5.conf-apache2 348 RMD160 9f3f49a52ebf92c2650501c5ceb6f95ce4bb2e76 SHA1 62992e793446b4a9a64900d1ecba7bae06873382 SHA256 5bb8a45570582b4389a7d3feea0398e1c13ed4ced96e559b9406ed8c965dea8c
3
+AUX 70_mod_php5.conf-apache2-r1 374 RMD160 ca06cdc9d1a3dc4129a60c938ee3a1b542497fbb SHA1 4733066b6324c5870e716485484c44c7c26a9ff1 SHA256 815c1ca23c9afe8479568ceaac4057eb91ea5444fbd863866b29adb4eea2c82b
4
+AUX 70_mod_php5_concurr.conf-apache2 348 RMD160 9f3f49a52ebf92c2650501c5ceb6f95ce4bb2e76 SHA1 62992e793446b4a9a64900d1ecba7bae06873382 SHA256 5bb8a45570582b4389a7d3feea0398e1c13ed4ced96e559b9406ed8c965dea8c
5
+AUX 70_mod_php5_concurr.conf-apache2-r1 376 RMD160 4f7de5c0784b6191450b5c1a7de7ad941620e199 SHA1 c42a23bd7a1d3e8c7e0ac906f50f180116349f76 SHA256 c05f499d9c8927391c586b94716a9f59d63767165552ea527ec7ff63c36eaa40
6
+AUX eblits/common-v1.eblit 376 RMD160 524d38035ef01b215c6dc06699c41550c246de9d SHA1 b85091f9e56b20217e5c2d3e25cef055642cd088 SHA256 d395752919fe05fa64a0e09deaf690e008a04f2c580f42233b5a854a1012045e
7
+AUX eblits/pkg_postinst-v1.eblit 2184 RMD160 ce65ba811eab10862d067c7e2b4bdc8d2b0aee56 SHA1 11c14f2235041cfb08e33cf2550bebef2037e92b SHA256 9e1cd81be4f051f3156de0ce5398a338b2ab6f8e73047c5983beda47f2f762b0
8
+AUX eblits/pkg_setup-v1.eblit 777 RMD160 aa63e7ab1bae34feffbbfaae902f11c6e797ba9d SHA1 f7334a4750b1a1bb2f24021dff884733a88ac347 SHA256 2613f51ee9e3a258dbab38ff2df724f2971a50a5ad8c097cb5a4e3744df5fc8a
9
+AUX eblits/src_compile-v1.eblit 1897 RMD160 45aa94bdf920a567ab9002309f6afbed8ba13abb SHA1 83c7fce59355d4bc7684bcfad975a147426f7911 SHA256 0fe6bfd4734f0dfe0bf420b09a5e19698490a8441c1ee20d7446bcceee480336
10
+AUX eblits/src_configure-v1.eblit 10019 RMD160 32f9cf226742689ed0ddf8c2fe87fa3233f83071 SHA1 2e027b84a318452068dcee0a1d1934d1b4b14e03 SHA256 540e9e770a8039aa4b40f9f915cb839e7f2ed8c05a06b9cf87f41253f0ccb5bc
11
+AUX eblits/src_install-v1.eblit 4415 RMD160 dc02d3abc3aa3dae2208675c4f00b3d616d1262b SHA1 f41b3430e0054866dbfbdbac5ce11127d4963112 SHA256 0dba349226de4559cd62c73572cb5c1d8213d7ce9f7d5338887d71158f2da64e
12
+AUX eblits/src_prepare-v1.eblit 2616 RMD160 ccff64d09cc90ada1ea5d1311457cf9a05f12f8e SHA1 7db40d0ca7ef01e5b61962f261511803f768f1bc SHA256 915b9755a37f7670f6e436fe5072dae8f5e6b437ccdfbff835e26bb2f9d22b1e
13
+AUX eblits/src_test-v1.eblit 1480 RMD160 68ef731042ef236efee923649b318239c0219d52 SHA1 81c047f180e43eb1e6b0309ee8d6751950ce1b97 SHA256 ddc836ca2e7b2abac20450fc6eb8c7d30277c567d23051016b903ece1d07a6b2
14
+AUX php-5.2.12-libpng14.patch 222 RMD160 d63bd712d077d9606a02d6620c7084bca7197c01 SHA1 a25a47386d625a47698094fc4825208c6ec8f2a4 SHA256 af94a9c2a104dcb037aa059dd46b6f534adb939ea44ad4cb9e3a0a7c49b64fab
15
+AUX php-5.3.1-sha512.diff 58046 RMD160 1479068ed76c041427cdd85f18911b76f5d9bf02 SHA1 6745a2ea314554ddf3550e9ebaa192bc2ed04c8a SHA256 f152e27055e26817448f60b88d8d0738cc3def6d6f10c2d7fbbd84e5a096a344
16
+AUX php5-ldvs 22 RMD160 5846dab2745b68a88175dd4e72d0b8cf4756dd46 SHA1 592398c92575adb14ec972847ce2aca28a7b9c2c SHA256 b79d0e52b1b3b4543b31ad45525ae1c2814a27ea8e676772ab10bf6fb12dfe79
17
+DIST php-5.2.13.tar.bz2 9084518 RMD160 9e21d32a7b757d25ed827834b26235ea1eebfcc8 SHA1 7127a21f1b493e3cd43f45cadecdb46b623eb1fb SHA256 2b50a2535e3bb9a98cd4d1633f9452d877276c40b385915261f040d535c7eadb
18
+DIST php-patchset-5.2.13-r0.tar.bz2 10207 RMD160 b367c17742553fcfbf4cb1b76f8dd4aae9f08cf8 SHA1 20b60e3aef34d0b558f0c896c6981957490b2ba9 SHA256 c71dad65178186786393164a0cb4f056b85f0e00579da3dc2dbe5b863ec4262b
19
+DIST suhosin-patch-5.2.13-0.9.7.patch.gz 22989 RMD160 63a022a5bf0fb8c6688f4c0ebcfaa8a437ea6935 SHA1 e2faf8db2d7facbd44cee2f737ce87732835d341 SHA256 787743e5d201ab2ce3fcc3f252eedd7f167470fa1f55af0646d7f03aab89d184
20
+EBUILD php-5.2.13.ebuild 16876 RMD160 47cb3b5a07da0e1b47ff2b48d9570e16348aa05e SHA1 e485585c4c66dcca2b02343849bde752d0f67ac5 SHA256 fc574234a108f208515199f0d83dff92ba3714e41da6b41621eef6b147ac0501
21
+MISC howto-slot 245 RMD160 cb09ab083354e80e907275b97405c5dbea27751d SHA1 2602522299cb7a9b50d081e2f73e970e54ba57ef SHA256 a17dfddea74501c6c92e565a5b9cc9117f86bc740d5976f4dbb1c8d490c0744c
... ...
@@ -0,0 +1,2 @@
1
+MANPATH="/usr/lib/php5/man/"
2
+CONFIG_PROTECT_MASK="/etc/php/cli-php5/ext-active/ /etc/php/cgi-php5/ext-active/ /etc/php/apache2-php5/ext-active/"
... ...
@@ -0,0 +1,14 @@
1
+<IfDefine PHP5>
2
+	# Load the module first
3
+	<IfModule !mod_php5.c>
4
+		LoadModule php5_module    modules/libphp5.so
5
+	</IfModule>
6
+
7
+	# Set it to handle the files
8
+	<IfModule mod_mime.c>
9
+		AddHandler application/x-httpd-php .php .php5 .phtml
10
+		AddHandler application/x-httpd-php-source .phps
11
+	</IfModule>
12
+
13
+	DirectoryIndex index.php index.phtml
14
+</IfDefine>
... ...
@@ -0,0 +1,17 @@
1
+<IfDefine PHP5>
2
+	# Load the module first
3
+	<IfModule !mod_php5.c>
4
+		LoadModule php5_module    modules/libphp5.so
5
+	</IfModule>
6
+
7
+	# Set it to handle the files
8
+	<FilesMatch "\.ph(p5?|tml)$">
9
+		SetHandler application/x-httpd-php
10
+	</FilesMatch>
11
+
12
+	<FilesMatch "\.phps$">
13
+		SetHandler application/x-httpd-php-source
14
+	</FilesMatch>
15
+
16
+	DirectoryIndex index.php index.phtml
17
+</IfDefine>
... ...
@@ -0,0 +1,14 @@
1
+<IfDefine PHP5>
2
+	# Load the module first
3
+	<IfModule !mod_php5.c>
4
+		LoadModule php5_module    modules/libphp5.so
5
+	</IfModule>
6
+
7
+	# Set it to handle the files
8
+	<IfModule mod_mime.c>
9
+		AddHandler application/x-httpd-php .php .php5 .phtml
10
+		AddHandler application/x-httpd-php-source .phps
11
+	</IfModule>
12
+
13
+	DirectoryIndex index.php index.phtml
14
+</IfDefine>
... ...
@@ -0,0 +1,17 @@
1
+<IfDefine PHP5>
2
+	# Load the module first
3
+	<IfModule !mod_php5.c>
4
+		LoadModule php5_module    modules/libphp5.so
5
+	</IfModule>
6
+
7
+	# Set it to handle the files
8
+	<FilesMatch "\.ph(p5?|tml)$">
9
+		SetHandler application/x-httpd-php5
10
+	</FilesMatch>
11
+
12
+	<FilesMatch "\.phps$">
13
+		SetHandler application/x-httpd-php5-source
14
+	</FilesMatch>
15
+
16
+	DirectoryIndex index.php index.phtml
17
+</IfDefine>
... ...
@@ -0,0 +1,9 @@
1
+# Copyright 1999-2010 Gentoo Foundation
2
+# Distributed under the terms of the GNU General Public License v2
3
+# $Header: /var/cvsroot/gentoo-x86/dev-lang/php/files/eblits/common-v1.eblit,v 1.1 2010/05/27 23:05:04 mabi Exp $
4
+
5
+php_set_ini_dir() {
6
+	PHP_INI_DIR="/etc/php/${1}-php${PHP_MV}"
7
+	PHP_EXT_INI_DIR="${PHP_INI_DIR}/ext"
8
+	PHP_EXT_INI_DIR_ACTIVE="${PHP_INI_DIR}/ext-active"
9
+}
... ...
@@ -0,0 +1,72 @@
1
+# Copyright 1999-2010 Gentoo Foundation
2
+# Distributed under the terms of the GNU General Public License v2
3
+# $Header: /var/cvsroot/gentoo-x86/dev-lang/php/files/eblits/pkg_postinst-v1.eblit,v 1.1 2010/05/27 23:05:04 mabi Exp $
4
+
5
+eblit-php-pkg_postinst() {
6
+	# Output some general info to the user
7
+	if use apache2 ; then
8
+		APACHE2_MOD_DEFINE="PHP${PHP_MV}"
9
+		if use concurrentmodphp ; then
10
+			APACHE2_MOD_CONF="70_mod_php${PHP_MV}_concurr"
11
+		else
12
+			APACHE2_MOD_CONF="70_mod_php${PHP_MV}"
13
+		fi
14
+		apache-module_pkg_postinst
15
+	fi
16
+
17
+	# Update Apache2 to use mod_php
18
+	if use apache2 ; then
19
+		"${ROOT}/usr/sbin/php-select" -t apache2 php${PHP_MV} > /dev/null 2>&1
20
+		exitStatus=$?
21
+		if [[ ${exitStatus} == 2 ]] ; then
22
+			php-select apache2 php${PHP_MV}
23
+		elif [[ ${exitStatus} == 4 ]] ; then
24
+			ewarn "To make Apache2 use php-${PHP_MV}, use"
25
+			ewarn "    php-select apache2 php${PHP_MV}"
26
+			ewarn
27
+		fi
28
+	fi
29
+
30
+	# Create the symlinks for php-cli
31
+	if use cli ; then
32
+		"${ROOT}/usr/sbin/php-select" -t php php${PHP_MV} > /dev/null 2>&1
33
+		exitStatus=$?
34
+		if [[ ${exitStatus} == 5 ]] ; then
35
+			php-select php php${PHP_MV}
36
+		elif [[ ${exitStatus} == 4 ]] ; then
37
+			ewarn "To make usr/bin/php point to php-${PHP_MV}, use"
38
+			ewarn "    php-select php php${PHP_MV}"
39
+			ewarn
40
+		fi
41
+	fi
42
+
43
+	# Create the symlinks for php-cgi
44
+	if use cgi ; then
45
+		"${ROOT}/usr/sbin/php-select" -t php-cgi php${PHP_MV} > /dev/null 2>&1
46
+		exitStatus=$?
47
+		if [[ ${exitStatus} == 5 ]] ; then
48
+			php-select php-cgi php${PHP_MV}
49
+		elif [[ ${exitStatus} == 4 ]] ; then
50
+			ewarn "To make usr/bin/php-cgi point to php-${PHP_MV}, use"
51
+			ewarn "    php-select php-cgi php${PHP_MV}"
52
+			ewarn
53
+		fi
54
+	fi
55
+
56
+	# Create the symlinks for php-devel
57
+	"${ROOT}/usr/sbin/php-select" -t php-devel php${PHP_MV} > /dev/null 2>&1
58
+	exitStatus=$?
59
+	if [[ $exitStatus == 5 ]] ; then
60
+		php-select php-devel php${PHP_MV}
61
+	elif [[ $exitStatus == 4 ]] ; then
62
+		ewarn "To make usr/bin/php-config and usr/bin/phpize point to php-${PHP_MV}, use"
63
+		ewarn "    php-select php-devel php${PHP_MV}"
64
+		ewarn
65
+	fi
66
+
67
+	ewarn "You may have to recompile third-party extensions now"
68
+	ewarn "(includes every dev-php5/pecl-* package and probably others in that category)"
69
+	ewarn
70
+}
71
+
72
+
... ...
@@ -0,0 +1,28 @@
1
+# Copyright 1999-2010 Gentoo Foundation
2
+# Distributed under the terms of the GNU General Public License v2
3
+# $Header: /var/cvsroot/gentoo-x86/dev-lang/php/files/eblits/pkg_setup-v1.eblit,v 1.2 2010/07/08 22:39:52 mabi Exp $
4
+
5
+eblit-php-pkg_setup() {
6
+	if use concurrentmodphp || use kolab ; then
7
+		ewarn "concurrentmodphp and kolab are Gentoo-specific experimental"
8
+		ewarn "patches. Before reporting any bugs to bugs.php.net, make sure to"
9
+		ewarn "rebuild PHP with those USE flags disabled"
10
+		ewarn
11
+	fi
12
+
13
+	# Mail support
14
+	php_check_mta
15
+
16
+	# imap support
17
+	# if virtuals/imap-c-client goes to new style virtual, we  can exchange this
18
+	# for proper use-deps
19
+	php_check_imap
20
+
21
+	# Oracle support
22
+	php_check_oracle_8
23
+
24
+	phpconfutils_warn_about_external_deps
25
+	depend.apache_pkg_setup
26
+}
27
+
28
+
... ...
@@ -0,0 +1,90 @@
1
+# Copyright 1999-2010 Gentoo Foundation
2
+# Distributed under the terms of the GNU General Public License v2
3
+# $Header: /var/cvsroot/gentoo-x86/dev-lang/php/files/eblits/src_compile-v1.eblit,v 1.4 2010/07/26 13:42:12 mabi Exp $
4
+
5
+eblit-php-src_compile() {
6
+	SAPI_DIR="${WORKDIR}/sapis"
7
+	local is_first_sapi=1
8
+
9
+	for sapi in ${SAPIS} ; do
10
+		use "${sapi}" || continue
11
+		if [[ ${is_first_sapi} == 1 ]]; then
12
+			is_first_sapi=0
13
+		else
14
+			emake clean
15
+		fi
16
+
17
+		php_sapi_build "${sapi}"
18
+		php_sapi_copy "${sapi}"
19
+	done
20
+}
21
+
22
+php_sapi_build() {
23
+	local sapi="$1"
24
+	php_set_ini_dir "${sapi}"
25
+
26
+	mkdir -p "${SAPI_DIR}/${sapi}"
27
+
28
+	sapi_conf="${my_conf} --with-config-file-path=${PHP_INI_DIR}
29
+		--with-config-file-scan-dir=${PHP_EXT_INI_DIR_ACTIVE}"
30
+
31
+	for one_sapi in $SAPIS ; do
32
+		case "$one_sapi" in
33
+			cli|cgi|embed|fpm)
34
+				if [[ "${one_sapi}" == "${sapi}" ]] ; then
35
+					sapi_conf="${sapi_conf} --enable-${one_sapi}"
36
+				else
37
+					sapi_conf="${sapi_conf} --disable-${one_sapi}"
38
+				fi
39
+				;;
40
+
41
+			apache2)
42
+				if [[ "${one_sapi}" == "${sapi}" ]] ; then
43
+					sapi_conf="${sapi_conf} --with-apxs2=/usr/sbin/apxs"
44
+				else
45
+					sapi_conf="${sapi_conf} --without-apxs2"
46
+				fi
47
+				;;
48
+
49
+		esac
50
+	done
51
+
52
+	econf ${sapi_conf}
53
+	emake || die "emake failed"
54
+}
55
+
56
+php_sapi_copy() {
57
+	local sapi="$1"
58
+	local source=""
59
+
60
+	case "$sapi" in
61
+		cli)
62
+			source="sapi/cli/php"
63
+			;;
64
+		cgi)
65
+			source="sapi/cgi/php-cgi"
66
+			;;
67
+		fpm)
68
+			source="sapi/fpm/php-fpm"
69
+			;;
70
+		embed)
71
+			source="libs/libphp${PHP_MV}.so"
72
+			;;
73
+
74
+		apache2)
75
+			# apache2 is a special case; the necessary files
76
+			# (yes, multiple) are copied by make install, not
77
+			# by the ebuild; that's the reason, why apache2 has
78
+			# to be the last sapi
79
+			emake INSTALL_ROOT="${SAPI_DIR}/${sapi}/" install-sapi
80
+			;;
81
+
82
+		*)
83
+			die "unhandled sapi in php_sapi_copy"
84
+			;;
85
+	esac
86
+
87
+	if [[ "${source}" ]] ; then
88
+		cp "$source" "${SAPI_DIR}/$sapi" || die "Unable to copy ${sapi} SAPI"
89
+	fi
90
+}
... ...
@@ -0,0 +1,246 @@
1
+# Copyright 1999-2010 Gentoo Foundation
2
+# Distributed under the terms of the GNU General Public License v2
3
+# $Header: /var/cvsroot/gentoo-x86/dev-lang/php/files/eblits/src_configure-v1.eblit,v 1.4 2010/07/26 13:42:12 mabi Exp $
4
+
5
+eblit-php-src_configure() {
6
+	PHP_DESTDIR="/usr/$(get_libdir)/php${PHP_MV}"
7
+
8
+	# This is a global variable and should be in caps. It isn't because the
9
+	# phpconfutils eclass relies on exactly this name...
10
+	# for --with-libdir see bug #327025
11
+	my_conf="
12
+		--prefix="${PHP_DESTDIR}"
13
+		--mandir="${PHP_DESTDIR}"/man
14
+		--infodir="${PHP_DESTDIR}"/info
15
+		--libdir="${PHP_DESTDIR}"/lib
16
+		--with-libdir=$(get_libdir)
17
+		--without-pear
18
+		$(use_enable threads maintainer-zts)"
19
+
20
+	phpconfutils_init
21
+
22
+	#                             extension	      USE flag        shared
23
+	phpconfutils_extension_enable  "bcmath"       "bcmath"           1
24
+	phpconfutils_extension_with    "bz2"          "bzip2"            1
25
+	phpconfutils_extension_enable  "calendar"     "calendar"         1
26
+	phpconfutils_extension_disable "ctype"        "ctype"            0
27
+	phpconfutils_extension_with    "curl"         "curl"             1
28
+	phpconfutils_extension_with    "curlwrappers" "curlwrappers"     0
29
+	phpconfutils_extension_disable "dom"          "xml"              0
30
+	phpconfutils_extension_with    "enchant"      "enchant"          1 "/usr"
31
+	phpconfutils_extension_enable  "exif"         "exif"             1
32
+	phpconfutils_extension_disable "fileinfo"     "fileinfo"         1
33
+	phpconfutils_extension_disable "filter"       "filter"           0
34
+	phpconfutils_extension_enable  "ftp"          "ftp"              1
35
+	phpconfutils_extension_with    "gettext"      "nls"              1
36
+	phpconfutils_extension_with    "gmp"          "gmp"              1
37
+	phpconfutils_extension_disable "hash"         "hash"             0
38
+	phpconfutils_extension_without "iconv"        "iconv"            0
39
+	phpconfutils_extension_enable  "intl"         "intl"             1
40
+	phpconfutils_extension_disable "ipv6"         "ipv6"             0
41
+	phpconfutils_extension_disable "json"         "json"             0
42
+	phpconfutils_extension_with    "kerberos"     "kerberos"         0 "/usr"
43
+	phpconfutils_extension_disable "libxml"       "xml"              0
44
+	phpconfutils_extension_enable  "mbstring"     "unicode"          1
45
+	phpconfutils_extension_with    "mcrypt"       "crypt"            1
46
+	phpconfutils_extension_with    "mssql"        "mssql"            1
47
+	phpconfutils_extension_with    "onig"         "unicode"          0 "/usr"
48
+	phpconfutils_extension_with    "openssl"      "ssl"              0
49
+	phpconfutils_extension_with    "openssl-dir"  "ssl"              0 "/usr"
50
+	phpconfutils_extension_enable  "pcntl"        "pcntl"            1
51
+	phpconfutils_extension_disable "phar"         "phar"             1
52
+	phpconfutils_extension_disable "pdo"          "pdo"              0
53
+	phpconfutils_extension_with    "pgsql"        "postgres"         1
54
+	phpconfutils_extension_disable "posix"        "posix"            0
55
+	phpconfutils_extension_with    "pspell"       "spell"            1
56
+	phpconfutils_extension_with    "recode"       "recode"           1
57
+	phpconfutils_extension_disable "simplexml"    "simplexml"        0
58
+	phpconfutils_extension_enable  "shmop"        "sharedmem"        0
59
+	phpconfutils_extension_with    "snmp"         "snmp"             1
60
+	phpconfutils_extension_enable  "soap"         "soap"             1
61
+	phpconfutils_extension_enable  "sockets"      "sockets"          1
62
+	phpconfutils_extension_without "sqlite3"      "sqlite3"          1 "/usr"
63
+	phpconfutils_extension_with    "sybase-ct"    "sybase-ct"        1
64
+	phpconfutils_extension_enable  "sysvmsg"      "sysvipc"          1
65
+	phpconfutils_extension_enable  "sysvsem"      "sysvipc"          1
66
+	phpconfutils_extension_enable  "sysvshm"      "sysvipc"          1
67
+	phpconfutils_extension_with    "tidy"         "tidy"             1
68
+	phpconfutils_extension_disable "tokenizer"    "tokenizer"        0
69
+	phpconfutils_extension_enable  "wddx"         "wddx"             1
70
+	phpconfutils_extension_disable "xml"          "xml"              0
71
+	phpconfutils_extension_disable "xmlreader"    "xmlreader"        0
72
+	phpconfutils_extension_disable "xmlwriter"    "xmlwriter"        0
73
+	phpconfutils_extension_with    "xmlrpc"       "xmlrpc"           1
74
+	phpconfutils_extension_with    "xsl"          "xsl"              1
75
+	phpconfutils_extension_enable  "zip"          "zip"              1
76
+	phpconfutils_extension_with    "zlib"         "zlib"             1
77
+	phpconfutils_extension_enable  "debug"        "debug"            0
78
+
79
+	# DBA support
80
+	if use cdb || use berkdb || use flatfile || use gdbm || use inifile \
81
+		|| use qdbm ; then
82
+		my_conf="${my_conf} --enable-dba${shared}"
83
+	fi
84
+
85
+	# DBA drivers support
86
+	phpconfutils_extension_with   "cdb"        "cdb"      0
87
+	phpconfutils_extension_with   "db4"        "berkdb"   0
88
+	phpconfutils_extension_enable "flatfile"   "flatfile" 0
89
+	phpconfutils_extension_with   "gdbm"       "gdbm"     0
90
+	phpconfutils_extension_enable "inifile"    "inifile"  0
91
+	phpconfutils_extension_with   "qdbm"       "qdbm"     0
92
+
93
+	# Support for the GD graphics library
94
+	if use gd-external ; then
95
+		phpconfutils_extension_with   "freetype-dir" "truetype"    0 "/usr"
96
+		phpconfutils_extension_with   "t1lib"        "truetype"    0 "/usr"
97
+		phpconfutils_extension_enable "gd-jis-conv"  "cjk"         0
98
+		phpconfutils_extension_with   "gd"           "gd-external" 1 "/usr"
99
+	else
100
+		phpconfutils_extension_with   "freetype-dir" "truetype"    0 "/usr"
101
+		phpconfutils_extension_with   "t1lib"        "truetype"    0 "/usr"
102
+		phpconfutils_extension_enable "gd-jis-conv"  "cjk"         0
103
+		phpconfutils_extension_with   "jpeg-dir"     "gd"          0 "/usr"
104
+		phpconfutils_extension_with   "png-dir"      "gd"          0 "/usr"
105
+		phpconfutils_extension_with   "xpm-dir"      "xpm"         0 "/usr"
106
+		# enable gd last, so configure can pick up the previous settings
107
+		phpconfutils_extension_with   "gd"           "gd"          0
108
+	fi
109
+
110
+	# IMAP support
111
+	if use imap ; then
112
+		phpconfutils_extension_with "imap"     "imap" 1
113
+		phpconfutils_extension_with "imap-ssl" "ssl"  0
114
+	fi
115
+
116
+	phpconfutils_extension_with "interbase"	"interbase"	0 "/opt"
117
+	phpconfutils_extension_with	"interbase"	"firebird"	0 "/usr"
118
+
119
+	# LDAP support
120
+	if use ldap ; then
121
+		if use oci8 ; then
122
+			phpconfutils_extension_with "ldap" "ldap" 1 "${ORACLE_HOME}"
123
+		else
124
+			phpconfutils_extension_with "ldap"      "ldap"      1
125
+			phpconfutils_extension_with "ldap-sasl" "ldap-sasl" 0
126
+		fi
127
+	fi
128
+
129
+	# MySQL support
130
+	if use mysql ; then
131
+		if use mysqlnd ; then
132
+			phpconfutils_extension_with "mysql"      "mysql" 1 "mysqlnd"
133
+		else
134
+			phpconfutils_extension_with "mysql"      "mysql" 1 "/usr"
135
+		fi
136
+		phpconfutils_extension_with "mysql-sock" "mysql" 0 "/var/run/mysqld/mysqld.sock"
137
+	fi
138
+
139
+	# MySQLi support
140
+	if use mysqlnd ; then
141
+		phpconfutils_extension_with "mysqli" "mysqli" 1 "mysqlnd"
142
+	else
143
+		phpconfutils_extension_with "mysqli" "mysqli" 1 "/usr/bin/mysql_config"
144
+	fi
145
+
146
+	# ODBC support
147
+	if use odbc ; then
148
+		phpconfutils_extension_with "unixODBC" "odbc"     1 "/usr"
149
+		phpconfutils_extension_with "adabas"   "adabas"   1
150
+		phpconfutils_extension_with "birdstep" "birdstep" 1
151
+		phpconfutils_extension_with "dbmaker"  "dbmaker"  1
152
+		phpconfutils_extension_with "empress"  "empress"  1
153
+		if use empress ; then
154
+			phpconfutils_extension_with "empress-bcs" "empress-bcs" 0
155
+		fi
156
+		phpconfutils_extension_with "esoob"   "esoob" 1
157
+		phpconfutils_extension_with "ibm-db2" "db2"   1
158
+		phpconfutils_extension_with "sapdb"   "sapdb" 1
159
+		phpconfutils_extension_with "solid"   "solid" 1
160
+	fi
161
+
162
+	if use iodbc ; then
163
+		phpconfutils_extension_with "iodbc"   "iodbc" 1 "/usr"
164
+	fi
165
+
166
+	# Oracle support
167
+	phpconfutils_extension_with "oci8" "oci8" 1
168
+	if use oci8-instant-client ; then
169
+		OCI8IC_PKG="$(best_version dev-db/oracle-instantclient-basic | \
170
+			sed -e 's|dev-db/oracle-instantclient-basic-||g' | \
171
+			sed -e 's|-r.*||g')"
172
+
173
+		phpconfutils_extension_with "oci8" "oci8-instant-client" 1 \
174
+			"instantclient,/usr/lib/oracle/${OCI8IC_PKG}/client/lib"
175
+	fi
176
+
177
+	# PDO support
178
+	if use pdo ; then
179
+		phpconfutils_extension_with "pdo-dblib"  "mssql"    1
180
+		if use mysqlnd ; then
181
+			phpconfutils_extension_with "pdo-mysql"  "mysql"    1 "mysqlnd"
182
+		else
183
+			phpconfutils_extension_with "pdo-mysql"  "mysql"    1 "/usr"
184
+		fi
185
+		phpconfutils_extension_with "pdo-pgsql"  "postgres"	1
186
+		phpconfutils_extension_with "pdo-sqlite" "sqlite"   1 "/usr"
187
+		phpconfutils_extension_with "pdo-odbc"   "odbc"     1 "unixODBC,/usr"
188
+		if use oci8 ; then
189
+			phpconfutils_extension_with "pdo-oci" "oci8" 1
190
+		fi
191
+		if use oci8-instant-client ; then
192
+			phpconfutils_extension_with "pdo-oci" "oci8-instant-client" 1 \
193
+				"instantclient,/usr,${OCI8IC_PKG}"
194
+		fi
195
+	fi
196
+
197
+	# readline/libedit support
198
+	phpconfutils_extension_with "readline" "readline" 0
199
+	phpconfutils_extension_with "libedit"  "libedit"  0
200
+
201
+	# Session support
202
+	if use session ; then
203
+		phpconfutils_extension_with "mm" "sharedmem" 0
204
+	else
205
+		phpconfutils_extension_disable "session" "session" 0
206
+	fi
207
+
208
+	# SQLite support
209
+	if use sqlite ; then
210
+		phpconfutils_extension_with   "sqlite"      "sqlite"  0 "/usr"
211
+		phpconfutils_extension_enable "sqlite-utf8" "unicode" 0
212
+	else
213
+		phpconfutils_extension_without "sqlite" "sqlite" 0
214
+	fi
215
+
216
+	if use pic ; then
217
+		my_conf="${my_conf} --with-pic"
218
+	fi
219
+
220
+	if has fpm ${IUSE//+} && use fpm ; then
221
+		my_conf="${my_conf} --with-libevent-dir=/usr/lib"
222
+	fi
223
+
224
+
225
+	# we use the system copy of pcre
226
+	# --with-pcre-regex affects ext/pcre
227
+	# --with-pcre-dir affects ext/filter and ext/zip
228
+	my_conf="${my_conf} --with-pcre-regex=/usr --with-pcre-dir=/usr"
229
+
230
+	# Catch CFLAGS problems
231
+	php_check_cflags
232
+
233
+	# Support user-passed configuration parameters
234
+	my_conf="${my_conf} ${EXTRA_ECONF:-}"
235
+
236
+	# Support the Apache2 extras, they must be set globally for all
237
+	# SAPIs to work correctly, especially for external PHP extensions
238
+	if use apache2 ; then
239
+		# Concurrent PHP Apache2 modules support
240
+		if use concurrentmodphp ; then
241
+			append-ldflags "-Wl,--version-script=${FILESDIR}/php${PHP_MV}-ldvs"
242
+		fi
243
+	fi
244
+}
245
+
246
+
... ...
@@ -0,0 +1,140 @@
1
+# Copyright 1999-2010 Gentoo Foundation
2
+# Distributed under the terms of the GNU General Public License v2
3
+# $Header: /var/cvsroot/gentoo-x86/dev-lang/php/files/eblits/src_install-v1.eblit,v 1.4 2010/07/26 13:42:12 mabi Exp $
4
+
5
+eblit-php-src_install() {
6
+	# Makefile forgets to create this before trying to write to it...
7
+	dodir "${PHP_DESTDIR}/bin"
8
+
9
+	# Install php environment (without any sapis)
10
+	emake INSTALL_ROOT="${D}" \
11
+		install-build install-headers install-programs \
12
+		|| die "emake install failed"
13
+
14
+	local extension_dir="$("${D}/${PHP_DESTDIR}/bin/php-config" --extension-dir)"
15
+
16
+	# And install the modules to it
17
+	if use sharedext ; then
18
+		insinto "${extension_dir}"
19
+		doins "${S}/modules/"*.so
20
+	fi
21
+
22
+	# Generate the USE file for PHP
23
+	phpconfutils_generate_usefile
24
+
25
+	# Create the directory where we'll put version-specific php scripts
26
+	keepdir /usr/share/php${PHP_MV}
27
+
28
+	local sapi="", file=""
29
+	local sapi_list=""
30
+
31
+	for sapi in ${SAPIS}; do
32
+		if use "${sapi}" ; then
33
+			einfo "Installing SAPI: ${sapi}"
34
+			# needed each time, php_install_ini would reset it
35
+			into "${PHP_DESTDIR}"
36
+			file=$(find "${SAPI_DIR}/${sapi}/" -type f | head -n 1)
37
+
38
+			if [[ "${file: -3}" == ".so" ]]; then 
39
+				if [[ "${sapi}" == "apache2" ]]; then
40
+					insinto "${PHP_DESTDIR}/../apache2/modules/"
41
+					newins "${file}" "${file/*\/}"
42
+				else
43
+					dolib.so "${file}" || die "Unable to install ${sapi} sapi"
44
+				fi
45
+			else
46
+				dobin "${file}" || die "Unable to install ${sapi} sapi"
47
+			fi
48
+
49
+			php_install_ini "${sapi}"
50
+
51
+			# construct correct SAPI string for php-config
52
+			# thanks to ferringb for the bash voodoo
53
+			if [[ "${sapi}" == "apache2" ]]; then
54
+			    sapi_list="${sapi_list:+${sapi_list} }apache2handler"
55
+			else
56
+				sapi_list="${sapi_list:+${sapi_list} }${sapi}"
57
+			fi
58
+		fi
59
+	done
60
+
61
+	# Install env.d files
62
+	newenvd "${FILESDIR}/20php${PHP_MV}-envd" \
63
+		"20php${PHP_MV}"
64
+	sed -e "s|/lib/|/$(get_libdir)/|g" -i \
65
+		"${D}/etc/env.d/20php${PHP_MV}"
66
+
67
+	# set php-config variable correctly (bug #278439)
68
+	sed -e "s:^\(php_sapis=\)\".*\"$:\1\"${sapi_list}\":" -i \
69
+		"${D}/usr/$(get_libdir)/php5/bin/php-config"
70
+}
71
+
72
+php_install_ini() {
73
+	local phpsapi="${1}"
74
+
75
+	# work out where we are installing the ini file
76
+	php_set_ini_dir "${phpsapi}"
77
+
78
+	local phpinisrc="${PHP_INI_UPSTREAM}-${phpsapi}"
79
+	cp "${PHP_INI_UPSTREAM}" "${phpinisrc}"
80
+
81
+	# default to expose_php=Off, bug 300695
82
+	sed -e 's|^expose_php .*|expose_php = Off|g' -i "${phpinisrc}"
83
+
84
+	# Set the extension dir
85
+	sed -e "s|^extension_dir .*$|extension_dir = ${extension_dir}|g" -i "${phpinisrc}"
86
+
87
+	# Set the include path to point to where we want to find PEAR packages
88
+	sed -e 's|^;include_path = ".:/php/includes".*|include_path = ".:/usr/share/php'${PHP_MV}':/usr/share/php"|' -i "${phpinisrc}"
89
+
90
+	dodir "${PHP_INI_DIR}"
91
+	insinto "${PHP_INI_DIR}"
92
+	newins "${phpinisrc}" "${PHP_INI_FILE}"
93
+
94
+	dodir "${PHP_EXT_INI_DIR}"
95
+	dodir "${PHP_EXT_INI_DIR_ACTIVE}"
96
+
97
+	# Install any extensions built as shared objects
98
+	if use sharedext ; then
99
+		insinto "${PHP_EXT_INI_DIR}"
100
+		for extension in "${D}/${extension_dir}/"*.so ; do
101
+			extension="${extension##*/}"
102
+			inifilename="${extension/.so/.ini}"
103
+			echo "extension=${extension}" > "${S}/modules/$inifilename"
104
+			doins "${S}/modules/$inifilename"
105
+			dosym "${PHP_EXT_INI_DIR}/${inifilename}" "${PHP_EXT_INI_DIR_ACTIVE}/${inifilename}"
106
+		done
107
+	fi
108
+
109
+	# SAPI-specific handling
110
+	if [[ "${sapi}" == "apache2" ]] ; then
111
+		if use concurrentmodphp ; then
112
+			einfo "Installing Apache2 config file 70_mod_php${PHP_MV}_concurr.conf"
113
+			insinto "${APACHE_MODULES_CONFDIR}"
114
+			newins "${FILESDIR}/70_mod_php${PHP_MV}_concurr.conf-apache2" \
115
+				"70_mod_php${PHP_MV}_concurr.conf"
116
+
117
+			# Put the ld version script in the right place so
118
+			# it's always accessible
119
+			insinto "/var/lib/php-pkg/${CATEGORY}/${PN}-${PVR}/"
120
+			doins "${FILESDIR}/php${PHP_MV}-ldvs"
121
+		else
122
+			einfo "Installing Apache2 config 70_mod_php${PHP_MV}.conf)"
123
+			insinto ${APACHE_MODULES_CONFDIR}
124
+			newins "${FILESDIR}/70_mod_php${PHP_MV}.conf-apache2" \
125
+				"70_mod_php${PHP_MV}.conf"
126
+		fi
127
+	fi
128
+
129
+	if [[ "${sapi}" == "fpm" ]] ; then
130
+		einfo "Installing FPM CGI config file php-fpm.conf"
131
+		epatch "${FILESDIR}/php-fpm-gentooified.patch"
132
+		insinto ${PHP_INI_DIR}
133
+		doins "${S}/sapi/fpm/php-fpm.conf"
134
+		dodir "/etc/init.d"
135
+		insinto "/etc/init.d"
136
+		newins  "${FILESDIR}/php-fpm.init" "php-fpm"
137
+		fperms 755 "/etc/init.d/php-fpm"
138
+		dosym "${PHP_DESTDIR}/bin/php-fpm" "/usr/bin/php-fpm"
139
+	fi
140
+}
... ...
@@ -0,0 +1,70 @@
1
+# Copyright 1999-2010 Gentoo Foundation
2
+# Distributed under the terms of the GNU General Public License v2
3
+# $Header: /var/cvsroot/gentoo-x86/dev-lang/php/files/eblits/src_prepare-v1.eblit,v 1.3 2010/06/01 16:17:05 mabi Exp $
4
+
5
+eblit-php-src_prepare() {
6
+	# USE=sharedmem (session/mod_mm to be exact) tries to mmap() this path
7
+	# ([empty session.save_path]/session_mm_[sapi][gid].sem)
8
+	# there is no easy way to circumvent that, all php calls during
9
+	# install use -n, so no php.ini file will be used.
10
+	# As such, this is the easiest way to get around
11
+	addpredict /session_mm_cli250.sem
12
+	addpredict /session_mm_cli0.sem
13
+
14
+	# Concurrent PHP Apache2 modules support
15
+	use apache2 && use concurrentmodphp && \
16
+		epatch "${WORKDIR}/${PV}/opt/concurrent_apache_modules.patch"
17
+
18
+	# kolab support (support for imap annotations)
19
+	use kolab && epatch "${WORKDIR}/${PV}/opt/imap-kolab-annotations.patch"
20
+
21
+	# Change PHP branding
22
+	sed -re	"s|^(PHP_EXTRA_VERSION=\").*(\")|\1${PHP_EXTRA_BRANDING}-pl${PR/r/}-gentoo\2|g" \
23
+		-i configure.in || die "Unable to change PHP branding"
24
+
25
+	# Apply generic PHP patches
26
+	EPATCH_SOURCE="${WORKDIR}/${PV}/generic" EPATCH_SUFFIX="patch" \
27
+		EPATCH_FORCE="yes" \
28
+		EPATCH_MULTI_MSG="Applying generic patches and fixes from upstream..." epatch
29
+
30
+	# Patch PHP to show Gentoo as the server platform
31
+	sed -e 's/PHP_UNAME=`uname -a | xargs`/PHP_UNAME=`uname -s -n -r -v | xargs`/g' \
32
+		-i configure.in || die "Failed to fix server platform name"
33
+
34
+	# Prevent PHP from activating the Apache config,
35
+	# as we will do that ourselves
36
+	sed -i \
37
+		-e "s,-i -a -n php${PHP_MV},-i -n php${PHP_MV},g" \
38
+		-e "s,-i -A -n php${PHP_MV},-i -n php${PHP_MV},g" \
39
+		configure sapi/apache2filter/config.m4 sapi/apache2handler/config.m4
40
+
41
+	# Patch PHP to support heimdal instead of mit-krb5
42
+	if has_version "app-crypt/heimdal" ; then
43
+		sed -e 's|gssapi_krb5|gssapi|g' -i acinclude.m4 \
44
+			|| die "Failed to fix heimdal libname"
45
+		sed -e 's|PHP_ADD_LIBRARY(k5crypto, 1, $1)||g' -i acinclude.m4 \
46
+			|| die "Failed to fix heimdal crypt library reference"
47
+	fi
48
+
49
+	# Suhosin support
50
+	if use suhosin ; then
51
+		epatch "${WORKDIR}/${SUHOSIN_PATCH}"
52
+	fi
53
+
54
+	# rebuild the whole autotools stuff as we are heavily patching it
55
+	# (suhosin, fastbuild, ...)
56
+
57
+	# eaclocal doesn't accept --force, so we try to force re-generation
58
+	# this way
59
+	rm aclocal.m4
60
+
61
+	# work around divert() issues with newer autoconf, bug #281697
62
+	if has_version '>=sys-devel/autoconf-2.64' ; then
63
+		sed -i -r \
64
+			-e 's:^((m4_)?divert)[(]([0-9]*)[)]:\1(600\3):' \
65
+			$(grep -l divert $(find . -name '*.m4') configure.in) || die
66
+	fi
67
+	eautoreconf --force -W no-cross
68
+}
69
+
70
+
... ...
@@ -0,0 +1,54 @@
1
+# Copyright 1999-2010 Gentoo Foundation
2
+# Distributed under the terms of the GNU General Public License v2
3
+# $Header: /var/cvsroot/gentoo-x86/dev-lang/php/files/eblits/src_test-v1.eblit,v 1.1 2010/05/27 23:05:04 mabi Exp $
4
+
5
+eblit-php-src_test() {
6
+	vecho ">>> Test phase [test]: ${CATEGORY}/${PF}"
7
+
8
+	if [[ ! -x "${S}/sapi/cli/php" ]] ; then
9
+		ewarn "Test phase requires USE=cli, skipping"
10
+		return
11
+	else
12
+		export TEST_PHP_EXECUTABLE="${S}/sapi/cli/php"
13
+	fi
14
+
15
+	if [[ -x "${S}/sapi/cgi/php-cgi" ]] ; then
16
+		export TEST_PHP_CGI_EXECUTABLE="${S}/sapi/cgi/php-cgi"
17
+	fi
18
+	
19
+	
20
+	REPORT_EXIT_STATUS=1 "${TEST_PHP_EXECUTABLE}" -n  -d "session.save_path=${T}" \
21
+		"${S}/run-tests.php" -n -q -d "session.save_path=${T}"
22
+
23
+	for name in ${EXPECTED_TEST_FAILURES}; do
24
+		mv "${name}.out" "${name}.out.orig" 2>/dev/null
25
+	done
26
+
27
+	local failed="$(find -name '*.out')"
28
+	if [[ ${failed} != "" ]] ; then
29
+		ewarn "The following test cases failed unexpectedly:"
30
+		for name in ${failed}; do
31
+			ewarn "  ${name/.out/}"
32
+		done
33
+	else
34
+		einfo "No unexpected test failures, all fine"
35
+	fi
36
+
37
+	if [[ ${PHP_SHOW_UNEXPECTED_TEST_PASS} == "1" ]] ; then
38
+		local passed=""
39
+		for name in ${EXPECTED_TEST_FAILURES}; do
40
+			[[ -f "${name}.diff" ]] && continue
41
+			passed="${passed} ${name}"
42
+		done
43
+		if [[ ${passed} != "" ]] ; then
44
+			einfo "The following test cases passed unexpectedly:"
45
+			for name in ${passed}; do
46
+				ewarn "  ${passed}"
47
+			done
48
+		else
49
+			einfo "None of the known-to-fail tests passed, all fine"
50
+		fi
51
+	fi
52
+}
53
+
54
+
... ...
@@ -0,0 +1,11 @@
1
+--- ext/gd/libgd/gd_png.c
2
++++ ext/gd/libgd/gd_png.c
3
+@@ -139,7 +139,7 @@
4
+ 		return NULL;
5
+ 	}
6
+ 
7
+-	if (!png_check_sig (sig, 8)) { /* bad signature */
8
++	if (png_sig_cmp (sig, 0, 8)) { /* bad signature */
9
+ 		return NULL;
10
+ 	}
11
+ 
... ...
@@ -0,0 +1,1801 @@
1
+Index: ext/standard/crypt_sha512.c
2
+===================================================================
3
+--- ext/standard/crypt_sha512.c	(Revision 0)
4
++++ ext/standard/crypt_sha512.c	(Revision 291899)
5
+@@ -0,0 +1,831 @@
6
++/* SHA512-based Unix crypt implementation.
7
++   Released into the Public Domain by Ulrich Drepper <drepper@redhat.com>.  */
8
++/* Windows VC++ port by Pierre Joye <pierre@php.net> */
9
++
10
++#ifndef PHP_WIN32
11
++# include <endian.h>
12
++# include "php.h"
13
++# include "php_main.h"
14
++#endif
15
++
16
++#include <errno.h>
17
++#include <limits.h>
18
++#ifdef PHP_WIN32
19
++# include "win32/php_stdint.h"
20
++# include "win32/php_stdbool.h"
21
++# define __alignof__ __alignof
22
++# define alloca _alloca
23
++#else
24
++# if HAVE_INTTYPES_H
25
++#  include <inttypes.h>
26
++# elif HAVE_STDINT_H
27
++#  include <stdint.h>
28
++# endif
29
++# include <stdbool.h>
30
++#endif
31
++
32
++#include <stdio.h>
33
++#include <stdlib.h>
34
++
35
++#ifdef PHP_WIN32
36
++# include <string.h>
37
++#else
38
++# include <sys/param.h>
39
++# include <sys/types.h>
40
++# if HAVE_STRING_H
41
++#  define __USE_GNU 
42
++#  include <string.h>
43
++# else
44
++#  include <strings.h>
45
++# endif
46
++#endif
47
++#if 0
48
++#ifndef stpncpy
49
++char * stpncpy(char *dst, const char *src, size_t len)
50
++{
51
++	size_t n = strlen(src);
52
++	if (n > len) {
53
++		n = len;
54
++	}
55
++	return strncpy(dst, src, len) + n;
56
++}
57
++#endif
58
++
59
++#ifndef mempcpy
60
++void * mempcpy(void * dst, const void * src, size_t len)
61
++{
62
++	return (((char *)memcpy(dst, src, len)) + len);
63
++}
64
++#endif
65
++#endif
66
++
67
++#ifndef MIN
68
++# define MIN(a, b) (((a) < (b)) ? (a) : (b))
69
++#endif
70
++#ifndef MAX
71
++# define MAX(a, b) (((a) > (b)) ? (a) : (b))
72
++#endif
73
++
74
++/* Structure to save state of computation between the single steps.  */
75
++struct sha512_ctx
76
++{
77
++	uint64_t H[8];
78
++
79
++	uint64_t total[2];
80
++	uint64_t buflen;
81
++	char buffer[256];	/* NB: always correctly aligned for uint64_t.  */
82
++};
83
++
84
++
85
++#if PHP_WIN32 || (__BYTE_ORDER == __LITTLE_ENDIAN)
86
++# define SWAP(n) \
87
++  (((n) << 56)					\
88
++   | (((n) & 0xff00) << 40)			\
89
++   | (((n) & 0xff0000) << 24)			\
90
++   | (((n) & 0xff000000) << 8)			\
91
++   | (((n) >> 8) & 0xff000000)			\
92
++   | (((n) >> 24) & 0xff0000)			\
93
++   | (((n) >> 40) & 0xff00)			\
94
++   | ((n) >> 56))
95
++#else
96
++# define SWAP(n) (n)
97
++#endif
98
++
99
++/* This array contains the bytes used to pad the buffer to the next
100
++   64-byte boundary.  (FIPS 180-2:5.1.2)  */
101
++static const unsigned char fillbuf[128] = { 0x80, 0 /* , 0, 0, ...  */ };
102
++
103
++/* Constants for SHA512 from FIPS 180-2:4.2.3.  */
104
++static const uint64_t K[80] = {
105
++	UINT64_C (0x428a2f98d728ae22), UINT64_C (0x7137449123ef65cd),
106
++	UINT64_C (0xb5c0fbcfec4d3b2f), UINT64_C (0xe9b5dba58189dbbc),
107
++	UINT64_C (0x3956c25bf348b538), UINT64_C (0x59f111f1b605d019),
108
++	UINT64_C (0x923f82a4af194f9b), UINT64_C (0xab1c5ed5da6d8118),
109
++	UINT64_C (0xd807aa98a3030242), UINT64_C (0x12835b0145706fbe),
110
++	UINT64_C (0x243185be4ee4b28c), UINT64_C (0x550c7dc3d5ffb4e2),
111
++	UINT64_C (0x72be5d74f27b896f), UINT64_C (0x80deb1fe3b1696b1),
112
++	UINT64_C (0x9bdc06a725c71235), UINT64_C (0xc19bf174cf692694),
113
++	UINT64_C (0xe49b69c19ef14ad2), UINT64_C (0xefbe4786384f25e3),
114
++	UINT64_C (0x0fc19dc68b8cd5b5), UINT64_C (0x240ca1cc77ac9c65),
115
++	UINT64_C (0x2de92c6f592b0275), UINT64_C (0x4a7484aa6ea6e483),
116
++	UINT64_C (0x5cb0a9dcbd41fbd4), UINT64_C (0x76f988da831153b5),
117
++	UINT64_C (0x983e5152ee66dfab), UINT64_C (0xa831c66d2db43210),
118
++	UINT64_C (0xb00327c898fb213f), UINT64_C (0xbf597fc7beef0ee4),
119
++	UINT64_C (0xc6e00bf33da88fc2), UINT64_C (0xd5a79147930aa725),
120
++	UINT64_C (0x06ca6351e003826f), UINT64_C (0x142929670a0e6e70),
121
++	UINT64_C (0x27b70a8546d22ffc), UINT64_C (0x2e1b21385c26c926),
122
++	UINT64_C (0x4d2c6dfc5ac42aed), UINT64_C (0x53380d139d95b3df),
123
++	UINT64_C (0x650a73548baf63de), UINT64_C (0x766a0abb3c77b2a8),
124
++	UINT64_C (0x81c2c92e47edaee6), UINT64_C (0x92722c851482353b),
125
++	UINT64_C (0xa2bfe8a14cf10364), UINT64_C (0xa81a664bbc423001),
126
++	UINT64_C (0xc24b8b70d0f89791), UINT64_C (0xc76c51a30654be30),
127
++	UINT64_C (0xd192e819d6ef5218), UINT64_C (0xd69906245565a910),
128
++	UINT64_C (0xf40e35855771202a), UINT64_C (0x106aa07032bbd1b8),
129
++	UINT64_C (0x19a4c116b8d2d0c8), UINT64_C (0x1e376c085141ab53),
130
++	UINT64_C (0x2748774cdf8eeb99), UINT64_C (0x34b0bcb5e19b48a8),
131
++	UINT64_C (0x391c0cb3c5c95a63), UINT64_C (0x4ed8aa4ae3418acb),
132
++	UINT64_C (0x5b9cca4f7763e373), UINT64_C (0x682e6ff3d6b2b8a3),
133
++	UINT64_C (0x748f82ee5defb2fc), UINT64_C (0x78a5636f43172f60),
134
++	UINT64_C (0x84c87814a1f0ab72), UINT64_C (0x8cc702081a6439ec),
135
++	UINT64_C (0x90befffa23631e28), UINT64_C (0xa4506cebde82bde9),
136
++	UINT64_C (0xbef9a3f7b2c67915), UINT64_C (0xc67178f2e372532b),
137
++	UINT64_C (0xca273eceea26619c), UINT64_C (0xd186b8c721c0c207),
138
++	UINT64_C (0xeada7dd6cde0eb1e), UINT64_C (0xf57d4f7fee6ed178),
139
++	UINT64_C (0x06f067aa72176fba), UINT64_C (0x0a637dc5a2c898a6),
140
++	UINT64_C (0x113f9804bef90dae), UINT64_C (0x1b710b35131c471b),
141
++	UINT64_C (0x28db77f523047d84), UINT64_C (0x32caab7b40c72493),
142
++	UINT64_C (0x3c9ebe0a15c9bebc), UINT64_C (0x431d67c49c100d4c),
143
++	UINT64_C (0x4cc5d4becb3e42b6), UINT64_C (0x597f299cfc657e2a),
144
++	UINT64_C (0x5fcb6fab3ad6faec), UINT64_C (0x6c44198c4a475817)
145
++  };
146
++
147
++
148
++/* Process LEN bytes of BUFFER, accumulating context into CTX.
149
++   It is assumed that LEN % 128 == 0.  */
150
++static void
151
++sha512_process_block(const void *buffer, size_t len, struct sha512_ctx *ctx) {
152
++	const uint64_t *words = buffer;
153
++	size_t nwords = len / sizeof(uint64_t);
154
++	uint64_t a = ctx->H[0];
155
++	uint64_t b = ctx->H[1];
156
++	uint64_t c = ctx->H[2];
157
++	uint64_t d = ctx->H[3];
158
++	uint64_t e = ctx->H[4];
159
++	uint64_t f = ctx->H[5];
160
++	uint64_t g = ctx->H[6];
161
++	uint64_t h = ctx->H[7];
162
++
163
++  /* First increment the byte count.  FIPS 180-2 specifies the possible
164
++	 length of the file up to 2^128 bits.  Here we only compute the
165
++	 number of bytes.  Do a double word increment.  */
166
++	ctx->total[0] += len;
167
++	if (ctx->total[0] < len) {
168
++		++ctx->total[1];
169
++	}
170
++
171
++	/* Process all bytes in the buffer with 128 bytes in each round of
172
++	 the loop.  */
173
++	while (nwords > 0) {
174
++		uint64_t W[80];
175
++		uint64_t a_save = a;
176
++		uint64_t b_save = b;
177
++		uint64_t c_save = c;
178
++		uint64_t d_save = d;
179
++		uint64_t e_save = e;
180
++		uint64_t f_save = f;
181
++		uint64_t g_save = g;
182
++		uint64_t h_save = h;
183
++		unsigned int t;
184
++
185
++/* Operators defined in FIPS 180-2:4.1.2.  */
186
++#define Ch(x, y, z) ((x & y) ^ (~x & z))
187
++#define Maj(x, y, z) ((x & y) ^ (x & z) ^ (y & z))
188
++#define S0(x) (CYCLIC (x, 28) ^ CYCLIC (x, 34) ^ CYCLIC (x, 39))
189
++#define S1(x) (CYCLIC (x, 14) ^ CYCLIC (x, 18) ^ CYCLIC (x, 41))
190
++#define R0(x) (CYCLIC (x, 1) ^ CYCLIC (x, 8) ^ (x >> 7))
191
++#define R1(x) (CYCLIC (x, 19) ^ CYCLIC (x, 61) ^ (x >> 6))
192
++
193
++		/* It is unfortunate that C does not provide an operator for
194
++		   cyclic rotation.  Hope the C compiler is smart enough.  */
195
++#define CYCLIC(w, s) ((w >> s) | (w << (64 - s)))
196
++
197
++		/* Compute the message schedule according to FIPS 180-2:6.3.2 step 2.  */
198
++		for (t = 0; t < 16; ++t) {
199
++			W[t] = SWAP (*words);
200
++			++words;
201
++		}
202
++
203
++		for (t = 16; t < 80; ++t) {
204
++			W[t] = R1 (W[t - 2]) + W[t - 7] + R0 (W[t - 15]) + W[t - 16];
205
++		}
206
++
207
++		/* The actual computation according to FIPS 180-2:6.3.2 step 3.  */
208
++		for (t = 0; t < 80; ++t) {
209
++			uint64_t T1 = h + S1 (e) + Ch (e, f, g) + K[t] + W[t];
210
++			uint64_t T2 = S0 (a) + Maj (a, b, c);
211
++			h = g;
212
++			g = f;
213
++			f = e;
214
++			e = d + T1;
215
++			d = c;
216
++			c = b;
217
++			b = a;
218
++			a = T1 + T2;
219
++		}
220
++
221
++		/* Add the starting values of the context according to FIPS 180-2:6.3.2
222
++		step 4.  */
223
++		a += a_save;
224
++		b += b_save;
225
++		c += c_save;
226
++		d += d_save;
227
++		e += e_save;
228
++		f += f_save;
229
++		g += g_save;
230
++		h += h_save;
231
++
232
++		/* Prepare for the next round.  */
233
++		nwords -= 16;
234
++	}
235
++
236
++	/* Put checksum in context given as argument.  */
237
++	ctx->H[0] = a;
238
++	ctx->H[1] = b;
239
++	ctx->H[2] = c;
240
++	ctx->H[3] = d;
241
++	ctx->H[4] = e;
242
++	ctx->H[5] = f;
243
++	ctx->H[6] = g;
244
++	ctx->H[7] = h;
245
++}
246
++
247
++
248
++/* Initialize structure containing state of computation.
249
++   (FIPS 180-2:5.3.3)  */
250
++static void sha512_init_ctx (struct sha512_ctx *ctx) {
251
++	ctx->H[0] = UINT64_C (0x6a09e667f3bcc908);
252
++	ctx->H[1] = UINT64_C (0xbb67ae8584caa73b);
253
++	ctx->H[2] = UINT64_C (0x3c6ef372fe94f82b);
254
++	ctx->H[3] = UINT64_C (0xa54ff53a5f1d36f1);
255
++	ctx->H[4] = UINT64_C (0x510e527fade682d1);
256
++	ctx->H[5] = UINT64_C (0x9b05688c2b3e6c1f);
257
++	ctx->H[6] = UINT64_C (0x1f83d9abfb41bd6b);
258
++	ctx->H[7] = UINT64_C (0x5be0cd19137e2179);
259
++
260
++	ctx->total[0] = ctx->total[1] = 0;
261
++	ctx->buflen = 0;
262
++}
263
++
264
++
265
++/* Process the remaining bytes in the internal buffer and the usual
266
++	prolog according to the standard and write the result to RESBUF.
267
++
268
++	IMPORTANT: On some systems it is required that RESBUF is correctly
269
++	aligned for a 32 bits value. */
270
++static void * sha512_finish_ctx (struct sha512_ctx *ctx, void *resbuf) {
271
++	/* Take yet unprocessed bytes into account.  */
272
++	uint64_t bytes = ctx->buflen;
273
++	size_t pad;
274
++	unsigned int i;
275
++
276
++	/* Now count remaining bytes.  */
277
++	ctx->total[0] += bytes;
278
++	if (ctx->total[0] < bytes) {
279
++		++ctx->total[1];
280
++	}
281
++
282
++	pad = bytes >= 112 ? 128 + 112 - (size_t)bytes : 112 - (size_t)bytes;
283
++	memcpy(&ctx->buffer[bytes], fillbuf, pad);
284
++
285
++	/* Put the 128-bit file length in *bits* at the end of the buffer.  */
286
++	*(uint64_t *) &ctx->buffer[bytes + pad + 8] = SWAP(ctx->total[0] << 3);
287
++	*(uint64_t *) &ctx->buffer[bytes + pad] = SWAP((ctx->total[1] << 3) |
288
++						(ctx->total[0] >> 61));
289
++
290
++	/* Process last bytes.  */
291
++	sha512_process_block(ctx->buffer, (size_t)(bytes + pad + 16), ctx);
292
++
293
++	/* Put result from CTX in first 64 bytes following RESBUF.  */
294
++	for (i = 0; i < 8; ++i) {
295
++		((uint64_t *) resbuf)[i] = SWAP(ctx->H[i]);
296
++	}
297
++
298
++	return resbuf;
299
++}
300
++
301
++static void
302
++sha512_process_bytes(const void *buffer, size_t len, struct sha512_ctx *ctx) {
303
++	/* When we already have some bits in our internal buffer concatenate
304
++	 both inputs first.  */
305
++	if (ctx->buflen != 0) {
306
++		size_t left_over = (size_t)ctx->buflen;
307
++		size_t add = (size_t)(256 - left_over > len ? len : 256 - left_over);
308
++
309
++		memcpy(&ctx->buffer[left_over], buffer, add);
310
++		ctx->buflen += add;
311
++
312
++		if (ctx->buflen > 128) {
313
++			sha512_process_block(ctx->buffer, ctx->buflen & ~127, ctx);
314
++
315
++			ctx->buflen &= 127;
316
++			/* The regions in the following copy operation cannot overlap.  */
317
++			memcpy(ctx->buffer, &ctx->buffer[(left_over + add) & ~127],
318
++					(size_t)ctx->buflen);
319
++		}
320
++
321
++		buffer = (const char *) buffer + add;
322
++		len -= add;
323
++	}
324
++
325
++	/* Process available complete blocks.  */
326
++	if (len >= 128) {
327
++#if !_STRING_ARCH_unaligned
328
++/* To check alignment gcc has an appropriate operator.  Other
329
++   compilers don't.  */
330
++# if __GNUC__ >= 2
331
++#  define UNALIGNED_P(p) (((uintptr_t) p) % __alignof__ (uint64_t) != 0)
332
++# else
333
++#  define UNALIGNED_P(p) (((uintptr_t) p) % sizeof(uint64_t) != 0)
334
++# endif
335
++		if (UNALIGNED_P(buffer))
336
++			while (len > 128) {
337
++				sha512_process_block(memcpy(ctx->buffer, buffer, 128), 128, ctx);
338
++				buffer = (const char *) buffer + 128;
339
++				len -= 128;
340
++			}
341
++		else
342
++#endif
343
++		{
344
++		  sha512_process_block(buffer, len & ~127, ctx);
345
++		  buffer = (const char *) buffer + (len & ~127);
346
++		  len &= 127;
347
++		}
348
++	}
349
++
350
++  /* Move remaining bytes into internal buffer.  */
351
++	if (len > 0) {
352
++		size_t left_over = (size_t)ctx->buflen;
353
++
354
++		memcpy(&ctx->buffer[left_over], buffer, len);
355
++		left_over += len;
356
++		if (left_over >= 128) {
357
++			sha512_process_block(ctx->buffer, 128, ctx);
358
++			left_over -= 128;
359
++			memcpy(ctx->buffer, &ctx->buffer[128], left_over);
360
++		}
361
++		ctx->buflen = left_over;
362
++	}
363
++}
364
++
365
++
366
++/* Define our magic string to mark salt for SHA512 "encryption"
367
++   replacement.  */
368
++static const char sha512_salt_prefix[] = "$6$";
369
++
370
++/* Prefix for optional rounds specification.  */
371
++static const char sha512_rounds_prefix[] = "rounds=";
372
++
373
++/* Maximum salt string length.  */
374
++#define SALT_LEN_MAX 16
375
++/* Default number of rounds if not explicitly specified.  */
376
++#define ROUNDS_DEFAULT 5000
377
++/* Minimum number of rounds.  */
378
++#define ROUNDS_MIN 1000
379
++/* Maximum number of rounds.  */
380
++#define ROUNDS_MAX 999999999
381
++
382
++/* Table with characters for base64 transformation.  */
383
++static const char b64t[64] =
384
++"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
385
++
386
++
387
++char *
388
++php_sha512_crypt_r(const char *key, const char *salt, char *buffer, int buflen) {
389
++#ifdef PHP_WIN32
390
++	__declspec(align(64)) unsigned char alt_result[64];
391
++	__declspec(align(64)) unsigned char temp_result[64];
392
++#else
393
++	unsigned char alt_result[64]
394
++		__attribute__ ((__aligned__ (__alignof__ (uint64_t))));
395
++	unsigned char temp_result[64]
396
++		__attribute__ ((__aligned__ (__alignof__ (uint64_t))));
397
++#endif
398
++	struct sha512_ctx ctx;
399
++	struct sha512_ctx alt_ctx;
400
++	size_t salt_len;
401
++	size_t key_len;
402
++	size_t cnt;
403
++	char *cp;
404
++	char *copied_key = NULL;
405
++	char *copied_salt = NULL;
406
++	char *p_bytes;
407
++	char *s_bytes;
408
++	/* Default number of rounds.  */
409
++	size_t rounds = ROUNDS_DEFAULT;
410
++	bool rounds_custom = false;
411
++
412
++	/* Find beginning of salt string.  The prefix should normally always
413
++	 be present.  Just in case it is not.  */
414
++	if (strncmp(sha512_salt_prefix, salt, sizeof(sha512_salt_prefix) - 1) == 0) {
415
++		/* Skip salt prefix.  */
416
++		salt += sizeof(sha512_salt_prefix) - 1;
417
++	}
418
++
419
++	if (strncmp(salt, sha512_rounds_prefix, sizeof(sha512_rounds_prefix) - 1) == 0) {
420
++		const char *num = salt + sizeof(sha512_rounds_prefix) - 1;
421
++		char *endp;
422
++		unsigned long int srounds = strtoul(num, &endp, 10);
423
++
424
++		if (*endp == '$') {
425
++			salt = endp + 1;
426
++			rounds = MAX(ROUNDS_MIN, MIN(srounds, ROUNDS_MAX));
427
++			rounds_custom = true;
428
++		}
429
++	}
430
++
431
++	salt_len = MIN(strcspn(salt, "$"), SALT_LEN_MAX);
432
++	key_len = strlen(key);
433
++
434
++	if ((key - (char *) 0) % __alignof__ (uint64_t) != 0) {
435
++		char *tmp = (char *) alloca (key_len + __alignof__ (uint64_t));
436
++		key = copied_key =
437
++		memcpy(tmp + __alignof__(uint64_t) - (tmp - (char *) 0) % __alignof__(uint64_t), key, key_len);
438
++	}
439
++
440
++	if ((salt - (char *) 0) % __alignof__ (uint64_t) != 0) {
441
++		char *tmp = (char *) alloca(salt_len + __alignof__(uint64_t));
442
++
443
++		salt = copied_salt = memcpy(tmp + __alignof__(uint64_t) - (tmp - (char *) 0) % __alignof__(uint64_t), salt, salt_len);
444
++	}
445
++
446
++	/* Prepare for the real work.  */
447
++	sha512_init_ctx(&ctx);
448
++
449
++	/* Add the key string.  */
450
++	sha512_process_bytes(key, key_len, &ctx);
451
++
452
++	/* The last part is the salt string.  This must be at most 16
453
++	 characters and it ends at the first `$' character (for
454
++	 compatibility with existing implementations).  */
455
++	sha512_process_bytes(salt, salt_len, &ctx);
456
++
457
++
458
++	/* Compute alternate SHA512 sum with input KEY, SALT, and KEY.  The
459
++	 final result will be added to the first context.  */
460
++	sha512_init_ctx(&alt_ctx);
461
++
462
++	/* Add key.  */
463
++	sha512_process_bytes(key, key_len, &alt_ctx);
464
++
465
++	/* Add salt.  */
466
++	sha512_process_bytes(salt, salt_len, &alt_ctx);
467
++
468
++	/* Add key again.  */
469
++	sha512_process_bytes(key, key_len, &alt_ctx);
470
++
471
++	/* Now get result of this (64 bytes) and add it to the other
472
++	 context.  */
473
++	sha512_finish_ctx(&alt_ctx, alt_result);
474
++
475
++	/* Add for any character in the key one byte of the alternate sum.  */
476
++	for (cnt = key_len; cnt > 64; cnt -= 64) {
477
++		sha512_process_bytes(alt_result, 64, &ctx);
478
++	}
479
++	sha512_process_bytes(alt_result, cnt, &ctx);
480
++
481
++	/* Take the binary representation of the length of the key and for every
482
++	 1 add the alternate sum, for every 0 the key.  */
483
++	for (cnt = key_len; cnt > 0; cnt >>= 1) {
484
++		if ((cnt & 1) != 0) {
485
++			sha512_process_bytes(alt_result, 64, &ctx);
486
++		} else {
487
++			sha512_process_bytes(key, key_len, &ctx);
488
++		}
489
++	}
490
++
491
++	/* Create intermediate result.  */
492
++	sha512_finish_ctx(&ctx, alt_result);
493
++
494
++	/* Start computation of P byte sequence.  */
495
++	sha512_init_ctx(&alt_ctx);
496
++
497
++	/* For every character in the password add the entire password.  */
498
++	for (cnt = 0; cnt < key_len; ++cnt) {
499
++		sha512_process_bytes(key, key_len, &alt_ctx);
500
++	}
501
++
502
++	/* Finish the digest.  */
503
++	sha512_finish_ctx(&alt_ctx, temp_result);
504
++
505
++	/* Create byte sequence P.  */
506
++	cp = p_bytes = alloca(key_len);
507
++	for (cnt = key_len; cnt >= 64; cnt -= 64) {
508
++		cp = mempcpy((void *) cp, (const void *)temp_result, 64);
509
++	}
510
++
511
++	memcpy(cp, temp_result, cnt);
512
++
513
++	/* Start computation of S byte sequence.  */
514
++	sha512_init_ctx(&alt_ctx);
515
++
516
++	/* For every character in the password add the entire password.  */
517
++	for (cnt = 0; cnt < 16 + alt_result[0]; ++cnt) {
518
++		sha512_process_bytes(salt, salt_len, &alt_ctx);
519
++	}
520
++
521
++	/* Finish the digest.  */
522
++	sha512_finish_ctx(&alt_ctx, temp_result);
523
++
524
++	/* Create byte sequence S.  */
525
++	cp = s_bytes = alloca(salt_len);
526
++	for (cnt = salt_len; cnt >= 64; cnt -= 64) {
527
++		cp = mempcpy(cp, temp_result, 64);
528
++	}
529
++	memcpy(cp, temp_result, cnt);
530
++
531
++	/* Repeatedly run the collected hash value through SHA512 to burn
532
++	 CPU cycles.  */
533
++	for (cnt = 0; cnt < rounds; ++cnt) {
534
++		/* New context.  */
535
++		sha512_init_ctx(&ctx);
536
++
537
++		/* Add key or last result.  */
538
++		if ((cnt & 1) != 0) {
539
++			sha512_process_bytes(p_bytes, key_len, &ctx);
540
++		} else {
541
++			sha512_process_bytes(alt_result, 64, &ctx);
542
++		}
543
++
544
++		/* Add salt for numbers not divisible by 3.  */
545
++		if (cnt % 3 != 0) {
546
++			sha512_process_bytes(s_bytes, salt_len, &ctx);
547
++		}
548
++
549
++		/* Add key for numbers not divisible by 7.  */
550
++		if (cnt % 7 != 0) {
551
++			sha512_process_bytes(p_bytes, key_len, &ctx);
552
++		}
553
++
554
++		/* Add key or last result.  */
555
++		if ((cnt & 1) != 0) {
556
++			sha512_process_bytes(alt_result, 64, &ctx);
557
++		} else {
558
++			sha512_process_bytes(p_bytes, key_len, &ctx);
559
++		}
560
++
561
++		/* Create intermediate result.  */
562
++		sha512_finish_ctx(&ctx, alt_result);
563
++	}
564
++
565
++	/* Now we can construct the result string.  It consists of three
566
++	 parts.  */
567
++	cp = stpncpy(buffer, sha512_salt_prefix, MAX(0, buflen));
568
++	buflen -= sizeof(sha512_salt_prefix) - 1;
569
++
570
++	if (rounds_custom) {
571
++#ifdef PHP_WIN32
572
++	  int n = _snprintf(cp, MAX(0, buflen), "%s%u$", sha512_rounds_prefix, rounds);
573
++#else
574
++	  int n = snprintf(cp, MAX(0, buflen), "%s%zu$", sha512_rounds_prefix, rounds);
575
++#endif
576
++	  cp += n;
577
++	  buflen -= n;
578
++	}
579
++
580
++	cp = stpncpy(cp, salt, MIN((size_t) MAX(0, buflen), salt_len));
581
++	buflen -= (int) MIN((size_t) MAX(0, buflen), salt_len);
582
++
583
++	if (buflen > 0) {
584
++		*cp++ = '$';
585
++		--buflen;
586
++	}
587
++
588
++#define b64_from_24bit(B2, B1, B0, N)                    \
589
++  do {									                 \
590
++	unsigned int w = ((B2) << 16) | ((B1) << 8) | (B0);	 \
591
++	int n = (N);							             \
592
++	while (n-- > 0 && buflen > 0)					     \
593
++	  {									                 \
594
++	*cp++ = b64t[w & 0x3f];						         \
595
++	--buflen;							                 \
596
++	w >>= 6;							                 \
597
++	  }									                 \
598
++  } while (0)
599
++
600
++	b64_from_24bit(alt_result[0], alt_result[21], alt_result[42], 4);
601
++	b64_from_24bit(alt_result[22], alt_result[43], alt_result[1], 4);
602
++	b64_from_24bit(alt_result[44], alt_result[2], alt_result[23], 4);
603
++	b64_from_24bit(alt_result[3], alt_result[24], alt_result[45], 4);
604
++	b64_from_24bit(alt_result[25], alt_result[46], alt_result[4], 4);
605
++	b64_from_24bit(alt_result[47], alt_result[5], alt_result[26], 4);
606
++	b64_from_24bit(alt_result[6], alt_result[27], alt_result[48], 4);
607
++	b64_from_24bit(alt_result[28], alt_result[49], alt_result[7], 4);
608
++	b64_from_24bit(alt_result[50], alt_result[8], alt_result[29], 4);
609
++	b64_from_24bit(alt_result[9], alt_result[30], alt_result[51], 4);
610
++	b64_from_24bit(alt_result[31], alt_result[52], alt_result[10], 4);
611
++	b64_from_24bit(alt_result[53], alt_result[11], alt_result[32], 4);
612
++	b64_from_24bit(alt_result[12], alt_result[33], alt_result[54], 4);
613
++	b64_from_24bit(alt_result[34], alt_result[55], alt_result[13], 4);
614
++	b64_from_24bit(alt_result[56], alt_result[14], alt_result[35], 4);
615
++	b64_from_24bit(alt_result[15], alt_result[36], alt_result[57], 4);
616
++	b64_from_24bit(alt_result[37], alt_result[58], alt_result[16], 4);
617
++	b64_from_24bit(alt_result[59], alt_result[17], alt_result[38], 4);
618
++	b64_from_24bit(alt_result[18], alt_result[39], alt_result[60], 4);
619
++	b64_from_24bit(alt_result[40], alt_result[61], alt_result[19], 4);
620
++	b64_from_24bit(alt_result[62], alt_result[20], alt_result[41], 4);
621
++	b64_from_24bit(0, 0, alt_result[63], 2);
622
++
623
++	if (buflen <= 0) {
624
++		errno = ERANGE;
625
++		buffer = NULL;
626
++	} else {
627
++		*cp = '\0';		/* Terminate the string.  */
628
++	}
629
++
630
++	/* Clear the buffer for the intermediate result so that people
631
++	 attaching to processes or reading core dumps cannot get any
632
++	 information.  We do it in this way to clear correct_words[]
633
++	 inside the SHA512 implementation as well.  */
634
++	sha512_init_ctx(&ctx);
635
++	sha512_finish_ctx(&ctx, alt_result);
636
++	memset(temp_result, '\0', sizeof(temp_result));
637
++	memset(p_bytes, '\0', key_len);
638
++	memset(s_bytes, '\0', salt_len);
639
++	memset(&ctx, '\0', sizeof(ctx));
640
++	memset(&alt_ctx, '\0', sizeof(alt_ctx));
641
++	if (copied_key != NULL) {
642
++		memset(copied_key, '\0', key_len);
643
++	}
644
++	if (copied_salt != NULL) {
645
++		memset(copied_salt, '\0', salt_len);
646
++	}
647
++
648
++	return buffer;
649
++}
650
++
651
++
652
++/* This entry point is equivalent to the `crypt' function in Unix
653
++   libcs.  */
654
++char *
655
++php_sha512_crypt(const char *key, const char *salt) {
656
++	/* We don't want to have an arbitrary limit in the size of the
657
++	 password.  We can compute an upper bound for the size of the
658
++	 result in advance and so we can prepare the buffer we pass to
659
++	 `sha512_crypt_r'.  */
660
++	static char *buffer;
661
++	static int buflen;
662
++	int needed = (int)(sizeof(sha512_salt_prefix) - 1
663
++		+ sizeof(sha512_rounds_prefix) + 9 + 1
664
++		+ strlen(salt) + 1 + 86 + 1);
665
++
666
++	if (buflen < needed) {
667
++		char *new_buffer = (char *) realloc(buffer, needed);
668
++		if (new_buffer == NULL) {
669
++			return NULL;
670
++		}
671
++
672
++		buffer = new_buffer;
673
++		buflen = needed;
674
++	}
675
++
676
++	return php_sha512_crypt_r (key, salt, buffer, buflen);
677
++}
678
++
679
++#ifdef TEST
680
++static const struct {
681
++	const char *input;
682
++	const char result[64];
683
++} tests[] =
684
++	{
685
++	/* Test vectors from FIPS 180-2: appendix C.1.  */
686
++	{ "abc",
687
++	  "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41\x31"
688
++	  "\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55\xd3\x9a"
689
++	  "\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3\xfe\xeb\xbd"
690
++	  "\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f\xa5\x4c\xa4\x9f" },
691
++	/* Test vectors from FIPS 180-2: appendix C.2.  */
692
++	{ "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
693
++	  "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
694
++	  "\x8e\x95\x9b\x75\xda\xe3\x13\xda\x8c\xf4\xf7\x28\x14\xfc\x14\x3f"
695
++	  "\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88\x90\x18"
696
++	  "\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4\xb5\x43\x3a"
697
++	  "\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b\x87\x4b\xe9\x09" },
698
++	/* Test vectors from the NESSIE project.  */
699
++	{ "",
700
++	  "\xcf\x83\xe1\x35\x7e\xef\xb8\xbd\xf1\x54\x28\x50\xd6\x6d\x80\x07"
701
++	  "\xd6\x20\xe4\x05\x0b\x57\x15\xdc\x83\xf4\xa9\x21\xd3\x6c\xe9\xce"
702
++	  "\x47\xd0\xd1\x3c\x5d\x85\xf2\xb0\xff\x83\x18\xd2\x87\x7e\xec\x2f"
703
++	  "\x63\xb9\x31\xbd\x47\x41\x7a\x81\xa5\x38\x32\x7a\xf9\x27\xda\x3e" },
704
++	{ "a",
705
++	  "\x1f\x40\xfc\x92\xda\x24\x16\x94\x75\x09\x79\xee\x6c\xf5\x82\xf2"
706
++	  "\xd5\xd7\xd2\x8e\x18\x33\x5d\xe0\x5a\xbc\x54\xd0\x56\x0e\x0f\x53"
707
++	  "\x02\x86\x0c\x65\x2b\xf0\x8d\x56\x02\x52\xaa\x5e\x74\x21\x05\x46"
708
++	  "\xf3\x69\xfb\xbb\xce\x8c\x12\xcf\xc7\x95\x7b\x26\x52\xfe\x9a\x75" },
709
++	{ "message digest",
710
++	  "\x10\x7d\xbf\x38\x9d\x9e\x9f\x71\xa3\xa9\x5f\x6c\x05\x5b\x92\x51"
711
++	  "\xbc\x52\x68\xc2\xbe\x16\xd6\xc1\x34\x92\xea\x45\xb0\x19\x9f\x33"
712
++	  "\x09\xe1\x64\x55\xab\x1e\x96\x11\x8e\x8a\x90\x5d\x55\x97\xb7\x20"
713
++	  "\x38\xdd\xb3\x72\xa8\x98\x26\x04\x6d\xe6\x66\x87\xbb\x42\x0e\x7c" },
714
++	{ "abcdefghijklmnopqrstuvwxyz",
715
++	  "\x4d\xbf\xf8\x6c\xc2\xca\x1b\xae\x1e\x16\x46\x8a\x05\xcb\x98\x81"
716
++	  "\xc9\x7f\x17\x53\xbc\xe3\x61\x90\x34\x89\x8f\xaa\x1a\xab\xe4\x29"
717
++	  "\x95\x5a\x1b\xf8\xec\x48\x3d\x74\x21\xfe\x3c\x16\x46\x61\x3a\x59"
718
++	  "\xed\x54\x41\xfb\x0f\x32\x13\x89\xf7\x7f\x48\xa8\x79\xc7\xb1\xf1" },
719
++	{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
720
++	  "\x20\x4a\x8f\xc6\xdd\xa8\x2f\x0a\x0c\xed\x7b\xeb\x8e\x08\xa4\x16"
721
++	  "\x57\xc1\x6e\xf4\x68\xb2\x28\xa8\x27\x9b\xe3\x31\xa7\x03\xc3\x35"
722
++	  "\x96\xfd\x15\xc1\x3b\x1b\x07\xf9\xaa\x1d\x3b\xea\x57\x78\x9c\xa0"
723
++	  "\x31\xad\x85\xc7\xa7\x1d\xd7\x03\x54\xec\x63\x12\x38\xca\x34\x45" },
724
++	{ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
725
++	  "\x1e\x07\xbe\x23\xc2\x6a\x86\xea\x37\xea\x81\x0c\x8e\xc7\x80\x93"
726
++	  "\x52\x51\x5a\x97\x0e\x92\x53\xc2\x6f\x53\x6c\xfc\x7a\x99\x96\xc4"
727
++	  "\x5c\x83\x70\x58\x3e\x0a\x78\xfa\x4a\x90\x04\x1d\x71\xa4\xce\xab"
728
++	  "\x74\x23\xf1\x9c\x71\xb9\xd5\xa3\xe0\x12\x49\xf0\xbe\xbd\x58\x94" },
729
++	{ "123456789012345678901234567890123456789012345678901234567890"
730
++	  "12345678901234567890",
731
++	  "\x72\xec\x1e\xf1\x12\x4a\x45\xb0\x47\xe8\xb7\xc7\x5a\x93\x21\x95"
732
++	  "\x13\x5b\xb6\x1d\xe2\x4e\xc0\xd1\x91\x40\x42\x24\x6e\x0a\xec\x3a"
733
++	  "\x23\x54\xe0\x93\xd7\x6f\x30\x48\xb4\x56\x76\x43\x46\x90\x0c\xb1"
734
++	  "\x30\xd2\xa4\xfd\x5d\xd1\x6a\xbb\x5e\x30\xbc\xb8\x50\xde\xe8\x43" }
735
++  };
736
++#define ntests (sizeof (tests) / sizeof (tests[0]))
737
++
738
++
739
++static const struct
740
++{
741
++	const char *salt;
742
++	const char *input;
743
++	const char *expected;
744
++} tests2[] = {
745
++	{ "$6$saltstring", "Hello world!",
746
++	"$6$saltstring$svn8UoSVapNtMuq1ukKS4tPQd8iKwSMHWjl/O817G3uBnIFNjnQJu"
747
++	"esI68u4OTLiBFdcbYEdFCoEOfaS35inz1"},
748
++	{ "$6$rounds=10000$saltstringsaltstring", "Hello world!",
749
++	"$6$rounds=10000$saltstringsaltst$OW1/O6BYHV6BcXZu8QVeXbDWra3Oeqh0sb"
750
++	"HbbMCVNSnCM/UrjmM0Dp8vOuZeHBy/YTBmSK6H9qs/y3RnOaw5v." },
751
++	{ "$6$rounds=5000$toolongsaltstring", "This is just a test",
752
++	"$6$rounds=5000$toolongsaltstrin$lQ8jolhgVRVhY4b5pZKaysCLi0QBxGoNeKQ"
753
++	"zQ3glMhwllF7oGDZxUhx1yxdYcz/e1JSbq3y6JMxxl8audkUEm0" },
754
++	{ "$6$rounds=1400$anotherlongsaltstring",
755
++	"a very much longer text to encrypt.  This one even stretches over more"
756
++	"than one line.",
757
++	"$6$rounds=1400$anotherlongsalts$POfYwTEok97VWcjxIiSOjiykti.o/pQs.wP"
758
++	"vMxQ6Fm7I6IoYN3CmLs66x9t0oSwbtEW7o7UmJEiDwGqd8p4ur1" },
759
++	{ "$6$rounds=77777$short",
760
++	"we have a short salt string but not a short password",
761
++	"$6$rounds=77777$short$WuQyW2YR.hBNpjjRhpYD/ifIw05xdfeEyQoMxIXbkvr0g"
762
++	"ge1a1x3yRULJ5CCaUeOxFmtlcGZelFl5CxtgfiAc0" },
763
++	{ "$6$rounds=123456$asaltof16chars..", "a short string",
764
++	"$6$rounds=123456$asaltof16chars..$BtCwjqMJGx5hrJhZywWvt0RLE8uZ4oPwc"
765
++	"elCjmw2kSYu.Ec6ycULevoBK25fs2xXgMNrCzIMVcgEJAstJeonj1" },
766
++	{ "$6$rounds=10$roundstoolow", "the minimum number is still observed",
767
++	"$6$rounds=1000$roundstoolow$kUMsbe306n21p9R.FRkW3IGn.S9NPN0x50YhH1x"
768
++	"hLsPuWGsUSklZt58jaTfF4ZEQpyUNGc0dqbpBYYBaHHrsX." },
769
++};
770
++#define ntests2 (sizeof (tests2) / sizeof (tests2[0]))
771
++
772
++
773
++int main (void) {
774
++	struct sha512_ctx ctx;
775
++	char sum[64];
776
++	int result = 0;
777
++	int cnt;
778
++	int i;
779
++	char buf[1000];
780
++	static const char expected[64] =
781
++		"\xe7\x18\x48\x3d\x0c\xe7\x69\x64\x4e\x2e\x42\xc7\xbc\x15\xb4\x63"
782
++		"\x8e\x1f\x98\xb1\x3b\x20\x44\x28\x56\x32\xa8\x03\xaf\xa9\x73\xeb"
783
++		"\xde\x0f\xf2\x44\x87\x7e\xa6\x0a\x4c\xb0\x43\x2c\xe5\x77\xc3\x1b"
784
++		"\xeb\x00\x9c\x5c\x2c\x49\xaa\x2e\x4e\xad\xb2\x17\xad\x8c\xc0\x9b";
785
++
786
++	for (cnt = 0; cnt < (int) ntests; ++cnt) {
787
++		sha512_init_ctx (&ctx);
788
++		sha512_process_bytes (tests[cnt].input, strlen (tests[cnt].input), &ctx);
789
++		sha512_finish_ctx (&ctx, sum);
790
++		if (memcmp (tests[cnt].result, sum, 64) != 0) {
791
++			printf ("test %d run %d failed\n", cnt, 1);
792
++			result = 1;
793
++		}
794
++
795
++		sha512_init_ctx (&ctx);
796
++		for (i = 0; tests[cnt].input[i] != '\0'; ++i) {
797
++			sha512_process_bytes (&tests[cnt].input[i], 1, &ctx);
798
++		}
799
++		sha512_finish_ctx (&ctx, sum);
800
++		if (memcmp (tests[cnt].result, sum, 64) != 0) {
801
++			printf ("test %d run %d failed\n", cnt, 2);
802
++			result = 1;
803
++		}
804
++	}
805
++
806
++	/* Test vector from FIPS 180-2: appendix C.3.  */
807
++
808
++	memset (buf, 'a', sizeof (buf));
809
++	sha512_init_ctx (&ctx);
810
++	for (i = 0; i < 1000; ++i) {
811
++		sha512_process_bytes (buf, sizeof (buf), &ctx);
812
++	}
813
++
814
++	sha512_finish_ctx (&ctx, sum);
815
++	if (memcmp (expected, sum, 64) != 0) {
816
++		printf ("test %d failed\n", cnt);
817
++		result = 1;
818
++	}
819
++
820
++	for (cnt = 0; cnt < ntests2; ++cnt) {
821
++		char *cp = php_sha512_crypt(tests2[cnt].input, tests2[cnt].salt);
822
++
823
++		if (strcmp (cp, tests2[cnt].expected) != 0) {
824
++			printf ("test %d: expected \"%s\", got \"%s\"\n",
825
++					cnt, tests2[cnt].expected, cp);
826
++			result = 1;
827
++		}
828
++	}
829
++
830
++	if (result == 0) {
831
++		puts ("all tests OK");
832
++	}
833
++
834
++	return result;
835
++}
836
++#endif
837
+Index: ext/standard/crypt_sha256.c
838
+===================================================================
839
+--- ext/standard/crypt_sha256.c	(Revision 0)
840
++++ ext/standard/crypt_sha256.c	(Revision 291899)
841
+@@ -0,0 +1,754 @@
842
++/* SHA256-based Unix crypt implementation.
843
++   Released into the Public Domain by Ulrich Drepper <drepper@redhat.com>.  */
844
++/* Windows VC++ port by Pierre Joye <pierre@php.net> */
845
++
846
++#ifndef PHP_WIN32
847
++# include <endian.h>
848
++# include "php.h"
849
++# include "php_main.h"
850
++#endif
851
++
852
++#include <errno.h>
853
++#include <limits.h>
854
++
855
++#ifdef PHP_WIN32
856
++# include "win32/php_stdint.h"
857
++# include "win32/php_stdbool.h"
858
++# define __alignof__ __alignof
859
++# define alloca _alloca
860
++#else
861
++# if HAVE_INTTYPES_H
862
++#  include <inttypes.h>
863
++# elif HAVE_STDINT_H
864
++#  include <stdint.h>
865
++# endif
866
++# include <stdbool.h>
867
++#endif
868
++
869
++#include <stdio.h>
870
++#include <stdlib.h>
871
++
872
++#ifdef PHP_WIN32
873
++# include <string.h>
874
++#else
875
++# include <sys/param.h>
876
++# include <sys/types.h>
877
++# if HAVE_STRING_H
878
++//#  define __USE_GNU 1
879
++#  include <string.h>
880
++# else
881
++#  include <strings.h>
882
++# endif
883
++#endif
884
++
885
++#ifndef HAVE_STRPNCPY 
886
++char * stpncpy(char *dst, const char *src, size_t len)
887
++{
888
++	size_t n = strlen(src);
889
++	if (n > len) {
890
++		n = len;
891
++	}
892
++	return strncpy(dst, src, len) + n;
893
++}
894
++#endif
895
++
896
++#ifndef HAVE_MEMPCPY 
897
++void * mempcpy(void * dst, const void * src, size_t len)
898
++{
899
++	return (((char *)memcpy(dst, src, len)) + len);
900
++}
901
++#endif
902
++
903
++#ifndef MIN
904
++# define MIN(a, b) (((a) < (b)) ? (a) : (b))
905
++#endif
906
++#ifndef MAX
907
++# define MAX(a, b) (((a) > (b)) ? (a) : (b))
908
++#endif
909
++
910
++/* Structure to save state of computation between the single steps.  */
911
++struct sha256_ctx {
912
++	uint32_t H[8];
913
++
914
++	uint32_t total[2];
915
++	uint32_t buflen;
916
++	char buffer[128]; /* NB: always correctly aligned for uint32_t.  */
917
++};
918
++
919
++#if PHP_WIN32 || (__BYTE_ORDER == __LITTLE_ENDIAN)
920
++# define SWAP(n) \
921
++    (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
922
++#else
923
++# define SWAP(n) (n)
924
++#endif
925
++
926
++/* This array contains the bytes used to pad the buffer to the next
927
++   64-byte boundary.  (FIPS 180-2:5.1.1)  */
928
++static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ...  */ };
929
++
930
++
931
++/* Constants for SHA256 from FIPS 180-2:4.2.2.  */
932
++static const uint32_t K[64] = {
933
++	0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
934
++	0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
935
++	0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
936
++	0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
937
++	0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
938
++	0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
939
++	0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
940
++	0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
941
++	0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
942
++	0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
943
++	0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
944
++	0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
945
++	0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
946
++	0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
947
++	0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
948
++	0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
949
++};
950
++
951
++
952
++/* Process LEN bytes of BUFFER, accumulating context into CTX.
953
++   It is assumed that LEN % 64 == 0.  */
954
++static void sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx) {
955
++	const uint32_t *words = buffer;
956
++	size_t nwords = len / sizeof (uint32_t);
957
++	unsigned int t;
958
++
959
++	uint32_t a = ctx->H[0];
960
++	uint32_t b = ctx->H[1];
961
++	uint32_t c = ctx->H[2];
962
++	uint32_t d = ctx->H[3];
963
++	uint32_t e = ctx->H[4];
964
++	uint32_t f = ctx->H[5];
965
++	uint32_t g = ctx->H[6];
966
++	uint32_t h = ctx->H[7];
967
++
968
++	/* First increment the byte count.  FIPS 180-2 specifies the possible
969
++	 length of the file up to 2^64 bits.  Here we only compute the
970
++	 number of bytes.  Do a double word increment.  */
971
++	ctx->total[0] += len;
972
++	if (ctx->total[0] < len) {
973
++		++ctx->total[1];
974
++	}
975
++
976
++	/* Process all bytes in the buffer with 64 bytes in each round of
977
++	 the loop.  */
978
++	while (nwords > 0) {
979
++		uint32_t W[64];
980
++		uint32_t a_save = a;
981
++		uint32_t b_save = b;
982
++		uint32_t c_save = c;
983
++		uint32_t d_save = d;
984
++		uint32_t e_save = e;
985
++		uint32_t f_save = f;
986
++		uint32_t g_save = g;
987
++		uint32_t h_save = h;
988
++
989
++	/* Operators defined in FIPS 180-2:4.1.2.  */
990
++#define Ch(x, y, z) ((x & y) ^ (~x & z))
991
++#define Maj(x, y, z) ((x & y) ^ (x & z) ^ (y & z))
992
++#define S0(x) (CYCLIC (x, 2) ^ CYCLIC (x, 13) ^ CYCLIC (x, 22))
993
++#define S1(x) (CYCLIC (x, 6) ^ CYCLIC (x, 11) ^ CYCLIC (x, 25))
994
++#define R0(x) (CYCLIC (x, 7) ^ CYCLIC (x, 18) ^ (x >> 3))
995
++#define R1(x) (CYCLIC (x, 17) ^ CYCLIC (x, 19) ^ (x >> 10))
996
++
997
++	/* It is unfortunate that C does not provide an operator for
998
++	cyclic rotation.  Hope the C compiler is smart enough.  */
999
++#define CYCLIC(w, s) ((w >> s) | (w << (32 - s)))
1000
++
1001
++		/* Compute the message schedule according to FIPS 180-2:6.2.2 step 2.  */
1002
++		for (t = 0; t < 16; ++t) {
1003
++			W[t] = SWAP (*words);
1004
++			++words;
1005
++		}
1006
++		for (t = 16; t < 64; ++t)
1007
++			W[t] = R1 (W[t - 2]) + W[t - 7] + R0 (W[t - 15]) + W[t - 16];
1008
++
1009
++		/* The actual computation according to FIPS 180-2:6.2.2 step 3.  */
1010
++		for (t = 0; t < 64; ++t) {
1011
++			uint32_t T1 = h + S1 (e) + Ch (e, f, g) + K[t] + W[t];
1012
++			uint32_t T2 = S0 (a) + Maj (a, b, c);
1013
++			h = g;
1014
++			g = f;
1015
++			f = e;
1016
++			e = d + T1;
1017
++			d = c;
1018
++			c = b;
1019
++			b = a;
1020
++			a = T1 + T2;
1021
++		}
1022
++
1023
++		/* Add the starting values of the context according to FIPS 180-2:6.2.2
1024
++		step 4.  */
1025
++		a += a_save;
1026
++		b += b_save;
1027
++		c += c_save;
1028
++		d += d_save;
1029
++		e += e_save;
1030
++		f += f_save;
1031
++		g += g_save;
1032
++		h += h_save;
1033
++
1034
++		/* Prepare for the next round.  */
1035
++		nwords -= 16;
1036
++	}
1037
++
1038
++	/* Put checksum in context given as argument.  */
1039
++	ctx->H[0] = a;
1040
++	ctx->H[1] = b;
1041
++	ctx->H[2] = c;
1042
++	ctx->H[3] = d;
1043
++	ctx->H[4] = e;
1044
++	ctx->H[5] = f;
1045
++	ctx->H[6] = g;
1046
++	ctx->H[7] = h;
1047
++}
1048
++
1049
++
1050
++/* Initialize structure containing state of computation.
1051
++   (FIPS 180-2:5.3.2)  */
1052
++static void sha256_init_ctx(struct sha256_ctx *ctx) {
1053
++	ctx->H[0] = 0x6a09e667;
1054
++	ctx->H[1] = 0xbb67ae85;
1055
++	ctx->H[2] = 0x3c6ef372;
1056
++	ctx->H[3] = 0xa54ff53a;
1057
++	ctx->H[4] = 0x510e527f;
1058
++	ctx->H[5] = 0x9b05688c;
1059
++	ctx->H[6] = 0x1f83d9ab;
1060
++	ctx->H[7] = 0x5be0cd19;
1061
++
1062
++	ctx->total[0] = ctx->total[1] = 0;
1063
++	ctx->buflen = 0;
1064
++}
1065
++
1066
++
1067
++/* Process the remaining bytes in the internal buffer and the usual
1068
++   prolog according to the standard and write the result to RESBUF.
1069
++
1070
++   IMPORTANT: On some systems it is required that RESBUF is correctly
1071
++   aligned for a 32 bits value.  */
1072
++static void * sha256_finish_ctx(struct sha256_ctx *ctx, void *resbuf) {
1073
++	/* Take yet unprocessed bytes into account.  */
1074
++	uint32_t bytes = ctx->buflen;
1075
++	size_t pad;
1076
++	unsigned int i;
1077
++
1078
++	/* Now count remaining bytes.  */
1079
++	ctx->total[0] += bytes;
1080
++	if (ctx->total[0] < bytes) {
1081
++		++ctx->total[1];
1082
++	}
1083
++
1084
++	pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
1085
++	memcpy(&ctx->buffer[bytes], fillbuf, pad);
1086
++
1087
++	/* Put the 64-bit file length in *bits* at the end of the buffer.  */
1088
++	*(uint32_t *) &ctx->buffer[bytes + pad + 4] = SWAP (ctx->total[0] << 3);
1089
++	*(uint32_t *) &ctx->buffer[bytes + pad] = SWAP ((ctx->total[1] << 3) |
1090
++						  (ctx->total[0] >> 29));
1091
++
1092
++	/* Process last bytes.  */
1093
++	sha256_process_block(ctx->buffer, bytes + pad + 8, ctx);
1094
++
1095
++	/* Put result from CTX in first 32 bytes following RESBUF.  */
1096
++	for (i = 0; i < 8; ++i) {
1097
++		((uint32_t *) resbuf)[i] = SWAP(ctx->H[i]);
1098
++	}
1099
++
1100
++	return resbuf;
1101
++}
1102
++
1103
++
1104
++static void sha256_process_bytes(const void *buffer, size_t len, struct sha256_ctx *ctx) {
1105
++	/* When we already have some bits in our internal buffer concatenate
1106
++	 both inputs first.  */
1107
++	if (ctx->buflen != 0) {
1108
++		size_t left_over = ctx->buflen;
1109
++		size_t add = 128 - left_over > len ? len : 128 - left_over;
1110
++
1111
++		  memcpy(&ctx->buffer[left_over], buffer, add);
1112
++		  ctx->buflen += add;
1113
++
1114
++		if (ctx->buflen > 64) {
1115
++			sha256_process_block(ctx->buffer, ctx->buflen & ~63, ctx);
1116
++			ctx->buflen &= 63;
1117
++			/* The regions in the following copy operation cannot overlap.  */
1118
++			memcpy(ctx->buffer, &ctx->buffer[(left_over + add) & ~63], ctx->buflen);
1119
++		}
1120
++
1121
++		buffer = (const char *) buffer + add;
1122
++		len -= add;
1123
++	}
1124
++
1125
++	/* Process available complete blocks.  */
1126
++	if (len >= 64) {
1127
++/* To check alignment gcc has an appropriate operator.  Other
1128
++compilers don't.  */
1129
++#if __GNUC__ >= 2
1130
++# define UNALIGNED_P(p) (((uintptr_t) p) % __alignof__ (uint32_t) != 0)
1131
++#else
1132
++# define UNALIGNED_P(p) (((uintptr_t) p) % sizeof (uint32_t) != 0)
1133
++#endif
1134
++		if (UNALIGNED_P (buffer))
1135
++			while (len > 64) {
1136
++				sha256_process_block(memcpy(ctx->buffer, buffer, 64), 64, ctx);
1137
++				buffer = (const char *) buffer + 64;
1138
++				len -= 64;
1139
++			} else {
1140
++				sha256_process_block(buffer, len & ~63, ctx);
1141
++				buffer = (const char *) buffer + (len & ~63);
1142
++				len &= 63;
1143
++			}
1144
++	}
1145
++
1146
++	/* Move remaining bytes into internal buffer.  */
1147
++	if (len > 0) {
1148
++		size_t left_over = ctx->buflen;
1149
++
1150
++		memcpy(&ctx->buffer[left_over], buffer, len);
1151
++		left_over += len;
1152
++		if (left_over >= 64) {
1153
++			sha256_process_block(ctx->buffer, 64, ctx);
1154
++			left_over -= 64;
1155
++			memcpy(ctx->buffer, &ctx->buffer[64], left_over);
1156
++		}
1157
++		ctx->buflen = left_over;
1158
++	}
1159
++}
1160
++
1161
++
1162
++/* Define our magic string to mark salt for SHA256 "encryption"
1163
++   replacement.  */
1164
++static const char sha256_salt_prefix[] = "$5$";
1165
++
1166
++/* Prefix for optional rounds specification.  */
1167
++static const char sha256_rounds_prefix[] = "rounds=";
1168
++
1169
++/* Maximum salt string length.  */
1170
++#define SALT_LEN_MAX 16
1171
++/* Default number of rounds if not explicitly specified.  */
1172
++#define ROUNDS_DEFAULT 5000
1173
++/* Minimum number of rounds.  */
1174
++#define ROUNDS_MIN 1000
1175
++/* Maximum number of rounds.  */
1176
++#define ROUNDS_MAX 999999999
1177
++
1178
++/* Table with characters for base64 transformation.  */
1179
++static const char b64t[64] =
1180
++"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
1181
++
1182
++char * php_sha256_crypt_r(const char *key, const char *salt, char *buffer, int buflen)
1183
++{
1184
++#ifdef PHP_WIN32
1185
++	__declspec(align(32)) unsigned char alt_result[32];
1186
++	__declspec(align(32)) unsigned char temp_result[32];
1187
++#else
1188
++	unsigned char alt_result[32]
1189
++	__attribute__ ((__aligned__ (__alignof__ (uint32_t))));
1190
++	unsigned char temp_result[32]
1191
++	__attribute__ ((__aligned__ (__alignof__ (uint32_t))));
1192
++#endif
1193
++
1194
++	struct sha256_ctx ctx;
1195
++	struct sha256_ctx alt_ctx;
1196
++	size_t salt_len;
1197
++	size_t key_len;
1198
++	size_t cnt;
1199
++	char *cp;
1200
++	char *copied_key = NULL;
1201
++	char *copied_salt = NULL;
1202
++	char *p_bytes;
1203
++	char *s_bytes;
1204
++	/* Default number of rounds.  */
1205
++	size_t rounds = ROUNDS_DEFAULT;
1206
++	bool rounds_custom = false;
1207
++
1208
++	/* Find beginning of salt string.  The prefix should normally always
1209
++	be present.  Just in case it is not.  */
1210
++	if (strncmp(sha256_salt_prefix, salt, sizeof(sha256_salt_prefix) - 1) == 0) {
1211
++		/* Skip salt prefix.  */
1212
++		salt += sizeof(sha256_salt_prefix) - 1;
1213
++	}
1214
++
1215
++	if (strncmp(salt, sha256_rounds_prefix, sizeof(sha256_rounds_prefix) - 1) == 0) {
1216
++		const char *num = salt + sizeof(sha256_rounds_prefix) - 1;
1217
++		char *endp;
1218
++		unsigned long int srounds = strtoul(num, &endp, 10);
1219
++		if (*endp == '$') {
1220
++			salt = endp + 1;
1221
++			rounds = MAX(ROUNDS_MIN, MIN(srounds, ROUNDS_MAX));
1222
++			rounds_custom = true;
1223
++		}
1224
++	}
1225
++
1226
++	salt_len = MIN(strcspn(salt, "$"), SALT_LEN_MAX);
1227
++	key_len = strlen(key);
1228
++
1229
++	if ((key - (char *) 0) % __alignof__ (uint32_t) != 0) {
1230
++		char *tmp = (char *) alloca(key_len + __alignof__(uint32_t));
1231
++		key = copied_key = memcpy(tmp + __alignof__(uint32_t) - (tmp - (char *) 0) % __alignof__(uint32_t), key, key_len);
1232
++	}
1233
++
1234
++	if ((salt - (char *) 0) % __alignof__(uint32_t) != 0) {
1235
++		char *tmp = (char *) alloca(salt_len + __alignof__(uint32_t));
1236
++		salt = copied_salt =
1237
++		memcpy(tmp + __alignof__(uint32_t) - (tmp - (char *) 0) % __alignof__ (uint32_t), salt, salt_len);
1238
++	}
1239
++
1240
++	/* Prepare for the real work.  */
1241
++	sha256_init_ctx(&ctx);
1242
++
1243
++	/* Add the key string.  */
1244
++	sha256_process_bytes(key, key_len, &ctx);
1245
++
1246
++	/* The last part is the salt string.  This must be at most 16
1247
++	 characters and it ends at the first `$' character (for
1248
++	 compatibility with existing implementations).  */
1249
++	sha256_process_bytes(salt, salt_len, &ctx);
1250
++
1251
++
1252
++	/* Compute alternate SHA256 sum with input KEY, SALT, and KEY.  The
1253
++	 final result will be added to the first context.  */
1254
++	sha256_init_ctx(&alt_ctx);
1255
++
1256
++	/* Add key.  */
1257
++	sha256_process_bytes(key, key_len, &alt_ctx);
1258
++
1259
++	/* Add salt.  */
1260
++	sha256_process_bytes(salt, salt_len, &alt_ctx);
1261
++
1262
++	/* Add key again.  */
1263
++	sha256_process_bytes(key, key_len, &alt_ctx);
1264
++
1265
++	/* Now get result of this (32 bytes) and add it to the other
1266
++	 context.  */
1267
++	sha256_finish_ctx(&alt_ctx, alt_result);
1268
++
1269
++	/* Add for any character in the key one byte of the alternate sum.  */
1270
++	for (cnt = key_len; cnt > 32; cnt -= 32) {
1271
++		sha256_process_bytes(alt_result, 32, &ctx);
1272
++	}
1273
++	sha256_process_bytes(alt_result, cnt, &ctx);
1274
++
1275
++	/* Take the binary representation of the length of the key and for every
1276
++	1 add the alternate sum, for every 0 the key.  */
1277
++	for (cnt = key_len; cnt > 0; cnt >>= 1) {
1278
++		if ((cnt & 1) != 0) {
1279
++			sha256_process_bytes(alt_result, 32, &ctx);
1280
++		} else {
1281
++			sha256_process_bytes(key, key_len, &ctx);
1282
++		}
1283
++	}
1284
++
1285
++	/* Create intermediate result.  */
1286
++	sha256_finish_ctx(&ctx, alt_result);
1287
++
1288
++	/* Start computation of P byte sequence.  */
1289
++	sha256_init_ctx(&alt_ctx);
1290
++
1291
++	/* For every character in the password add the entire password.  */
1292
++	for (cnt = 0; cnt < key_len; ++cnt) {
1293
++		sha256_process_bytes(key, key_len, &alt_ctx);
1294
++	}
1295
++
1296
++	/* Finish the digest.  */
1297
++	sha256_finish_ctx(&alt_ctx, temp_result);
1298
++
1299
++	/* Create byte sequence P.  */
1300
++	cp = p_bytes = alloca(key_len);
1301
++	for (cnt = key_len; cnt >= 32; cnt -= 32) {
1302
++		cp = mempcpy((void *)cp, (const void *)temp_result, 32);
1303
++	}
1304
++	memcpy(cp, temp_result, cnt);
1305
++
1306
++	/* Start computation of S byte sequence.  */
1307
++	sha256_init_ctx(&alt_ctx);
1308
++
1309
++	/* For every character in the password add the entire password.  */
1310
++	for (cnt = 0; cnt < 16 + alt_result[0]; ++cnt) {
1311
++		sha256_process_bytes(salt, salt_len, &alt_ctx);
1312
++	}
1313
++
1314
++	/* Finish the digest.  */
1315
++	sha256_finish_ctx(&alt_ctx, temp_result);
1316
++
1317
++	/* Create byte sequence S.  */
1318
++	cp = s_bytes = alloca(salt_len);
1319
++	for (cnt = salt_len; cnt >= 32; cnt -= 32) {
1320
++		cp = mempcpy(cp, temp_result, 32);
1321
++	}
1322
++	memcpy(cp, temp_result, cnt);
1323
++
1324
++	/* Repeatedly run the collected hash value through SHA256 to burn
1325
++	CPU cycles.  */
1326
++	for (cnt = 0; cnt < rounds; ++cnt) {
1327
++		/* New context.  */
1328
++		sha256_init_ctx(&ctx);
1329
++
1330
++		/* Add key or last result.  */
1331
++		if ((cnt & 1) != 0) {
1332
++			sha256_process_bytes(p_bytes, key_len, &ctx);
1333
++		} else {
1334
++			sha256_process_bytes(alt_result, 32, &ctx);
1335
++		}
1336
++
1337
++		/* Add salt for numbers not divisible by 3.  */
1338
++		if (cnt % 3 != 0) {
1339
++			sha256_process_bytes(s_bytes, salt_len, &ctx);
1340
++		}
1341
++
1342
++		/* Add key for numbers not divisible by 7.  */
1343
++		if (cnt % 7 != 0) {
1344
++			sha256_process_bytes(p_bytes, key_len, &ctx);
1345
++		}
1346
++
1347
++		/* Add key or last result.  */
1348
++		if ((cnt & 1) != 0) {
1349
++			sha256_process_bytes(alt_result, 32, &ctx);
1350
++		} else {
1351
++			sha256_process_bytes(p_bytes, key_len, &ctx);
1352
++		}
1353
++
1354
++		/* Create intermediate result.  */
1355
++		sha256_finish_ctx(&ctx, alt_result);
1356
++	}
1357
++
1358
++	/* Now we can construct the result string.  It consists of three
1359
++	parts.  */
1360
++	cp = stpncpy(buffer, sha256_salt_prefix, MAX(0, buflen));
1361
++	buflen -= sizeof(sha256_salt_prefix) - 1;
1362
++
1363
++	if (rounds_custom) {
1364
++#ifdef PHP_WIN32
1365
++		int n = _snprintf(cp, MAX(0, buflen), "%s%u$", sha256_rounds_prefix, rounds);
1366
++#else
1367
++		int n = snprintf(cp, MAX(0, buflen), "%s%zu$", sha256_rounds_prefix, rounds);
1368
++#endif
1369
++		cp += n;
1370
++		buflen -= n;
1371
++	}
1372
++
1373
++	cp = stpncpy(cp, salt, MIN ((size_t) MAX (0, buflen), salt_len));
1374
++	buflen -= MIN((size_t) MAX (0, buflen), salt_len);
1375
++
1376
++	if (buflen > 0) {
1377
++		*cp++ = '$';
1378
++		--buflen;
1379
++	}
1380
++
1381
++#define b64_from_24bit(B2, B1, B0, N)					      \
1382
++  do {									      \
1383
++    unsigned int w = ((B2) << 16) | ((B1) << 8) | (B0);			      \
1384
++    int n = (N);							      \
1385
++    while (n-- > 0 && buflen > 0)					      \
1386
++      {									      \
1387
++	*cp++ = b64t[w & 0x3f];						      \
1388
++	--buflen;							      \
1389
++	w >>= 6;							      \
1390
++      }									      \
1391
++  } while (0)
1392
++
1393
++	b64_from_24bit(alt_result[0], alt_result[10], alt_result[20], 4);
1394
++	b64_from_24bit(alt_result[21], alt_result[1], alt_result[11], 4);
1395
++	b64_from_24bit(alt_result[12], alt_result[22], alt_result[2], 4);
1396
++	b64_from_24bit(alt_result[3], alt_result[13], alt_result[23], 4);
1397
++	b64_from_24bit(alt_result[24], alt_result[4], alt_result[14], 4);
1398
++	b64_from_24bit(alt_result[15], alt_result[25], alt_result[5], 4);
1399
++	b64_from_24bit(alt_result[6], alt_result[16], alt_result[26], 4);
1400
++	b64_from_24bit(alt_result[27], alt_result[7], alt_result[17], 4);
1401
++	b64_from_24bit(alt_result[18], alt_result[28], alt_result[8], 4);
1402
++	b64_from_24bit(alt_result[9], alt_result[19], alt_result[29], 4);
1403
++	b64_from_24bit(0, alt_result[31], alt_result[30], 3);
1404
++	if (buflen <= 0) {
1405
++		errno = ERANGE;
1406
++		buffer = NULL;
1407
++	} else
1408
++		*cp = '\0';		/* Terminate the string.  */
1409
++
1410
++	/* Clear the buffer for the intermediate result so that people
1411
++     attaching to processes or reading core dumps cannot get any
1412
++     information.  We do it in this way to clear correct_words[]
1413
++     inside the SHA256 implementation as well.  */
1414
++	sha256_init_ctx(&ctx);
1415
++	sha256_finish_ctx(&ctx, alt_result);
1416
++	memset(temp_result, '\0', sizeof(temp_result));
1417
++	memset(p_bytes, '\0', key_len);
1418
++	memset(s_bytes, '\0', salt_len);
1419
++	memset(&ctx, '\0', sizeof(ctx));
1420
++	memset(&alt_ctx, '\0', sizeof(alt_ctx));
1421
++
1422
++	if (copied_key != NULL) {
1423
++		memset(copied_key, '\0', key_len);
1424
++
1425
++	}
1426
++	if (copied_salt != NULL) {
1427
++		memset(copied_salt, '\0', salt_len);
1428
++	}
1429
++
1430
++	return buffer;
1431
++}
1432
++
1433
++
1434
++/* This entry point is equivalent to the `crypt' function in Unix
1435
++   libcs.  */
1436
++char * php_sha256_crypt(const char *key, const char *salt)
1437
++{
1438
++	/* We don't want to have an arbitrary limit in the size of the
1439
++	password.  We can compute an upper bound for the size of the
1440
++	result in advance and so we can prepare the buffer we pass to
1441
++	`sha256_crypt_r'.  */
1442
++	static char *buffer;
1443
++	static int buflen;
1444
++	int needed = (sizeof(sha256_salt_prefix) - 1
1445
++			+ sizeof(sha256_rounds_prefix) + 9 + 1
1446
++			+ strlen(salt) + 1 + 43 + 1);
1447
++
1448
++	if (buflen < needed) {
1449
++		char *new_buffer = (char *) realloc(buffer, needed);
1450
++		if (new_buffer == NULL) {
1451
++			return NULL;
1452
++		}
1453
++
1454
++		buffer = new_buffer;
1455
++		buflen = needed;
1456
++	}
1457
++
1458
++	return php_sha256_crypt_r(key, salt, buffer, buflen);
1459
++}
1460
++
1461
++
1462
++#ifdef TEST
1463
++static const struct
1464
++{
1465
++	const char *input;
1466
++	const char result[32];
1467
++} tests[] =
1468
++	{
1469
++	/* Test vectors from FIPS 180-2: appendix B.1.  */
1470
++	{ "abc",
1471
++	"\xba\x78\x16\xbf\x8f\x01\xcf\xea\x41\x41\x40\xde\x5d\xae\x22\x23"
1472
++	"\xb0\x03\x61\xa3\x96\x17\x7a\x9c\xb4\x10\xff\x61\xf2\x00\x15\xad" },
1473
++	/* Test vectors from FIPS 180-2: appendix B.2.  */
1474
++	{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
1475
++	"\x24\x8d\x6a\x61\xd2\x06\x38\xb8\xe5\xc0\x26\x93\x0c\x3e\x60\x39"
1476
++	"\xa3\x3c\xe4\x59\x64\xff\x21\x67\xf6\xec\xed\xd4\x19\xdb\x06\xc1" },
1477
++	/* Test vectors from the NESSIE project.  */
1478
++	{ "",
1479
++	"\xe3\xb0\xc4\x42\x98\xfc\x1c\x14\x9a\xfb\xf4\xc8\x99\x6f\xb9\x24"
1480
++	"\x27\xae\x41\xe4\x64\x9b\x93\x4c\xa4\x95\x99\x1b\x78\x52\xb8\x55" },
1481
++	{ "a",
1482
++	"\xca\x97\x81\x12\xca\x1b\xbd\xca\xfa\xc2\x31\xb3\x9a\x23\xdc\x4d"
1483
++	"\xa7\x86\xef\xf8\x14\x7c\x4e\x72\xb9\x80\x77\x85\xaf\xee\x48\xbb" },
1484
++	{ "message digest",
1485
++	"\xf7\x84\x6f\x55\xcf\x23\xe1\x4e\xeb\xea\xb5\xb4\xe1\x55\x0c\xad"
1486
++	"\x5b\x50\x9e\x33\x48\xfb\xc4\xef\xa3\xa1\x41\x3d\x39\x3c\xb6\x50" },
1487
++	{ "abcdefghijklmnopqrstuvwxyz",
1488
++	"\x71\xc4\x80\xdf\x93\xd6\xae\x2f\x1e\xfa\xd1\x44\x7c\x66\xc9\x52"
1489
++	"\x5e\x31\x62\x18\xcf\x51\xfc\x8d\x9e\xd8\x32\xf2\xda\xf1\x8b\x73" },
1490
++	{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
1491
++	"\x24\x8d\x6a\x61\xd2\x06\x38\xb8\xe5\xc0\x26\x93\x0c\x3e\x60\x39"
1492
++	"\xa3\x3c\xe4\x59\x64\xff\x21\x67\xf6\xec\xed\xd4\x19\xdb\x06\xc1" },
1493
++	{ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
1494
++	"\xdb\x4b\xfc\xbd\x4d\xa0\xcd\x85\xa6\x0c\x3c\x37\xd3\xfb\xd8\x80"
1495
++	"\x5c\x77\xf1\x5f\xc6\xb1\xfd\xfe\x61\x4e\xe0\xa7\xc8\xfd\xb4\xc0" },
1496
++	{ "123456789012345678901234567890123456789012345678901234567890"
1497
++	"12345678901234567890",
1498
++	"\xf3\x71\xbc\x4a\x31\x1f\x2b\x00\x9e\xef\x95\x2d\xd8\x3c\xa8\x0e"
1499
++	"\x2b\x60\x02\x6c\x8e\x93\x55\x92\xd0\xf9\xc3\x08\x45\x3c\x81\x3e" }
1500
++  };
1501
++#define ntests (sizeof (tests) / sizeof (tests[0]))
1502
++
1503
++
1504
++static const struct
1505
++{
1506
++	const char *salt;
1507
++	const char *input;
1508
++	const char *expected;
1509
++} tests2[] =
1510
++{
1511
++	{ "$5$saltstring", "Hello world!",
1512
++	"$5$saltstring$5B8vYYiY.CVt1RlTTf8KbXBH3hsxY/GNooZaBBGWEc5" },
1513
++	{ "$5$rounds=10000$saltstringsaltstring", "Hello world!",
1514
++	"$5$rounds=10000$saltstringsaltst$3xv.VbSHBb41AL9AvLeujZkZRBAwqFMz2."
1515
++	"opqey6IcA" },
1516
++	{ "$5$rounds=5000$toolongsaltstring", "This is just a test",
1517
++	"$5$rounds=5000$toolongsaltstrin$Un/5jzAHMgOGZ5.mWJpuVolil07guHPvOW8"
1518
++	"mGRcvxa5" },
1519
++	{ "$5$rounds=1400$anotherlongsaltstring",
1520
++	"a very much longer text to encrypt.  This one even stretches over more"
1521
++	"than one line.",
1522
++	"$5$rounds=1400$anotherlongsalts$Rx.j8H.h8HjEDGomFU8bDkXm3XIUnzyxf12"
1523
++	"oP84Bnq1" },
1524
++	{ "$5$rounds=77777$short",
1525
++	"we have a short salt string but not a short password",
1526
++	"$5$rounds=77777$short$JiO1O3ZpDAxGJeaDIuqCoEFysAe1mZNJRs3pw0KQRd/" },
1527
++	{ "$5$rounds=123456$asaltof16chars..", "a short string",
1528
++	"$5$rounds=123456$asaltof16chars..$gP3VQ/6X7UUEW3HkBn2w1/Ptq2jxPyzV/"
1529
++	"cZKmF/wJvD" },
1530
++	{ "$5$rounds=10$roundstoolow", "the minimum number is still observed",
1531
++	"$5$rounds=1000$roundstoolow$yfvwcWrQ8l/K0DAWyuPMDNHpIVlTQebY9l/gL97"
1532
++	"2bIC" },
1533
++};
1534
++#define ntests2 (sizeof (tests2) / sizeof (tests2[0]))
1535
++
1536
++
1537
++int main(void) {
1538
++	struct sha256_ctx ctx;
1539
++	char sum[32];
1540
++	int result = 0;
1541
++	int cnt, i;
1542
++	char buf[1000];
1543
++	static const char expected[32] =
1544
++	"\xcd\xc7\x6e\x5c\x99\x14\xfb\x92\x81\xa1\xc7\xe2\x84\xd7\x3e\x67"
1545
++	"\xf1\x80\x9a\x48\xa4\x97\x20\x0e\x04\x6d\x39\xcc\xc7\x11\x2c\xd0";
1546
++
1547
++	for (cnt = 0; cnt < (int) ntests; ++cnt) {
1548
++		sha256_init_ctx(&ctx);
1549
++		sha256_process_bytes(tests[cnt].input, strlen(tests[cnt].input), &ctx);
1550
++		sha256_finish_ctx(&ctx, sum);
1551
++		if (memcmp(tests[cnt].result, sum, 32) != 0) {
1552
++			printf("test %d run %d failed\n", cnt, 1);
1553
++			result = 1;
1554
++		}
1555
++
1556
++		sha256_init_ctx(&ctx);
1557
++		for (i = 0; tests[cnt].input[i] != '\0'; ++i) {
1558
++			sha256_process_bytes(&tests[cnt].input[i], 1, &ctx);
1559
++		}
1560
++		sha256_finish_ctx(&ctx, sum);
1561
++		if (memcmp(tests[cnt].result, sum, 32) != 0) {
1562
++			printf("test %d run %d failed\n", cnt, 2);
1563
++			result = 1;
1564
++		}
1565
++	}
1566
++
1567
++	/* Test vector from FIPS 180-2: appendix B.3.  */
1568
++
1569
++	memset(buf, 'a', sizeof(buf));
1570
++	sha256_init_ctx(&ctx);
1571
++	for (i = 0; i < 1000; ++i) {
1572
++		sha256_process_bytes (buf, sizeof (buf), &ctx);
1573
++	}
1574
++
1575
++	sha256_finish_ctx(&ctx, sum);
1576
++
1577
++	if (memcmp(expected, sum, 32) != 0) {
1578
++		printf("test %d failed\n", cnt);
1579
++		result = 1;
1580
++	}
1581
++
1582
++	for (cnt = 0; cnt < ntests2; ++cnt) {
1583
++		char *cp = php_sha256_crypt(tests2[cnt].input, tests2[cnt].salt);
1584
++		if (strcmp(cp, tests2[cnt].expected) != 0) {
1585
++			printf("test %d: expected \"%s\", got \"%s\"\n", cnt, tests2[cnt].expected, cp);
1586
++			result = 1;
1587
++		}
1588
++	}
1589
++
1590
++	if (result == 0)
1591
++	puts("all tests OK");
1592
++
1593
++	return result;
1594
++}
1595
++#endif
1596
+Index: ext/standard/config.w32
1597
+===================================================================
1598
+--- ext/standard/config.w32	(Revision 291898)
1599
++++ ext/standard/config.w32	(Revision 291899)
1600
+@@ -9,8 +9,8 @@
1601
+ CHECK_HEADER_ADD_INCLUDE("timelib_config.h", "CFLAGS_STANDARD", "ext/date/lib");
1602
+ 
1603
+ EXTENSION("standard", "array.c base64.c basic_functions.c browscap.c \
1604
+-	crc32.c crypt.c \
1605
+-	crypt_freesec.c crypt_blowfish.c php_crypt_r.c \
1606
++	crc32.c crypt.c crypt_freesec.c crypt_blowfish.c crypt_sha256.c \
1607
++	crypt_sha512.c  php_crypt_r.c \
1608
+ 	cyr_convert.c datetime.c dir.c dl.c dns.c dns_win32.c exec.c \
1609
+ 	file.c filestat.c formatted_print.c fsock.c head.c html.c image.c \
1610
+ 	info.c iptc.c lcg.c link_win32.c mail.c math.c md5.c metaphone.c microtime.c \
1611
+Index: ext/standard/php_crypt_r.h
1612
+===================================================================
1613
+--- ext/standard/php_crypt_r.h	(Revision 291898)
1614
++++ ext/standard/php_crypt_r.h	(Revision 291899)
1615
+@@ -49,6 +49,8 @@
1616
+ extern char * php_md5_crypt_r(const char *pw, const char *salt, char *out);
1617
+ extern char * php_crypt_blowfish_rn(__CONST char *key, __CONST char *setting,
1618
+ 	char *output, int size);
1619
++extern char * php_sha512_crypt_r (const char *key, const char *salt, char *buffer, int buflen);
1620
++extern char * php_sha256_crypt_r (const char *key, const char *salt, char *buffer, int buflen);
1621
+ 
1622
+ #ifdef __cplusplus
1623
+ }
1624
+Index: ext/standard/crypt.c
1625
+===================================================================
1626
+--- ext/standard/crypt.c	(Revision 291898)
1627
++++ ext/standard/crypt.c	(Revision 291899)
1628
+@@ -82,6 +82,12 @@
1629
+ #define PHP_MAX_SALT_LEN 60
1630
+ #endif
1631
+ 
1632
++#if PHP_SHA512_CRYPT
1633
++#undef PHP_MAX_SALT_LEN
1634
++#define PHP_MAX_SALT_LEN 123
1635
++#endif
1636
++
1637
++
1638
+ /* If the configure-time checks fail, we provide DES.
1639
+  * XXX: This is a hack. Fix the real problem! */
1640
+ 
1641
+@@ -163,6 +169,7 @@
1642
+ 		php_to64(&salt[0], PHP_CRYPT_RAND, 2);
1643
+ 		salt[2] = '\0';
1644
+ #endif
1645
++		salt_in_len = strlen(salt);
1646
+ 	}
1647
+ 
1648
+ /* Windows (win32/crypt) has a stripped down version of libxcrypt and 
1649
+@@ -175,7 +182,36 @@
1650
+ 			char output[MD5_HASH_MAX_LEN];
1651
+ 
1652
+ 			RETURN_STRING(php_md5_crypt_r(str, salt, output), 1);
1653
+-		} else  if (
1654
++		} else if (salt[0]=='$' && salt[1]=='6' && salt[2]=='$') {
1655
++			const char sha512_salt_prefix[] = "$6$";
1656
++			const char sha512_rounds_prefix[] = "rounds=";
1657
++			char *output;
1658
++			int needed = (sizeof(sha512_salt_prefix) - 1
1659
++						+ sizeof(sha512_rounds_prefix) + 9 + 1
1660
++						+ strlen(salt) + 1 + 43 + 1);
1661
++			output = emalloc(needed * sizeof(char *));
1662
++			salt[salt_in_len] = '\0';
1663
++
1664
++			php_sha512_crypt_r(str, salt, output, needed);
1665
++
1666
++			RETVAL_STRING(output, 1);
1667
++			memset(output, 0, PHP_MAX_SALT_LEN + 1);
1668
++			efree(output);
1669
++		} else if (salt[0]=='$' && salt[1]=='5' && salt[2]=='$') {
1670
++			const char sha256_salt_prefix[] = "$5$";
1671
++			const char sha256_rounds_prefix[] = "rounds=";
1672
++			char *output;
1673
++			int needed = (sizeof(sha256_salt_prefix) - 1
1674
++						+ sizeof(sha256_rounds_prefix) + 9 + 1
1675
++						+ strlen(salt) + 1 + 43 + 1);
1676
++			output = emalloc(needed * sizeof(char *));
1677
++			salt[salt_in_len] = '\0';
1678
++			php_sha256_crypt_r(str, salt, output, needed);
1679
++
1680
++			RETVAL_STRING(output, 1);
1681
++			memset(output, 0, PHP_MAX_SALT_LEN + 1);
1682
++			efree(output);
1683
++		} else if (
1684
+ 				salt[0] == '$' &&
1685
+ 				salt[1] == '2' &&
1686
+ 				salt[2] == 'a' &&
1687
+Index: ext/standard/config.m4
1688
+===================================================================
1689
+--- ext/standard/config.m4	(Revision 291898)
1690
++++ ext/standard/config.m4	(Revision 291899)
1691
+@@ -172,6 +172,65 @@
1692
+   ac_cv_crypt_blowfish=no
1693
+ ])])
1694
+ 
1695
++AC_CACHE_CHECK(for SHA512 crypt, ac_cv_crypt_SHA512,[
1696
++AC_TRY_RUN([
1697
++#if HAVE_UNISTD_H
1698
++#include <unistd.h>
1699
++#endif
1700
++
1701
++#if HAVE_CRYPT_H
1702
++#include <crypt.h>
1703
++#endif
1704
++
1705
++main() {
1706
++#if HAVE_CRYPT
1707
++    char salt[30], answer[80];
1708
++    
1709
++    salt[0]='$'; salt[1]='6'; salt[2]='$'; salt[3]='$'; salt[4]='b'; salt[5]='a'; salt[6]='r'; salt[7]='\0';
1710
++    strcpy(answer, salt);
1711
++    strcpy(&answer[29],"$6$$QMXjqd7rHQZPQ1yHsXkQqC1FBzDiVfTHXL.LaeDAeVV.IzMaV9VU4MQ8kPuZa2SOP1A0RPm772EaFYjpEJtdu.");
1712
++    exit (strcmp((char *)crypt("foo",salt),answer));
1713
++#else
1714
++	exit(0);
1715
++#endif
1716
++}],[
1717
++  ac_cv_crypt_SHA512=yes
1718
++],[
1719
++  ac_cv_crypt_SHA512=no
1720
++],[
1721
++  ac_cv_crypt_SHA512=no
1722
++])])
1723
++
1724
++AC_CACHE_CHECK(for SHA256 crypt, ac_cv_crypt_SHA256,[
1725
++AC_TRY_RUN([
1726
++#if HAVE_UNISTD_H
1727
++#include <unistd.h>
1728
++#endif
1729
++
1730
++#if HAVE_CRYPT_H
1731
++#include <crypt.h>
1732
++#endif
1733
++
1734
++main() {
1735
++#if HAVE_CRYPT
1736
++    char salt[30], answer[80];
1737
++    salt[0]='$'; salt[1]='5'; salt[2]='$'; salt[3]='$'; salt[4]='s'; salt[5]='a'; salt[6]='l'; salt[7]='t';  salt[8]='s'; salt[9]='t'; salt[10]='r'; salt[11]='i'; salt[12]='n'; salt[13]='g'; salt[14]='\0';    
1738
++    strcat(salt,"");
1739
++    strcpy(answer, salt);
1740
++    strcpy(&answer[29], "$5$saltstring$5B8vYYiY.CVt1RlTTf8KbXBH3hsxY/GNooZaBBGWEc5");
1741
++    exit (strcmp((char *)crypt("foo",salt),answer));
1742
++#else
1743
++	exit(0);
1744
++#endif
1745
++}],[
1746
++  ac_cv_crypt_SHA256=yes
1747
++],[
1748
++  ac_cv_crypt_SHA256=no
1749
++],[
1750
++  ac_cv_crypt_SHA256=no
1751
++])])
1752
++
1753
++
1754
+ dnl
1755
+ dnl If one of them is missing, use our own implementation, portable code is then possible
1756
+ dnl
1757
+@@ -181,8 +240,10 @@
1758
+   AC_DEFINE_UNQUOTED(PHP_BLOWFISH_CRYPT, 1, [Whether the system supports BlowFish salt])
1759
+   AC_DEFINE_UNQUOTED(PHP_EXT_DES_CRYPT, 1, [Whether the system supports extended DES salt])
1760
+   AC_DEFINE_UNQUOTED(PHP_MD5_CRYPT, 1, [Whether the system supports extended DES salt])
1761
++  AC_DEFINE_UNQUOTED(PHP_SHA512_CRYPT, 1, [Whether the system supports SHA512 salt])
1762
++  AC_DEFINE_UNQUOTED(PHP_SHA256_CRYPT, 1, [Whether the system supports SHA256 salt])
1763
+ 
1764
+-  PHP_ADD_SOURCES(PHP_EXT_DIR(standard), crypt_freesec.c crypt_blowfish.c php_crypt_r.c)
1765
++  PHP_ADD_SOURCES(PHP_EXT_DIR(standard), crypt_freesec.c crypt_blowfish.c crypt_sha512.c crypt_sha256.c php_crypt_r.c)
1766
+ else
1767
+   if test "$ac_cv_crypt_des" = "yes"; then
1768
+     ac_result=1
1769
+@@ -211,13 +272,31 @@
1770
+   fi
1771
+   AC_DEFINE_UNQUOTED(PHP_EXT_DES_CRYPT, $ac_result, [Whether the system supports extended DES salt])
1772
+ 
1773
++  if test "$ac_cv_crypt_sha512" = "yes"; then
1774
++    ac_result=1
1775
++    ac_crypt_sha512=1
1776
++  else
1777
++    ac_result=0
1778
++    ac_crypt_sha512=0
1779
++  fi
1780
++  AC_DEFINE_UNQUOTED(PHP_EXT_SHA512_CRYPT, $ac_result, [Whether the system supports SHA512 salt])
1781
++
1782
++  if test "$ac_cv_crypt_sha256" = "yes"; then
1783
++    ac_result=1
1784
++    ac_crypt_sha256=1
1785
++  else
1786
++    ac_result=0
1787
++    ac_crypt_sha256=0
1788
++  fi
1789
++  AC_DEFINE_UNQUOTED(PHP_EXT_SHA256_CRYPT, $ac_result, [Whether the system supports SHA256 salt])
1790
++
1791
+   AC_DEFINE_UNQUOTED(PHP_USE_PHP_CRYPT_R, 0, [Whether PHP has to use its own crypt_r for blowfish, des and ext des])
1792
+ fi
1793
+ 
1794
+ dnl
1795
+ dnl Check for available functions
1796
+ dnl
1797
+-AC_CHECK_FUNCS(getcwd getwd asinh acosh atanh log1p hypot glob strfmon nice fpclass isinf isnan)
1798
++AC_CHECK_FUNCS(getcwd getwd asinh acosh atanh log1p hypot glob strfmon nice fpclass isinf isnan mempcpy strpncpy)
1799
+ AC_FUNC_FNMATCH	
1800
+ 
1801
+ divert(5)dnl
... ...
@@ -0,0 +1 @@
1
+PHP_5 { global: *; };
... ...
@@ -0,0 +1,4 @@
1
+change all $(get_libdir)/php appearances in both eclass and ebuild to something like php52
2
+change all /etc/php appearances in ebuild and eclass to sth. /etc/php53
3
+disable mod_php (USE=-apache2)
4
+change /etc/env.d/20php5 to sth. 20php53 in ebuild
... ...
@@ -0,0 +1,551 @@
1
+# Copyright 1999-2010 Gentoo Foundation
2
+# Distributed under the terms of the GNU General Public License v2
3
+# $Header: /var/cvsroot/gentoo-x86/dev-lang/php/php-5.2.13.ebuild,v 1.8 2010/07/05 23:19:20 mabi Exp $
4
+
5
+CGI_SAPI_USE="discard-path force-cgi-redirect"
6
+APACHE2_SAPI_USE="concurrentmodphp threads"
7
+IUSE="cli cgi ${CGI_SAPI_USE} ${APACHE2_SAPI_USE} fastbuild"
8
+
9
+KEYWORDS="alpha amd64 arm hppa ia64 ppc ppc64 s390 sh sparc x86 ~x86-fbsd"
10
+
11
+# NOTE: Portage doesn't support setting PROVIDE based on the USE flags
12
+#		that have been enabled, so we have to PROVIDE everything for now
13
+#		and hope for the best
14
+PROVIDE="virtual/php"
15
+
16
+# php package settings
17
+SLOT="5.2"
18
+MY_PHP_PV="${PV}"
19
+MY_PHP_P="php-${MY_PHP_PV}"
20
+PHP_PACKAGE="1"
21
+# php patch settings, general
22
+PHP_PATCHSET_REV="${PR/r/}"
23
+PHP_PATCHSET_URI="http://dev.gentoo.org/~keytoaster/distfiles/php-patchset-${PV}-r${PHP_PATCHSET_REV}.tar.bz2"
24
+SUHOSIN_PATCH="suhosin-patch-5.2.13-0.9.7.patch.gz"
25
+MULTILIB_PATCH="${MY_PHP_PV}/opt/multilib-search-path.patch"
26
+# php patch settings, ebuild specific
27
+FASTBUILD_PATCH="${MY_PHP_PV}/opt/fastbuild.patch"
28
+CONCURRENTMODPHP_PATCH="${MY_PHP_PV}/opt/concurrent_apache_modules.patch"
29
+# kolab patch - http://kolab.org/cgi-bin/viewcvs-kolab.cgi/server/patches/php/
30
+# bugs about this go to wrobel@gentoo.org
31
+KOLAB_PATCH="${MY_PHP_PV}/opt/kolab-imap-annotations.patch"
32
+
33
+inherit versionator php5_2-sapi apache-module
34
+
35
+# Suhosin patch support
36
+[[ -n "${SUHOSIN_PATCH}" ]] && SRC_URI="${SRC_URI} suhosin? (
37
+http://download.suhosin.org/${SUHOSIN_PATCH} )"
38
+
39
+DESCRIPTION="The PHP language runtime engine: CLI, CGI and Apache2 SAPIs."
40
+
41
+DEPEND="app-admin/php-toolkit
42
+	imap? ( >=virtual/imap-c-client-2006k )
43
+	pcre? ( >=dev-libs/libpcre-7.8 )
44
+	xml? ( >=dev-libs/libxml2-2.7.2-r2 )
45
+	xmlrpc? ( >=dev-libs/libxml2-2.7.2-r2 virtual/libiconv )"
46
+
47
+RDEPEND="${DEPEND}"
48
+if [[ -n "${KOLAB_PATCH}" ]] ; then
49
+	IUSE="${IUSE} kolab"
50
+	DEPEND="${DEPEND}
51
+		kolab? ( >=net-libs/c-client-2004g-r1 )"
52
+fi
53
+
54
+PDEPEND="suhosin? ( >=dev-php5/suhosin-0.9.29 )"
55
+
56
+want_apache
57
+
58
+pkg_setup() {
59
+	PHPCONFUTILS_AUTO_USE=""
60
+
61
+	# Make sure the user has specified at least one SAPI
62
+	einfo "Determining SAPI(s) to build"
63
+	phpconfutils_require_any "  Enabled  SAPI:" "  Disabled SAPI:" cli cgi apache2
64
+
65
+	# Threaded Apache2 support
66
+	if use apache2 ; then
67
+		has_apache_threads
68
+	fi
69
+
70
+	# Concurrent PHP Apache2 modules support
71
+	if use apache2 ; then
72
+		if use concurrentmodphp ; then
73
+			ewarn
74
+			ewarn "'concurrentmodphp' makes it possible to load multiple, differently"
75
+			ewarn "versioned mod_php's into the same Apache instance. This is done with"
76
+			ewarn "a few linker tricks and workarounds, and is not guaranteed to always"
77
+			ewarn "work correctly, so use it at your own risk. Especially, do not use"
78
+			ewarn "this in conjunction with PHP modules (PECL, ...) other than the ones"
79
+			ewarn "you may find in the Portage tree or the PHP Overlay!"
80
+			ewarn "This is an experimental feature, so please rebuild PHP"
81
+			ewarn "without the 'concurrentmodphp' USE flag if you experience"
82
+			ewarn "any problems, and then reproduce any bugs before filing"
83
+			ewarn "them in Gentoo's Bugzilla or bugs.php.net."
84
+			ewarn "If you have conclusive evidence that a bug directly"
85
+			ewarn "derives from 'concurrentmodphp', please file a bug in"
86
+			ewarn "Gentoo's Bugzilla only."
87
+			ewarn
88
+			ebeep 5
89
+		fi
90
+	fi
91
+
92
+	# fastbuild support
93
+	if use fastbuild ; then
94
+		ewarn
95
+		ewarn "'fastbuild' attempts to build all SAPIs in a single pass."
96
+		ewarn "This is an experimental feature, so please rebuild PHP"
97
+		ewarn "without the 'fastbuild' USE flag if you experience"
98
+		ewarn "any problems, and then reproduce any bugs before filing"
99
+		ewarn "them in Gentoo's Bugzilla or bugs.php.net."
100
+		ewarn "If you have conclusive evidence that a bug directly"
101
+		ewarn "derives from 'fastbuild', please file a bug in"
102
+		ewarn "Gentoo's Bugzilla only."
103
+		ewarn
104
+	fi
105
+
106
+	if use pcre ; then
107
+		built_with_use dev-libs/libpcre unicode || \
108
+			die "Please rebuild dev-libs/libpcre with USE=unicode"
109
+	fi
110
+
111
+	depend.apache_pkg_setup
112
+	php5_2-sapi_pkg_setup
113
+}
114
+
115
+php_determine_sapis() {
116
+	# holds the list of sapis that we want to build
117
+	PHPSAPIS=
118
+
119
+	if use cli || phpconfutils_usecheck cli ; then
120
+		PHPSAPIS="${PHPSAPIS} cli"
121
+	fi
122
+
123
+	if use cgi ; then
124
+		PHPSAPIS="${PHPSAPIS} cgi"
125
+	fi
126
+
127
+	# note - apache SAPI comes after the simpler cli/cgi sapis
128
+	if use apache2 ; then
129
+		PHPSAPIS="${PHPSAPIS} apache${APACHE_VERSION}"
130
+	fi
131
+}
132
+
133
+src_unpack() {
134
+	if [[ "${PHP_PACKAGE}" == 1 ]] ; then
135
+		unpack ${A}
136
+	fi
137
+
138
+	cd "${S}"
139
+
140
+	epatch "${FILESDIR}"/${PN}-5.2.12-libpng14.patch
141
+
142
+	# Concurrent PHP Apache2 modules support
143
+	if use apache2 ; then
144
+		if use concurrentmodphp ; then
145
+			if [[ -n "${CONCURRENTMODPHP_PATCH}" ]] && [[ -f "${WORKDIR}/${CONCURRENTMODPHP_PATCH}" ]] ; then
146
+				epatch "${WORKDIR}/${CONCURRENTMODPHP_PATCH}"
147
+			else
148
+				ewarn "There is no concurrent mod_php patch available for this PHP release yet!"
149
+			fi
150
+		fi
151
+	fi
152
+
153
+	# fastbuild support
154
+	if use fastbuild ; then
155
+		if [[ -n "${FASTBUILD_PATCH}" ]] && [[ -f "${WORKDIR}/${FASTBUILD_PATCH}" ]] ; then
156
+			epatch "${WORKDIR}/${FASTBUILD_PATCH}"
157
+		else
158
+			ewarn "There is no fastbuild patch available for this PHP release yet!"
159
+		fi
160
+	fi
161
+
162
+	# kolab support
163
+	if [[ -n "${KOLAB_PATCH}" ]] ; then
164
+		use kolab && epatch "${WORKDIR}/${KOLAB_PATCH}"
165
+	fi
166
+
167
+	# pretend to not have flex, bug 221357
168
+	sed -re 's:( +)PHP_SUBST\(LEX\):\1LEX="exit 0;"\n\0:' -i acinclude.m4
169
+
170
+	# Now let the eclass do the rest and regenerate the configure
171
+	php5_2-sapi_src_unpack
172
+
173
+	# Fix Makefile.global:test to consider the CGI SAPI if present
174
+	if use cgi ; then
175
+		sed -e "s|test \! -z \"\$(top_builddir)/php-cli\" \&\& test -x \"\$(top_builddir)/php-cli\"|test \! -z \"\$(top_builddir)/php-cli\" \&\& test -x \"\$(top_builddir)/php-cli\" \&\& test \! -z \"\$(top_builddir)/php-cgi\" \&\& test -x \"\$(top_builddir)/php-cgi\"|g" -i Makefile.global
176
+		sed -e "s|TEST_PHP_EXECUTABLE=\"\$(top_builddir)/php-cli\"|TEST_PHP_EXECUTABLE=\"\$(top_builddir)/php-cli\" TEST_PHP_CGI_EXECUTABLE=\"\$(top_builddir)/php-cgi\"|g" -i Makefile.global
177
+	fi
178
+
179
+	# try to fix some test cases which fail because of sandbox otherwise
180
+	sed -e 's:/no/such/:.\0:' -i ext/standard/tests/file/005_error.phpt \
181
+		ext/standard/tests/file/006_error.phpt \
182
+		ext/standard/tests/file/touch.phpt
183
+
184
+	# REMOVING BROKEN TESTS:
185
+	# removing this test as it has been broken for ages and is not easily
186
+	# fixable (depends on a lot of factors)
187
+	rm ext/standard/tests/general_functions/phpinfo.phpt
188
+
189
+	# never worked properly, no easy fix
190
+	rm ext/iconv/tests/iconv_stream_filter.phpt
191
+
192
+	# needs write access to /tmp and others
193
+	rm ext/session/tests/session_save_path_variation5.phpt
194
+
195
+	# new tests since 5.2.7 which have never been working for me
196
+	rm ext/spl/tests/arrayObject___construct_basic4.phpt \
197
+		ext/spl/tests/arrayObject___construct_basic5.phpt \
198
+		ext/spl/tests/arrayObject_exchangeArray_basic3.phpt \
199
+		ext/spl/tests/arrayObject_setFlags_basic1.phpt
200
+
201
+	# those might as well be related to suhosin
202
+	rm ext/session/tests/session_decode_variation3.phpt \
203
+		ext/session/tests/session_encode_variation8.phpt
204
+
205
+	# missing skipif
206
+	use reflection || \
207
+		rm ext/standard/tests/directory/DirectoryClass_basic_001.phpt
208
+
209
+	# sandbox-related (sandbox checks for permissions before even looking
210
+	# at the fs, but the tests expect "No such file or directory"
211
+	sed -e 's:/blah:./bla:' -i \
212
+		ext/session/tests/session_save_path_variation{2,3}.phpt
213
+	rm ext/standard/tests/file/rename_variation13.phpt
214
+
215
+	# test passes, but run-tests.php claims failure
216
+	rm ext/standard/tests/file/tempnam_variation4.phpt
217
+
218
+	# these tests behave differently with suhosin enabled, adapting them...
219
+	use suhosin && sed -e 's:File(\.\./):File(..):g' -i \
220
+		tests/security/open_basedir*{.inc,.phpt}
221
+}
222
+
223
+src_compile() {
224
+	# bug 217392 (autconf-2.62 behavior changes)
225
+	export CFLAGS="${CFLAGS} -D_GNU_SOURCE"
226
+	export CXXFLAGS="${CXXFLAGS} -D_GNU_SOURCE"
227
+	if use fastbuild && [[ -n "${FASTBUILD_PATCH}" ]] ; then
228
+		src_compile_fastbuild
229
+	else
230
+		src_compile_normal
231
+	fi
232
+}
233
+
234
+src_compile_fastbuild() {
235
+	php_determine_sapis
236
+
237
+	build_cli=0
238
+	build_cgi=0
239
+	build_apache2=0
240
+	my_conf=""
241
+
242
+	for x in ${PHPSAPIS} ; do
243
+		case ${x} in
244
+			cli)
245
+				build_cli=1
246
+				;;
247
+			cgi)
248
+				build_cgi=1
249
+				;;
250
+			apache2)
251
+				build_apache2=1
252
+				;;
253
+		esac
254
+	done
255
+
256
+	if [[ ${build_cli} = 1 ]] ; then
257
+		my_conf="${my_conf} --enable-cli"
258
+	else
259
+		my_conf="${my_conf} --disable-cli"
260
+	fi
261
+
262
+	if [[ ${build_cgi} = 1 ]] ; then
263
+		my_conf="${my_conf} --enable-cgi --enable-fastcgi"
264
+		phpconfutils_extension_enable "discard-path" "discard-path" 0
265
+		phpconfutils_extension_enable "force-cgi-redirect" "force-cgi-redirect" 0
266
+	else
267
+		my_conf="${my_conf} --disable-cgi"
268
+	fi
269
+
270
+	if [[ ${build_apache2} = 1 ]] ; then
271
+		my_conf="${my_conf} --with-apxs2=/usr/sbin/apxs2"
272
+
273
+		# Threaded Apache2 support
274
+		if use threads ; then
275
+			my_conf="${my_conf} --enable-maintainer-zts"
276
+			ewarn "Enabling ZTS for Apache2 MPM"
277
+		fi
278
+
279
+		# Concurrent PHP Apache2 modules support
280
+		if use concurrentmodphp ; then
281
+			append-ldflags "-Wl,--version-script=${FILESDIR}/php5-ldvs"
282
+		fi
283
+	fi
284
+
285
+	if use pcre || phpconfutils_usecheck pcre ; then
286
+		myconf="${my_conf} --with-pcre-dir=/usr"
287
+		phpconfutils_extension_with "pcre-regex" "pcre" 0 "/usr"
288
+	fi
289
+
290
+	# Now we know what we are building, build it
291
+	php5_2-sapi_src_compile
292
+
293
+	# To keep the separate php.ini files for each SAPI, we change the
294
+	# build-defs.h and recompile
295
+
296
+	if [[ ${build_cli} = 1 ]] ; then
297
+		einfo
298
+		einfo "Building CLI SAPI"
299
+		einfo
300
+
301
+		sed -e 's|^#define PHP_CONFIG_FILE_PATH.*|#define PHP_CONFIG_FILE_PATH "/etc/php52/cli-php5"|g;' -i main/build-defs.h
302
+		sed -e 's|^#define PHP_CONFIG_FILE_SCAN_DIR.*|#define PHP_CONFIG_FILE_SCAN_DIR "/etc/php52/cli-php5/ext-active"|g;' -i main/build-defs.h
303
+		for x in main/main.o main/main.lo main/php_ini.o main/php_ini.lo ; do
304
+			[[ -f ${x} ]] && rm -f ${x}
305
+		done
306
+		make sapi/cli/php || die "Unable to make CLI SAPI"
307
+		cp sapi/cli/php php-cli || die "Unable to copy CLI SAPI"
308
+	fi
309
+
310
+	if [[ ${build_cgi} = 1 ]] ; then
311
+		einfo
312
+		einfo "Building CGI SAPI"
313
+		einfo
314
+
315
+		sed -e 's|^#define PHP_CONFIG_FILE_PATH.*|#define PHP_CONFIG_FILE_PATH "/etc/php52/cgi-php5"|g;' -i main/build-defs.h
316
+		sed -e 's|^#define PHP_CONFIG_FILE_SCAN_DIR.*|#define PHP_CONFIG_FILE_SCAN_DIR "/etc/php52/cgi-php5/ext-active"|g;' -i main/build-defs.h
317
+		for x in main/main.o main/main.lo main/php_ini.o main/php_ini.lo ; do
318
+			[[ -f ${x} ]] && rm -f ${x}
319
+		done
320
+		make sapi/cgi/php-cgi || die "Unable to make CGI SAPI"
321
+		cp sapi/cgi/php-cgi php-cgi || die "Unable to copy CGI SAPI"
322
+	fi
323
+
324
+	if [[ ${build_apache2} = 1 ]] ; then
325
+		einfo
326
+		einfo "Building apache${APACHE_VERSION} SAPI"
327
+		einfo
328
+
329
+		sed -e "s|^#define PHP_CONFIG_FILE_PATH.*|#define PHP_CONFIG_FILE_PATH \"/etc/php52/apache${APACHE_VERSION}-php5\"|g;" -i main/build-defs.h
330
+		sed -e "s|^#define PHP_CONFIG_FILE_SCAN_DIR.*|#define PHP_CONFIG_FILE_SCAN_DIR \"/etc/php52/apache${APACHE_VERSION}-php5/ext-active\"|g;" -i main/build-defs.h
331
+		for x in main/main.o main/main.lo main/php_ini.o main/php_ini.lo ; do
332
+			[[ -f ${x} ]] && rm -f ${x}
333
+		done
334
+		make || die "Unable to make apache${APACHE_VERSION} SAPI"
335
+	fi
336
+}
337
+
338
+src_compile_normal() {
339
+	php_determine_sapis
340
+
341
+	CLEAN_REQUIRED=0
342
+	my_conf=""
343
+
344
+	# Support the Apache2 extras, they must be set globally for all
345
+	# SAPIs to work correctly, especially for external PHP extensions
346
+	if use apache2 ; then
347
+		# Concurrent PHP Apache2 modules support
348
+		if use concurrentmodphp ; then
349
+			append-ldflags "-Wl,--version-script=${FILESDIR}/php5-ldvs"
350
+		fi
351
+	fi
352
+
353
+	for x in ${PHPSAPIS} ; do
354
+		if use pcre || phpconfutils_usecheck pcre ; then
355
+			myconf="${my_conf} --with-pcre-dir=/usr"
356
+			phpconfutils_extension_with "pcre-regex" "pcre" 0 "/usr"
357
+		fi
358
+
359
+		# Support the Apache2 extras, they must be set globally for all
360
+		# SAPIs to work correctly, especially for external PHP extensions
361
+		if use apache2 ; then
362
+			# Threaded Apache2 support
363
+			if use threads ; then
364
+				my_conf="${my_conf} --enable-maintainer-zts"
365
+				ewarn "Enabling ZTS for Apache2 MPM"
366
+			fi
367
+		fi
368
+
369
+		if [[ "${CLEAN_REQUIRED}" = 1 ]] ; then
370
+			make clean
371
+		fi
372
+
373
+		PHPSAPI="${x}"
374
+
375
+		case ${x} in
376
+			cli)
377
+				my_conf="${my_conf} --enable-cli --disable-cgi"
378
+				php5_2-sapi_src_compile
379
+				cp sapi/cli/php php-cli || die "Unable to copy CLI SAPI"
380
+				;;
381
+			cgi)
382
+				my_conf="${my_conf} --disable-cli --enable-cgi --enable-fastcgi"
383
+				phpconfutils_extension_enable "discard-path" "discard-path" 0
384
+				phpconfutils_extension_enable "force-cgi-redirect" "force-cgi-redirect" 0
385
+				php5_2-sapi_src_compile
386
+				cp sapi/cgi/php-cgi php-cgi || die "Unable to copy CGI SAPI"
387
+				;;
388
+			apache2)
389
+				my_conf="${my_conf} --disable-cli --with-apxs2=/usr/sbin/apxs2"
390
+				php5_2-sapi_src_compile
391
+				;;
392
+		esac
393
+
394
+		CLEAN_REQUIRED=1
395
+		my_conf=""
396
+	done
397
+}
398
+
399
+src_install() {
400
+	php_determine_sapis
401
+
402
+	destdir=/usr/$(get_libdir)/php52
403
+
404
+	# Let the eclass do the common work
405
+	php5_2-sapi_src_install
406
+
407
+	einfo
408
+	einfo "Installing SAPI(s) ${PHPSAPIS}"
409
+	einfo
410
+
411
+	for x in ${PHPSAPIS} ; do
412
+
413
+		PHPSAPI="${x}"
414
+
415
+		case ${x} in
416
+			cli)
417
+				einfo "Installing CLI SAPI"
418
+				into ${destdir}
419
+				newbin php-cli php || die "Unable to install ${x} sapi"
420
+				php5_2-sapi_install_ini
421
+				;;
422
+			cgi)
423
+				einfo "Installing CGI SAPI"
424
+				into ${destdir}
425
+				dobin php-cgi || die "Unable to install ${x} sapi"
426
+				php5_2-sapi_install_ini
427
+				;;
428
+			apache2)
429
+				einfo "Installing Apache${APACHE_VERSION} SAPI"
430
+				make INSTALL_ROOT="${D}" install-sapi || die "Unable to install ${x} SAPI"
431
+				if use concurrentmodphp ; then
432
+					einfo "Installing Apache${APACHE_VERSION} config file for PHP5-concurrent (70_mod_php5_concurr.conf)"
433
+					insinto ${APACHE_MODULES_CONFDIR}
434
+					newins "${FILESDIR}/70_mod_php5_concurr.conf-apache2-r1" "70_mod_php5_concurr.conf"
435
+
436
+					# Put the ld version script in the right place so it's always accessible
437
+					insinto "/var/lib/php-pkg/${CATEGORY}/${PN}-${PVR}/"
438
+					doins "${FILESDIR}/php5-ldvs"
439
+
440
+					# Redefine the extension dir to have the modphp suffix
441
+					PHPEXTDIR="`"${D}/${destdir}/bin/php-config" --extension-dir`-versioned"
442
+				else
443
+					einfo "Installing Apache${APACHE_VERSION} config file for PHP5 (70_mod_php5.conf)"
444
+					insinto ${APACHE_MODULES_CONFDIR}
445
+					newins "${FILESDIR}/70_mod_php5.conf-apache2-r1" "70_mod_php5.conf"
446
+				fi
447
+				php5_2-sapi_install_ini
448
+				;;
449
+		esac
450
+	done
451
+
452
+	# Install env.d files
453
+	newenvd "${FILESDIR}/20php5-envd" "20php52"
454
+	sed -e "s|/lib/|/$(get_libdir)/|g" -i "${D}/etc/env.d/20php52"
455
+}
456
+
457
+pkg_postinst() {
458
+	# Output some general info to the user
459
+	if use apache2 ; then
460
+		APACHE2_MOD_DEFINE="PHP5"
461
+		if use concurrentmodphp ; then
462
+			APACHE2_MOD_CONF="70_mod_php5_concurr"
463
+		else
464
+			APACHE2_MOD_CONF="70_mod_php5"
465
+		fi
466
+		apache-module_pkg_postinst
467
+	fi
468
+
469
+	# Update Apache2 to use mod_php
470
+	if use apache2 ; then
471
+		"${ROOT}/usr/sbin/php-select" -t apache2 php5 > /dev/null 2>&1
472
+		exitStatus=$?
473
+		if [[ ${exitStatus} == 2 ]] ; then
474
+			php-select apache2 php5
475
+		elif [[ ${exitStatus} == 4 ]] ; then
476
+			ewarn
477
+			ewarn "Apache2 is configured to load a different version of PHP."
478
+			ewarn "To make Apache2 use PHP v5, use php-select:"
479
+			ewarn
480
+			ewarn "    php-select apache2 php5"
481
+			ewarn
482
+		fi
483
+	fi
484
+
485
+	# Create the symlinks for php-cli
486
+	if use cli || phpconfutils_usecheck cli ; then
487
+		"${ROOT}/usr/sbin/php-select" -t php php5 > /dev/null 2>&1
488
+		exitStatus=$?
489
+		if [[ ${exitStatus} == 5 ]] ; then
490
+			php-select php php5
491
+		elif [[ ${exitStatus} == 4 ]] ; then
492
+			ewarn
493
+			ewarn "/usr/bin/php links to a different version of PHP."
494
+			ewarn "To make /usr/bin/php point to PHP v5, use php-select:"
495
+			ewarn
496
+			ewarn "    php-select php php5"
497
+			ewarn
498
+		fi
499
+	fi
500
+
501
+	# Create the symlinks for php-cgi
502
+	if use cgi ; then
503
+		"${ROOT}/usr/sbin/php-select" -t php-cgi php5 > /dev/null 2>&1
504
+		exitStatus=$?
505
+		if [[ ${exitStatus} == 5 ]] ; then
506
+			php-select php-cgi php5
507
+		elif [[ ${exitStatus} == 4 ]] ; then
508
+			ewarn
509
+			ewarn "/usr/bin/php-cgi links to a different version of PHP."
510
+			ewarn "To make /usr/bin/php-cgi point to PHP v5, use php-select:"
511
+			ewarn
512
+			ewarn "    php-select php-cgi php5"
513
+			ewarn
514
+		fi
515
+	fi
516
+
517
+	# Create the symlinks for php-devel
518
+	"${ROOT}/usr/sbin/php-select" -t php-devel php5 > /dev/null 2>&1
519
+	exitStatus=$?
520
+	if [[ $exitStatus == 5 ]] ; then
521
+		php-select php-devel php5
522
+	elif [[ $exitStatus == 4 ]] ; then
523
+		ewarn
524
+		ewarn "/usr/bin/php-config and/or /usr/bin/phpize are linked to a"
525
+		ewarn "different version of PHP. To make them point to PHP v5, use"
526
+		ewarn "php-select:"
527
+		ewarn
528
+		ewarn "    php-select php-devel php5"
529
+		ewarn
530
+	fi
531
+
532
+	php5_2-sapi_pkg_postinst
533
+}
534
+
535
+src_test() {
536
+	echo ">>> Test phase [test]: ${CATEGORY}/${PF}"
537
+	if [[ ! -x "${S}"/php-cli ]]; then
538
+		ewarn "Running the php test suite requires USE=cli"
539
+		return
540
+	fi
541
+
542
+	export TEST_PHP_EXECUTABLE="${S}"/php-cli
543
+	if [[ -x "${S}"/php-cgi ]]; then
544
+		export TEST_PHP_CGI_EXECUTABLE="${S}"/php-cgi
545
+	fi
546
+	REPORT_EXIT_STATUS=1 "${S}"/php-cli -n "${S}"/run-tests.php -n
547
+
548
+	if [[ $? != 0 ]] ; then
549
+		eerror "Not all tests were successful!"
550
+	fi
551
+}
0 552