Skip to content

Commit 18d961b

Browse files
committed
php_mapi: add mapi_logon_np PHP function
Restore ability to use ZRPC without proper credentials, just for submit.php. It's still a crappy design to rely on zcore. References: GXL-487, GXH-129, DESK-1731, DESK-2542, DESK-3393, DESK-3799
1 parent 23a952f commit 18d961b

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
lines changed

php_mapi/mapi.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <gromox/zcore_client.hpp>
2424
#include <gromox/zcore_rpc.hpp>
2525
#include "php.h"
26+
#include "SAPI.h"
2627
#include "ext/standard/info.h"
2728
#include "Zend/zend_exceptions.h"
2829
#include "Zend/zend_builtin_functions.h"
@@ -753,6 +754,44 @@ static ZEND_FUNCTION(mapi_logon_ex)
753754
MAPI_G(hr) = ecSuccess;
754755
}
755756

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+
756795
static ZEND_FUNCTION(mapi_logon_token)
757796
{
758797
ZCL_MEMORY;
@@ -4157,6 +4196,7 @@ static zend_function_entry mapi_functions[] = {
41574196
F(mapi_logon_token)
41584197
F(mapi_logon_zarafa)
41594198
F(mapi_logon_ex)
4199+
F(mapi_logon_np)
41604200
F(mapi_getmsgstorestable)
41614201
F(mapi_openmsgstore)
41624202
F(mapi_openprofilesection)

php_mapi/mapi.stub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function mapi_createoneoff(?string $displayname, string $type, string $address,
1010
function mapi_parseoneoff(string $entryid) : array|bool {}
1111
function mapi_logon_zarafa(string $username, string $password, ?string $server = null, ?string $sslcert = null, ?string $sslpass = null, ?int $flags = 0, ?string $wa_version = null, ?string $misc_version = null) : resource|bool {}
1212
function mapi_logon_ex(string $username, string $password, int $flags) : resource|bool {}
13+
function mapi_logon_np(string $username, int $flags) : resource|bool {}
1314
function mapi_logon_token(string $token) : resource|bool {}
1415
function mapi_getmsgstorestable(resource $session) : resource|bool {}
1516
function mapi_openmsgstore(resource $ses, string $entryid) : resource|bool {}

php_mapi/mapi_arginfo.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 871b0416d0d4e8a11806aab29816729eb43e5d6b */
2+
* Stub hash: 8185b8356317dda89e8676a5b9e87d3392d23d49 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mapi_load_mapidefs, 0, 1, IS_VOID, 0)
55
ZEND_ARG_TYPE_INFO(0, level, IS_LONG, 1)
@@ -56,6 +56,11 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_mapi_logon_ex, 0, 3, resourc
5656
ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0)
5757
ZEND_END_ARG_INFO()
5858

59+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_mapi_logon_np, 0, 2, resource, MAY_BE_BOOL)
60+
ZEND_ARG_TYPE_INFO(0, username, IS_STRING, 0)
61+
ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0)
62+
ZEND_END_ARG_INFO()
63+
5964
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_mapi_logon_token, 0, 1, resource, MAY_BE_BOOL)
6065
ZEND_ARG_TYPE_INFO(0, token, IS_STRING, 0)
6166
ZEND_END_ARG_INFO()
@@ -621,3 +626,4 @@ ZEND_END_ARG_INFO()
621626
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mapi_strerror, 0, 1, IS_STRING, 0)
622627
ZEND_ARG_TYPE_INFO(0, code, IS_LONG, 0)
623628
ZEND_END_ARG_INFO()
629+

php_mapi/rpc_ext.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,7 @@ pack_result rpc_ext_push_request(const zcreq *prequest, BINARY *pbin_out)
12241224
E(logon_token)
12251225
E(getuserfreebusy)
12261226
E(getuserfreebusyical)
1227+
E(logon_np)
12271228
#undef E
12281229
default:
12291230
return pack_result::bad_switch;
@@ -1338,6 +1339,7 @@ pack_result rpc_ext_pull_response(const BINARY *pbin_in, zcresp *presponse)
13381339
E(logon_token)
13391340
E(getuserfreebusy)
13401341
E(getuserfreebusyical)
1342+
E(logon_np)
13411343
#undef E
13421344
default:
13431345
return pack_result::bad_switch;

tools/submit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
$loc_string .= hex2bin('00');
2121
$_SERVER['REMOTE_USER'] = $argv[1];
2222
try {
23-
$session = mapi_logon_ex($argv[1], null, 0);
23+
$session = mapi_logon_np($argv[1], 0);
2424
} catch (Exception $e) {
2525
die("fail to log on the " . $argv[1] . "'s store");
2626
}

0 commit comments

Comments
 (0)