improved PHP4 compatibility and config.m4

passphrase-errors now takes care of the actual errormode
This commit is contained in:
Thilo Raufeisen 2006-03-16 15:52:43 +00:00
parent 7852127f8d
commit f3a9027773
7 changed files with 112 additions and 50 deletions

View file

@ -2,7 +2,7 @@ dnl $Id$
dnl config.m4 for extension gnupg dnl config.m4 for extension gnupg
PHP_ARG_WITH(gnupg, for gnupg support, 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 if test "$PHP_GNUPG" != "no"; then
SEARCH_PATH="/usr/local/include /usr/include /usr/local/include/gpgme/ /usr/include/gpgme/" SEARCH_PATH="/usr/local/include /usr/include /usr/local/include/gpgme/ /usr/include/gpgme/"

86
gnupg.c
View file

@ -6,7 +6,7 @@
| modification, are permitted provided that the conditions mentioned | | modification, are permitted provided that the conditions mentioned |
| in the accompanying LICENSE file are met. | | 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; static int le_gnupg;
#define PHP_GNUPG_VERSION "0.7beta" #define PHP_GNUPG_VERSION "1.1"
#ifdef ZEND_ENGINE_2 #ifdef ZEND_ENGINE_2
static zend_object_handlers gnupg_object_handlers; static zend_object_handlers gnupg_object_handlers;
#endif #endif
/* {{{ defs */ /* {{{ defs */
#ifdef ZEND_ENGINE_2
#define GNUPG_GETOBJ() \ #define GNUPG_GETOBJ() \
zval *this = getThis(); \ zval *this = getThis(); \
gnupg_object *intern; \ gnupg_object *intern; \
@ -61,7 +63,26 @@ static zend_object_handlers gnupg_object_handlers;
}else{ \ }else{ \
php_error_docref(NULL TSRMLS_CC, E_WARNING, (char*)error); \ 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 */ /* {{{ free encryptkeys */
@ -196,7 +217,24 @@ static zend_function_entry gnupg_methods[] = {
ZEND_ME(gnupg, seterrormode, NULL, ZEND_ACC_PUBLIC) ZEND_ME(gnupg, seterrormode, NULL, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL} {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 */ #endif /* ZEND_ENGINE_2 */
/* {{{ functionlist gnupg */
static zend_function_entry gnupg_functions[] = { static zend_function_entry gnupg_functions[] = {
PHP_FE(gnupg_init, NULL) PHP_FE(gnupg_init, NULL)
PHP_FE(gnupg_keyinfo, 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 /* {{{ gnupg_module_entry
*/ */
zend_module_entry 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]; char uid[16];
int idx; int idx;
char *passphrase = NULL; char *passphrase = NULL;
zval *return_value = NULL;
if(last_was_bad){ if(last_was_bad){
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Incorrent passphrase"); GNUPG_ERR("Incorrent passphrase");
return 1; return 1;
} }
for(idx=0;idx<16;idx++){ 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'; uid[16] = '\0';
if(zend_hash_find(intern->signkeys,(char *) uid,17,(void **) &passphrase)==FAILURE){ 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; return 1;
} }
if(!passphrase){ if(!passphrase){
php_error_docref(NULL TSRMLS_CC, E_WARNING, "no passphrase set"); GNUPG_ERR("no passphrase set");
return 1; return 1;
} }
@ -386,9 +411,10 @@ gpgme_error_t passphrase_decrypt_cb (gnupg_object *intern, const char *uid_hint,
char uid[16]; char uid[16];
int idx; int idx;
char *passphrase = NULL; char *passphrase = NULL;
zval *return_value = NULL;
if(last_was_bad){ if(last_was_bad){
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Incorrent passphrase"); GNUPG_ERR("Incorrent passphrase");
return 1; return 1;
} }
for(idx=0;idx<16;idx++){ 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'; uid[16] = '\0';
if(zend_hash_find(intern->decryptkeys,(char *) uid,17,(void **) &passphrase)==FAILURE){ 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; return 1;
} }
if(!passphrase){ if(!passphrase){
php_error_docref(NULL TSRMLS_CC, E_WARNING, "no passphrase set"); GNUPG_ERR("no passphrase set");
return 1; return 1;
} }
write (fd, passphrase, strlen(passphrase)); write (fd, passphrase, strlen(passphrase));
@ -880,9 +906,12 @@ PHP_FUNCTION(gnupg_sign){
return; return;
} }
if((intern->err = gpgme_op_sign(intern->ctx, in, out, intern->signmode))!=GPG_ERR_NO_ERROR){ if((intern->err = gpgme_op_sign(intern->ctx, in, out, intern->signmode))!=GPG_ERR_NO_ERROR){
if(!intern->errortxt){
GNUPG_ERR("data signing failed"); GNUPG_ERR("data signing failed");
}
gpgme_data_release(in); gpgme_data_release(in);
gpgme_data_release(out); gpgme_data_release(out);
RETVAL_FALSE;
return; return;
} }
result = gpgme_op_sign_result (intern->ctx); result = gpgme_op_sign_result (intern->ctx);
@ -1015,9 +1044,12 @@ PHP_FUNCTION(gnupg_encryptsign){
return; return;
} }
if((intern->err = gpgme_op_encrypt_sign(intern->ctx, intern->encryptkeys, GPGME_ENCRYPT_ALWAYS_TRUST, in, out))!=GPG_ERR_NO_ERROR){ 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"); GNUPG_ERR("encrypt-sign failed");
}
gpgme_data_release(in); gpgme_data_release(in);
gpgme_data_release(out); gpgme_data_release(out);
RETVAL_FALSE;
return; return;
} }
@ -1096,7 +1128,7 @@ PHP_FUNCTION(gnupg_verify){
}else{ }else{
/* no separate signature was passed /* no separate signature was passed
* so we assume that it is a clearsigned message * 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 * 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){ 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; return;
} }
if((intern->err = gpgme_op_decrypt (intern->ctx, in, out))!=GPG_ERR_NO_ERROR){ if((intern->err = gpgme_op_decrypt (intern->ctx, in, out))!=GPG_ERR_NO_ERROR){
if(!intern->errortxt){
GNUPG_ERR("decrypt failed"); GNUPG_ERR("decrypt failed");
}
gpgme_data_release(in); gpgme_data_release(in);
gpgme_data_release(out); gpgme_data_release(out);
RETVAL_FALSE;
return; return;
} }
result = gpgme_op_decrypt_result (intern->ctx); result = gpgme_op_decrypt_result (intern->ctx);
@ -1233,9 +1268,12 @@ PHP_FUNCTION(gnupg_decryptverify){
return; return;
} }
if((intern->err = gpgme_op_decrypt_verify (intern->ctx, in, out))!=GPG_ERR_NO_ERROR){ if((intern->err = gpgme_op_decrypt_verify (intern->ctx, in, out))!=GPG_ERR_NO_ERROR){
if(!intern->errortxt){
GNUPG_ERR("decrypt-verify failed"); GNUPG_ERR("decrypt-verify failed");
}
gpgme_data_release(in); gpgme_data_release(in);
gpgme_data_release(out); gpgme_data_release(out);
RETVAL_FALSE;
return; return;
} }
userret = gpgme_data_release_and_get_mem(out,&ret_size); userret = gpgme_data_release_and_get_mem(out,&ret_size);

View file

@ -6,7 +6,7 @@
| modification, are permitted provided that the conditions mentioned | | modification, are permitted provided that the conditions mentioned |
| in the accompanying LICENSE file are met. | | in the accompanying LICENSE file are met. |
+--------------------------------------------------------------------+ +--------------------------------------------------------------------+
| Copyright (c) 2005, Thilo Raufeisen <traufeisen@php.net> | | Copyright (c) 2006, Thilo Raufeisen <traufeisen@php.net> |
+--------------------------------------------------------------------+ +--------------------------------------------------------------------+
*/ */

View file

@ -14,11 +14,12 @@
</maintainer> </maintainer>
</maintainers> </maintainers>
<release> <release>
<version>1.0</version> <version>1.1</version>
<date>2005-12-29</date> <date>2006-03-16</date>
<license>BSD, revised</license> <license>BSD, revised</license>
<state>stable</state> <state>stable</state>
<notes>bump to stable</notes> <notes>improved PHP4 compatibility
passphrase-errors now takes care of the errormode</notes>
<deps> <deps>
<dep type="php" rel="ge" version="4.3"/> <dep type="php" rel="ge" version="4.3"/>
</deps> </deps>
@ -43,6 +44,13 @@
</filelist> </filelist>
</release> </release>
<changelog> <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> <release>
<version>1.0</version> <version>1.0</version>
<date>2005-12-29</date> <date>2005-12-29</date>

View file

@ -15,18 +15,19 @@ http://pear.php.net/dtd/package-2.0.xsd">
<email>traufeisen@php.net</email> <email>traufeisen@php.net</email>
<active>yes</active> <active>yes</active>
</lead> </lead>
<date>2005-12-29</date> <date>2006-03-16</date>
<time>20:49:15</time> <time>16:50:53</time>
<version> <version>
<release>1.0</release> <release>1.1</release>
<api>1.0</api> <api>1.1</api>
</version> </version>
<stability> <stability>
<release>stable</release> <release>stable</release>
<api>stable</api> <api>stable</api>
</stability> </stability>
<license>BSD, revised</license> <license>BSD, revised</license>
<notes>bump to stable <notes>improved PHP4 compatibility
passphrase-errors now takes care of the errormode
</notes> </notes>
<contents> <contents>
<dir name="/"> <dir name="/">
@ -64,6 +65,21 @@ http://pear.php.net/dtd/package-2.0.xsd">
<providesextension>gnupg</providesextension> <providesextension>gnupg</providesextension>
<extsrcrelease /> <extsrcrelease />
<changelog> <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> <release>
<version> <version>
<release>1.0</release> <release>1.0</release>

View file

@ -6,7 +6,7 @@
| modification, are permitted provided that the conditions mentioned | | modification, are permitted provided that the conditions mentioned |
| in the accompanying LICENSE file are met. | | in the accompanying LICENSE file are met. |
+--------------------------------------------------------------------+ +--------------------------------------------------------------------+
| Copyright (c) 2005, Thilo Raufeisen <traufeisen@php.net> | | Copyright (c) 2006, Thilo Raufeisen <traufeisen@php.net> |
+--------------------------------------------------------------------+ +--------------------------------------------------------------------+
*/ */

View file

@ -6,7 +6,7 @@
| modification, are permitted provided that the conditions mentioned | | modification, are permitted provided that the conditions mentioned |
| in the accompanying LICENSE file are met. | | in the accompanying LICENSE file are met. |
+--------------------------------------------------------------------+ +--------------------------------------------------------------------+
| Copyright (c) 2005, Thilo Raufeisen <traufeisen@php.net> | | Copyright (c) 2006, Thilo Raufeisen <traufeisen@php.net> |
+--------------------------------------------------------------------+ +--------------------------------------------------------------------+
*/ */