|
23 | 23 | #include <gromox/zcore_client.hpp> |
24 | 24 | #include <gromox/zcore_rpc.hpp> |
25 | 25 | #include "php.h" |
| 26 | +#include "SAPI.h" |
26 | 27 | #include "ext/standard/info.h" |
27 | 28 | #include "Zend/zend_exceptions.h" |
28 | 29 | #include "Zend/zend_builtin_functions.h" |
@@ -753,6 +754,44 @@ static ZEND_FUNCTION(mapi_logon_ex) |
753 | 754 | MAPI_G(hr) = ecSuccess; |
754 | 755 | } |
755 | 756 |
|
| 757 | +static ZEND_FUNCTION(mapi_logon_np) |
| 758 | +{ |
| 759 | + ZCL_MEMORY; |
| 760 | + zend_long flags = 0; |
| 761 | + char *username; |
| 762 | + size_t username_len = 0; |
| 763 | + |
| 764 | + if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl", &username, |
| 765 | + &username_len, &flags) == FAILURE || |
| 766 | + username == nullptr || *username == '\0') |
| 767 | + pthrow(ecInvalidParam); |
| 768 | + |
| 769 | + /* enforce CLI mode */ |
| 770 | + if (sapi_module.name != nullptr) { |
| 771 | + if (strcasecmp(sapi_module.name, "cli") != 0) |
| 772 | + pthrow(ecAccessDenied); |
| 773 | + } else { |
| 774 | + zstrplus str_server(zend_string_init(ZEND_STRL("_SERVER"), 0)); |
| 775 | + auto server_vars = zend_hash_find(&EG(symbol_table), str_server.get()); |
| 776 | + zstrplus str_reqm(zend_string_init(ZEND_STRL("REQUEST_METHOD"), 0)); |
| 777 | + if (server_vars != nullptr && Z_TYPE_P(server_vars) == IS_ARRAY) { |
| 778 | + auto method = zend_hash_find(Z_ARRVAL_P(server_vars), str_reqm.get()); |
| 779 | + if (method != nullptr) |
| 780 | + pthrow(ecAccessDenied); |
| 781 | + } |
| 782 | + } |
| 783 | + auto res = st_malloc<MAPI_RESOURCE>(); |
| 784 | + if (res == nullptr) |
| 785 | + pthrow(ecMAPIOOM); |
| 786 | + auto result = zclient_logon_np(username, "", "", flags, &res->hsession); |
| 787 | + if (result != ecSuccess) |
| 788 | + pthrow(result); |
| 789 | + res->type = zs_objtype::session; |
| 790 | + res->hobject = 0; |
| 791 | + RETVAL_RG(res, le_mapi_session); |
| 792 | + MAPI_G(hr) = ecSuccess; |
| 793 | +} |
| 794 | + |
756 | 795 | static ZEND_FUNCTION(mapi_logon_token) |
757 | 796 | { |
758 | 797 | ZCL_MEMORY; |
@@ -4157,6 +4196,7 @@ static zend_function_entry mapi_functions[] = { |
4157 | 4196 | F(mapi_logon_token) |
4158 | 4197 | F(mapi_logon_zarafa) |
4159 | 4198 | F(mapi_logon_ex) |
| 4199 | + F(mapi_logon_np) |
4160 | 4200 | F(mapi_getmsgstorestable) |
4161 | 4201 | F(mapi_openmsgstore) |
4162 | 4202 | F(mapi_openprofilesection) |
|
0 commit comments