mirror of
https://github.com/php-gnupg/php-gnupg.git
synced 2024-11-22 06:27:08 +00:00
improved PHP4 compatibility and config.m4
passphrase-errors now takes care of the actual errormode
This commit is contained in:
parent
7852127f8d
commit
f3a9027773
7 changed files with 112 additions and 50 deletions
|
@ -2,7 +2,7 @@ dnl $Id$
|
|||
dnl config.m4 for extension gnupg
|
||||
|
||||
PHP_ARG_WITH(gnupg, for gnupg support,
|
||||
[ --with-gnupg[=DIR] Include gnupg support])
|
||||
[ --with-gnupg[=dir] Include gnupg support])
|
||||
|
||||
if test "$PHP_GNUPG" != "no"; then
|
||||
SEARCH_PATH="/usr/local/include /usr/include /usr/local/include/gpgme/ /usr/include/gpgme/"
|
||||
|
|
86
gnupg.c
86
gnupg.c
|
@ -6,7 +6,7 @@
|
|||
| modification, are permitted provided that the conditions mentioned |
|
||||
| in the accompanying LICENSE file are met. |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright (c) 2005, Thilo Raufeisen <traufeisen@php.net> |
|
||||
| Copyright (c) 2006, Thilo Raufeisen <traufeisen@php.net> |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
|
@ -27,13 +27,15 @@
|
|||
|
||||
static int le_gnupg;
|
||||
|
||||
#define PHP_GNUPG_VERSION "0.7beta"
|
||||
#define PHP_GNUPG_VERSION "1.1"
|
||||
|
||||
#ifdef ZEND_ENGINE_2
|
||||
static zend_object_handlers gnupg_object_handlers;
|
||||
#endif
|
||||
|
||||
/* {{{ defs */
|
||||
#ifdef ZEND_ENGINE_2
|
||||
|
||||
#define GNUPG_GETOBJ() \
|
||||
zval *this = getThis(); \
|
||||
gnupg_object *intern; \
|
||||
|
@ -61,7 +63,26 @@ static zend_object_handlers gnupg_object_handlers;
|
|||
}else{ \
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, (char*)error); \
|
||||
} \
|
||||
RETVAL_FALSE;
|
||||
if(return_value){ \
|
||||
RETVAL_FALSE; \
|
||||
}
|
||||
#else
|
||||
#define GNUPG_ERR(error) \
|
||||
if(intern && intern->errormode!=1) { \
|
||||
intern->errortxt = (char*)error; \
|
||||
}else{ \
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, (char*)error); \
|
||||
} \
|
||||
if(return_value){ \
|
||||
RETVAL_FALSE; \
|
||||
}
|
||||
|
||||
#define GNUPG_GETOBJ() \
|
||||
zval *this = NULL; \
|
||||
zval *res; \
|
||||
gnupg_object *intern;
|
||||
|
||||
#endif
|
||||
/* }}} */
|
||||
|
||||
/* {{{ free encryptkeys */
|
||||
|
@ -196,7 +217,24 @@ static zend_function_entry gnupg_methods[] = {
|
|||
ZEND_ME(gnupg, seterrormode, NULL, ZEND_ACC_PUBLIC)
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
/* }}} */
|
||||
|
||||
/* {{{ class constants */
|
||||
static void gnupg_declare_long_constant(const char *const_name, long value TSRMLS_DC){
|
||||
#if PHP_MAJOR_VERSION > 5 || PHP_MINOR_VERSION >= 1
|
||||
zend_declare_class_constant_long(gnupg_class_entry, (char*)const_name, strlen(const_name), value TSRMLS_CC);
|
||||
#else
|
||||
zval *constant = malloc(sizeof(*constant));
|
||||
ZVAL_LONG(constant,value);
|
||||
INIT_PZVAL(constant);
|
||||
zend_hash_update(&gnupg_class_entry->constants_table, (char*)const_name, strlen(const_name)+1, &constant, sizeof(zval*), NULL);
|
||||
#endif
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
#endif /* ZEND_ENGINE_2 */
|
||||
|
||||
/* {{{ functionlist gnupg */
|
||||
static zend_function_entry gnupg_functions[] = {
|
||||
PHP_FE(gnupg_init, NULL)
|
||||
PHP_FE(gnupg_keyinfo, NULL)
|
||||
|
@ -226,20 +264,6 @@ static zend_function_entry gnupg_functions[] = {
|
|||
};
|
||||
/* }}} */
|
||||
|
||||
/* {{{ class constants */
|
||||
static void gnupg_declare_long_constant(const char *const_name, long value TSRMLS_DC){
|
||||
#if PHP_MAJOR_VERSION > 5 || PHP_MINOR_VERSION >= 1
|
||||
zend_declare_class_constant_long(gnupg_class_entry, (char*)const_name, strlen(const_name), value TSRMLS_CC);
|
||||
#else
|
||||
zval *constant = malloc(sizeof(*constant));
|
||||
ZVAL_LONG(constant,value);
|
||||
INIT_PZVAL(constant);
|
||||
zend_hash_update(&gnupg_class_entry->constants_table, (char*)const_name, strlen(const_name)+1, &constant, sizeof(zval*), NULL);
|
||||
#endif
|
||||
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ gnupg_module_entry
|
||||
*/
|
||||
zend_module_entry gnupg_module_entry = {
|
||||
|
@ -359,9 +383,10 @@ gpgme_error_t passphrase_cb (gnupg_object *intern, const char *uid_hint, const c
|
|||
char uid[16];
|
||||
int idx;
|
||||
char *passphrase = NULL;
|
||||
zval *return_value = NULL;
|
||||
|
||||
if(last_was_bad){
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Incorrent passphrase");
|
||||
GNUPG_ERR("Incorrent passphrase");
|
||||
return 1;
|
||||
}
|
||||
for(idx=0;idx<16;idx++){
|
||||
|
@ -369,11 +394,11 @@ gpgme_error_t passphrase_cb (gnupg_object *intern, const char *uid_hint, const c
|
|||
}
|
||||
uid[16] = '\0';
|
||||
if(zend_hash_find(intern->signkeys,(char *) uid,17,(void **) &passphrase)==FAILURE){
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "no passphrase set");
|
||||
GNUPG_ERR("no passphrase set");
|
||||
return 1;
|
||||
}
|
||||
if(!passphrase){
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "no passphrase set");
|
||||
GNUPG_ERR("no passphrase set");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -386,9 +411,10 @@ gpgme_error_t passphrase_decrypt_cb (gnupg_object *intern, const char *uid_hint,
|
|||
char uid[16];
|
||||
int idx;
|
||||
char *passphrase = NULL;
|
||||
zval *return_value = NULL;
|
||||
|
||||
if(last_was_bad){
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Incorrent passphrase");
|
||||
GNUPG_ERR("Incorrent passphrase");
|
||||
return 1;
|
||||
}
|
||||
for(idx=0;idx<16;idx++){
|
||||
|
@ -396,11 +422,11 @@ gpgme_error_t passphrase_decrypt_cb (gnupg_object *intern, const char *uid_hint,
|
|||
}
|
||||
uid[16] = '\0';
|
||||
if(zend_hash_find(intern->decryptkeys,(char *) uid,17,(void **) &passphrase)==FAILURE){
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "no passphrase set");
|
||||
GNUPG_ERR("no passphrase set");
|
||||
return 1;
|
||||
}
|
||||
if(!passphrase){
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "no passphrase set");
|
||||
GNUPG_ERR("no passphrase set");
|
||||
return 1;
|
||||
}
|
||||
write (fd, passphrase, strlen(passphrase));
|
||||
|
@ -880,9 +906,12 @@ PHP_FUNCTION(gnupg_sign){
|
|||
return;
|
||||
}
|
||||
if((intern->err = gpgme_op_sign(intern->ctx, in, out, intern->signmode))!=GPG_ERR_NO_ERROR){
|
||||
if(!intern->errortxt){
|
||||
GNUPG_ERR("data signing failed");
|
||||
}
|
||||
gpgme_data_release(in);
|
||||
gpgme_data_release(out);
|
||||
RETVAL_FALSE;
|
||||
return;
|
||||
}
|
||||
result = gpgme_op_sign_result (intern->ctx);
|
||||
|
@ -1015,9 +1044,12 @@ PHP_FUNCTION(gnupg_encryptsign){
|
|||
return;
|
||||
}
|
||||
if((intern->err = gpgme_op_encrypt_sign(intern->ctx, intern->encryptkeys, GPGME_ENCRYPT_ALWAYS_TRUST, in, out))!=GPG_ERR_NO_ERROR){
|
||||
if(!intern->errortxt){
|
||||
GNUPG_ERR("encrypt-sign failed");
|
||||
}
|
||||
gpgme_data_release(in);
|
||||
gpgme_data_release(out);
|
||||
RETVAL_FALSE;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1096,7 +1128,7 @@ PHP_FUNCTION(gnupg_verify){
|
|||
}else{
|
||||
/* no separate signature was passed
|
||||
* so we assume that it is a clearsigned message
|
||||
* text no becomes the signature
|
||||
* text now becomes the signature
|
||||
* creating the text-databuffer is still needed
|
||||
*/
|
||||
if((intern->err = gpgme_data_new_from_mem (&gpgme_sig, text, text_len, 0))!=GPG_ERR_NO_ERROR){
|
||||
|
@ -1169,9 +1201,12 @@ PHP_FUNCTION(gnupg_decrypt){
|
|||
return;
|
||||
}
|
||||
if((intern->err = gpgme_op_decrypt (intern->ctx, in, out))!=GPG_ERR_NO_ERROR){
|
||||
if(!intern->errortxt){
|
||||
GNUPG_ERR("decrypt failed");
|
||||
}
|
||||
gpgme_data_release(in);
|
||||
gpgme_data_release(out);
|
||||
RETVAL_FALSE;
|
||||
return;
|
||||
}
|
||||
result = gpgme_op_decrypt_result (intern->ctx);
|
||||
|
@ -1233,9 +1268,12 @@ PHP_FUNCTION(gnupg_decryptverify){
|
|||
return;
|
||||
}
|
||||
if((intern->err = gpgme_op_decrypt_verify (intern->ctx, in, out))!=GPG_ERR_NO_ERROR){
|
||||
if(!intern->errortxt){
|
||||
GNUPG_ERR("decrypt-verify failed");
|
||||
}
|
||||
gpgme_data_release(in);
|
||||
gpgme_data_release(out);
|
||||
RETVAL_FALSE;
|
||||
return;
|
||||
}
|
||||
userret = gpgme_data_release_and_get_mem(out,&ret_size);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
| modification, are permitted provided that the conditions mentioned |
|
||||
| in the accompanying LICENSE file are met. |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright (c) 2005, Thilo Raufeisen <traufeisen@php.net> |
|
||||
| Copyright (c) 2006, Thilo Raufeisen <traufeisen@php.net> |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
|
|
14
package.xml
14
package.xml
|
@ -14,11 +14,12 @@
|
|||
</maintainer>
|
||||
</maintainers>
|
||||
<release>
|
||||
<version>1.0</version>
|
||||
<date>2005-12-29</date>
|
||||
<version>1.1</version>
|
||||
<date>2006-03-16</date>
|
||||
<license>BSD, revised</license>
|
||||
<state>stable</state>
|
||||
<notes>bump to stable</notes>
|
||||
<notes>improved PHP4 compatibility
|
||||
passphrase-errors now takes care of the errormode</notes>
|
||||
<deps>
|
||||
<dep type="php" rel="ge" version="4.3"/>
|
||||
</deps>
|
||||
|
@ -43,6 +44,13 @@
|
|||
</filelist>
|
||||
</release>
|
||||
<changelog>
|
||||
<release>
|
||||
<version>1.1</version>
|
||||
<date>2006-03-16</date>
|
||||
<state>stable</state>
|
||||
<notes>improved PHP4 compatibility
|
||||
passphrase-errors now takes care of the errormode</notes>
|
||||
</release>
|
||||
<release>
|
||||
<version>1.0</version>
|
||||
<date>2005-12-29</date>
|
||||
|
|
26
package2.xml
26
package2.xml
|
@ -15,18 +15,19 @@ http://pear.php.net/dtd/package-2.0.xsd">
|
|||
<email>traufeisen@php.net</email>
|
||||
<active>yes</active>
|
||||
</lead>
|
||||
<date>2005-12-29</date>
|
||||
<time>20:49:15</time>
|
||||
<date>2006-03-16</date>
|
||||
<time>16:50:53</time>
|
||||
<version>
|
||||
<release>1.0</release>
|
||||
<api>1.0</api>
|
||||
<release>1.1</release>
|
||||
<api>1.1</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>stable</release>
|
||||
<api>stable</api>
|
||||
</stability>
|
||||
<license>BSD, revised</license>
|
||||
<notes>bump to stable
|
||||
<notes>improved PHP4 compatibility
|
||||
passphrase-errors now takes care of the errormode
|
||||
</notes>
|
||||
<contents>
|
||||
<dir name="/">
|
||||
|
@ -64,6 +65,21 @@ http://pear.php.net/dtd/package-2.0.xsd">
|
|||
<providesextension>gnupg</providesextension>
|
||||
<extsrcrelease />
|
||||
<changelog>
|
||||
<release>
|
||||
<version>
|
||||
<release>1.1</release>
|
||||
<api>1.1</api>
|
||||
</version>
|
||||
<stability>
|
||||
<release>stable</release>
|
||||
<api>stable</api>
|
||||
</stability>
|
||||
<date>2006-03-16</date>
|
||||
<license>BSD, revised</license>
|
||||
<notes>improved PHP4 compatibility
|
||||
passphrase-errors now takes care of the errormode
|
||||
</notes>
|
||||
</release>
|
||||
<release>
|
||||
<version>
|
||||
<release>1.0</release>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
| modification, are permitted provided that the conditions mentioned |
|
||||
| in the accompanying LICENSE file are met. |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright (c) 2005, Thilo Raufeisen <traufeisen@php.net> |
|
||||
| Copyright (c) 2006, Thilo Raufeisen <traufeisen@php.net> |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
| modification, are permitted provided that the conditions mentioned |
|
||||
| in the accompanying LICENSE file are met. |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright (c) 2005, Thilo Raufeisen <traufeisen@php.net> |
|
||||
| Copyright (c) 2006, Thilo Raufeisen <traufeisen@php.net> |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
|
|
Loading…
Reference in a new issue