Skip to content

Commit e9dcdb8

Browse files
committed
@- Improved ISAPI module - it should no longer be necessary to set PHP as
@ an ISAPI filter, only as an ISAPI extension, unless you wish to perform @ authentication using PHP. This didn't yet get enough testing, but it @ should work (Zeev) - Fixed auth_user/auth_password memory leak (I didn't have time to test it under Apache, feedback welcome!)
1 parent 1f19c43 commit e9dcdb8

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

main/SAPI.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ SAPI_API void sapi_activate(SLS_D)
178178
SG(request_info).post_data = NULL;
179179
SG(request_info).current_user = NULL;
180180
SG(request_info).current_user_length = 0;
181+
SG(request_info).auth_user = SG(request_info).auth_password = NULL;
181182

182183
if (SG(request_info).request_method && !strcmp(SG(request_info).request_method, "HEAD")) {
183184
SG(request_info).headers_only = 1;
@@ -207,6 +208,12 @@ SAPI_API void sapi_deactivate(SLS_D)
207208
if (SG(request_info).post_data) {
208209
efree(SG(request_info).post_data);
209210
}
211+
if (SG(request_info).auth_user) {
212+
efree(SG(request_info).auth_user);
213+
}
214+
if (SG(request_info).auth_password) {
215+
efree(SG(request_info).auth_password);
216+
}
210217
if (SG(request_info).current_user) {
211218
efree(SG(request_info).current_user);
212219
}

sapi/isapi/php4isapi.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#define ISAPI_SERVER_VAR_BUF_SIZE 1024
3939
#define ISAPI_POST_DATA_BUF 1024
4040

41-
int IWasLoaded=0;
41+
static int isapi_globals_id=-1;
4242

4343
static char *isapi_server_variables[] = {
4444
"ALL_HTTP",
@@ -392,8 +392,15 @@ static sapi_module_struct sapi_module = {
392392
};
393393

394394

395+
typedef struct _php_isapi_globals {
396+
char *auth_user;
397+
char *auth_password;
398+
} php_isapi_globals;
399+
400+
395401
BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION pFilterVersion)
396402
{
403+
isapi_globals_id = ts_allocate_id(sizeof(php_isapi_globals), NULL, NULL);
397404
pFilterVersion->dwFilterVersion = HTTP_FILTER_REVISION;
398405
strcpy(pFilterVersion->lpszFilterDesc, sapi_module.name);
399406
pFilterVersion->dwFlags= (SF_NOTIFY_AUTHENTICATION | SF_NOTIFY_PREPROC_HEADERS);
@@ -403,22 +410,22 @@ BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION pFilterVersion)
403410

404411
DWORD WINAPI HttpFilterProc(PHTTP_FILTER_CONTEXT pfc, DWORD notificationType, LPVOID pvNotification)
405412
{
406-
SLS_FETCH();
413+
php_isapi_globals *isapi_globals = ts_resource(isapi_globals_id);
407414

408415
switch (notificationType) {
409416
case SF_NOTIFY_PREPROC_HEADERS:
410-
SG(request_info).auth_user = NULL;
411-
SG(request_info).auth_password = NULL;
417+
isapi_globals->auth_user = NULL;
418+
isapi_globals->auth_password = NULL;
412419
break;
413420
case SF_NOTIFY_AUTHENTICATION: {
414421
char *auth_user = ((HTTP_FILTER_AUTHENT *) pvNotification)->pszUser;
415422
char *auth_password = ((HTTP_FILTER_AUTHENT *) pvNotification)->pszPassword;
416423

417424
if (auth_user && auth_user[0]) {
418-
SG(request_info).auth_user = estrdup(auth_user);
425+
isapi_globals->auth_user = estrdup(auth_user);
419426
}
420427
if (auth_password && auth_password[0]) {
421-
SG(request_info).auth_password = estrdup(auth_password);
428+
isapi_globals->auth_password = estrdup(auth_password);
422429
}
423430
auth_user[0] = 0;
424431
auth_password[0] = 0;
@@ -447,6 +454,12 @@ static void init_request_info(sapi_globals_struct *sapi_globals, LPEXTENSION_CON
447454
*path_end = '\\';
448455
}
449456
}
457+
if (isapi_globals_id!=-1) { /* we have valid ISAPI Filter information */
458+
php_isapi_globals *isapi_globals = ts_resource(isapi_globals_id);
459+
460+
SG(request_info).auth_user = isapi_globals->auth_user;
461+
SG(request_info).auth_password = isapi_globals->auth_password;
462+
}
450463
}
451464

452465

@@ -564,7 +577,6 @@ __declspec(dllexport) BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, L
564577
if (sapi_module.startup) {
565578
sapi_module.startup(&sapi_module);
566579
}
567-
IWasLoaded = 1;
568580
break;
569581
case DLL_THREAD_ATTACH:
570582
break;

sapi/servlet/servlet.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,6 @@ JNIEXPORT void JNICALL Java_net_php_servlet_send
387387
FREESTRING(SG(request_info).request_uri);
388388
FREESTRING(SG(request_info).path_translated);
389389
FREESTRING(SG(request_info).content_type);
390-
FREESTRING(SG(request_info).auth_user);
391390
FREESTRING(((servlet_request*)SG(server_context))->cookies);
392391
efree(SG(server_context));
393392
SG(server_context)=0;

0 commit comments

Comments
 (0)