summaryrefslogtreecommitdiff
blob: ce5f36f11738516e58f7dad39ead0ab3bce3b5d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
diff -aurN a/crack.c b/crack.c
--- a/crack.c	2021-04-15 13:57:12.174874906 -0400
+++ b/crack.c	2021-04-15 14:10:21.203314001 -0400
@@ -68,9 +68,7 @@
 /* {{{ crack_module_entry
  */
 zend_module_entry crack_module_entry = {
-#if ZEND_MODULE_API_NO >= 20010901
     STANDARD_MODULE_HEADER,
-#endif
 	"crack",
 	crack_functions,
 	PHP_MINIT(crack),
@@ -78,9 +76,7 @@
 	PHP_RINIT(crack),
 	PHP_RSHUTDOWN(crack),
 	PHP_MINFO(crack),
-#if ZEND_MODULE_API_NO >= 20010901
-	"0.3",
-#endif
+	"0.4",
 	STANDARD_MODULE_PROPERTIES,
 };
 /* }}} */
@@ -102,57 +98,19 @@
 static void php_crack_init_globals(zend_crack_globals *crack_globals)
 {
 	crack_globals->last_message = NULL;
-#if PHP_VERSION_ID >= 70000
 	crack_globals->default_dict = NULL;
-#else
-	crack_globals->default_dict = -1;
-#endif
 }
 /* }}} */
 
 /* {{{ php_crack_checkpath
  */
-static int php_crack_checkpath(char* path TSRMLS_DC)
+static int php_crack_checkpath(char* path)
 {
 	char *filename;
 	int filename_len;
 	int result = SUCCESS;
 
-#if PHP_VERSION_ID < 50400
-	if (PG(safe_mode)) {
-		filename_len = strlen(path) + 10;
-		filename = (char *) emalloc(filename_len);
-		if (NULL == filename) {
-			return FAILURE;
-		}
-
-		memset(filename, '\0', filename_len);
-		strcpy(filename, path);
-		strcat(filename, ".pwd");
-		if (!php_checkuid(filename, "r", CHECKUID_CHECK_FILE_AND_DIR)) {
-			efree(filename);
-			return FAILURE;
-		}
-
-		memset(filename, '\0', filename_len);
-		strcpy(filename, path);
-		strcat(filename, ".pwi");
-		if (!php_checkuid(filename, "r", CHECKUID_CHECK_FILE_AND_DIR)) {
-			efree(filename);
-			return FAILURE;
-		}
-
-		memset(filename, '\0', filename_len);
-		strcpy(filename, path);
-		strcat(filename, ".hwm");
-		if (!php_checkuid(filename, "r", CHECKUID_CHECK_FILE_AND_DIR)) {
-			efree(filename);
-			return FAILURE;
-		}
-	}
-#endif
-
-	if (php_check_open_basedir(path TSRMLS_CC)) {
+	if (php_check_open_basedir(path)) {
 		return FAILURE;
 	}
 
@@ -162,7 +120,6 @@
 
 /* {{{ php_crack_set_default_dict
  */
-#if PHP_VERSION_ID >= 70000
 static void php_crack_set_default_dict(zend_resource *id)
 {
 	if (CRACKG(default_dict) != NULL) {
@@ -172,60 +129,32 @@
 	CRACKG(default_dict) = id;
 	id->gc.refcount++;
 }
-#else
-static void php_crack_set_default_dict(int id TSRMLS_DC)
-{
-	if (CRACKG(default_dict) != -1) {
-		zend_list_delete(CRACKG(default_dict));
-	}
-
-	CRACKG(default_dict) = id;
-	zend_list_addref(id);
-}
-#endif
 /* }}} */
 
 /* {{{ php_crack_get_default_dict
  */
-#if PHP_VERSION_ID >= 70000
 static zend_resource * php_crack_get_default_dict(INTERNAL_FUNCTION_PARAMETERS)
-#else
-static int php_crack_get_default_dict(INTERNAL_FUNCTION_PARAMETERS)
-#endif
 {
-#if PHP_VERSION_ID >= 70000
 	if ((NULL == CRACKG(default_dict)) && (NULL != CRACKG(default_dictionary))) {
-#else
-	if ((-1 == CRACKG(default_dict)) && (NULL != CRACKG(default_dictionary))) {
-#endif
 		CRACKLIB_PWDICT *pwdict;
 		printf("trying to open: %s\n", CRACKG(default_dictionary));
 		pwdict = cracklib_pw_open(CRACKG(default_dictionary), "r");
 		if (NULL != pwdict) {
-#if PHP_VERSION_ID >= 70000
 			ZVAL_RES(return_value, zend_register_resource(pwdict, le_crack));
 			php_crack_set_default_dict(Z_RES_P(return_value));
-#else
-			ZEND_REGISTER_RESOURCE(return_value, pwdict, le_crack);
-			php_crack_set_default_dict(Z_LVAL_P(return_value) TSRMLS_CC);
-#endif
 		}
 	}
-	
+
 	return CRACKG(default_dict);
 }
 /* }}} */
 
 /* {{{ php_crack_module_dtor
  */
-#if PHP_VERSION_ID >= 70000
 static void php_crack_module_dtor(zend_resource *rsrc)
-#else
-static void php_crack_module_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
-#endif
 {
 	CRACKLIB_PWDICT *pwdict = (CRACKLIB_PWDICT *) rsrc->ptr;
-	
+
 	if (pwdict != NULL) {
 		cracklib_pw_close(pwdict);
 	}
@@ -239,13 +168,10 @@
 #ifdef ZTS
 	ZEND_INIT_MODULE_GLOBALS(crack, php_crack_init_globals, NULL);
 #endif
-	
+
 	REGISTER_INI_ENTRIES();
 	le_crack = zend_register_list_destructors_ex(php_crack_module_dtor, NULL, "crack dictionary", module_number);
-#if PHP_VERSION_ID < 70000
-	Z_TYPE(crack_module_entry) = type;
-#endif
-	
+
 	return SUCCESS;
 }
 
@@ -263,12 +189,8 @@
 PHP_RINIT_FUNCTION(crack)
 {
 	CRACKG(last_message) = NULL;
-#if PHP_VERSION_ID >= 70000
 	CRACKG(default_dict) = NULL;
-#else
-	CRACKG(default_dict) = -1;
-#endif
-	
+
 	return SUCCESS;
 }
 /* }}} */
@@ -280,7 +202,7 @@
 	if (NULL != CRACKG(last_message)) {
 		efree(CRACKG(last_message));
 	}
-	
+
 	return SUCCESS;
 }
 /* }}} */
@@ -292,7 +214,7 @@
 	php_info_print_table_start();
 	php_info_print_table_header(2, "crack support", "enabled");
 	php_info_print_table_end();
-	
+
 	DISPLAY_INI_ENTRIES();
 }
 /* }}} */
@@ -304,32 +226,23 @@
 	char *path;
 	size_t path_len;
 	CRACKLIB_PWDICT *pwdict;
-	
-	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &path, &path_len) == FAILURE) {
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &path, &path_len) == FAILURE) {
 		RETURN_FALSE;
 	}
-	
-	if (php_crack_checkpath(path TSRMLS_CC) == FAILURE) {
+
+	if (php_crack_checkpath(path) == FAILURE) {
 		RETURN_FALSE;
 	}
-	
+
 	pwdict = cracklib_pw_open(path, "r");
 	if (NULL == pwdict) {
-#if ZEND_MODULE_API_NO >= 20021010
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not open crack dictionary: %s", path);
-#else
-		php_error(E_WARNING, "Could not open crack dictionary: %s", path);
-#endif
+		php_error_docref(NULL, E_WARNING, "Could not open crack dictionary: %s", path);
 		RETURN_FALSE;
 	}
 
-#if PHP_VERSION_ID >= 70000
 	RETURN_RES(zend_register_resource(pwdict, le_crack));
 	php_crack_set_default_dict(Z_RES_P(return_value));
-#else
-	ZEND_REGISTER_RESOURCE(return_value, pwdict, le_crack);
-	php_crack_set_default_dict(Z_LVAL_P(return_value) TSRMLS_CC);
-#endif
 }
 /* }}} */
 
@@ -338,33 +251,20 @@
 PHP_FUNCTION(crack_closedict)
 {
 	zval *dictionary = NULL;
-#if PHP_VERSION_ID >= 70000
 	zend_resource *id;
-#else
-	int id = -1;
-#endif
 	CRACKLIB_PWDICT *pwdict;
-	
-	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &dictionary)) {
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &dictionary)) {
 		RETURN_FALSE;
 	}
-	
+
 	if (NULL == dictionary) {
 		id = php_crack_get_default_dict(INTERNAL_FUNCTION_PARAM_PASSTHRU);
-#if PHP_VERSION_ID >= 70000
 		if (id == NULL) {
-#else
-		if (id == -1) {
-#endif
-#if ZEND_MODULE_API_NO >= 20021010
-			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not open default crack dicionary"); 
-#else
-			php_error(E_WARNING, "Could not open default crack dicionary"); 
-#endif
+			php_error_docref(NULL, E_WARNING, "Could not open default crack dicionary"); 
 			RETURN_FALSE;
 		}
 	}
-#if PHP_VERSION_ID >= 70000
 	if((pwdict = (CRACKLIB_PWDICT *)zend_fetch_resource(Z_RES_P(dictionary), "crack dictionary", le_crack)) == NULL)
 	{
 		RETURN_FALSE;
@@ -376,17 +276,6 @@
 	else {
 		zend_list_close(Z_RES_P(dictionary));
 	}
-#else
-	ZEND_FETCH_RESOURCE(pwdict, CRACKLIB_PWDICT *, &dictionary, id, "crack dictionary", le_crack);
-
-	if (NULL == dictionary) {
-		zend_list_delete(CRACKG(default_dict));
-		CRACKG(default_dict) = -1;
-	}
-	else {
-		zend_list_delete(Z_RESVAL_P(dictionary));
-	}
-#endif
 	RETURN_TRUE;
 }
 /* }}} */
@@ -404,25 +293,20 @@
 	size_t gecos_len;
 	char *message;
 	CRACKLIB_PWDICT *pwdict;
-#if PHP_VERSION_ID >= 70000
 	zend_resource *crack_res;
-#else
-	int id = -1;
-#endif
-	
+
 	if (NULL != CRACKG(last_message)) {
 		efree(CRACKG(last_message));
 		CRACKG(last_message) = NULL;
 	}
-	
-	if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "rs", &dictionary, &password, &password_len) == FAILURE) {
-		if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ssr", &password, &password_len, &username, &username_len, &gecos, &gecos_len, &dictionary) == FAILURE) {
+
+	if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "rs", &dictionary, &password, &password_len) == FAILURE) {
+		if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|ssr", &password, &password_len, &username, &username_len, &gecos, &gecos_len, &dictionary) == FAILURE) {
 			RETURN_FALSE;
 		}
 	}
-	
+
 	if (NULL == dictionary) {
-#if PHP_VERSION_ID >= 70000
 		crack_res = php_crack_get_default_dict(INTERNAL_FUNCTION_PARAM_PASSTHRU);
 		if (crack_res == NULL || crack_res->ptr == NULL) {
 			php_error(E_WARNING, "Could not open default crack dicionary");
@@ -436,22 +320,9 @@
 			RETURN_FALSE;
 		}
 	}
-#else
-		id = php_crack_get_default_dict(INTERNAL_FUNCTION_PARAM_PASSTHRU);
-		if (id == -1) {
-#if ZEND_MODULE_API_NO >= 20021010
-			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not open default crack dicionary"); 
-#else
-			php_error(E_WARNING, "Could not open default crack dicionary"); 
-#endif
-			RETURN_FALSE;
-		}
-	}
-	ZEND_FETCH_RESOURCE(pwdict, CRACKLIB_PWDICT *, &dictionary, id, "crack dictionary", le_crack);
-#endif
-	
+
 	message = cracklib_fascist_look_ex(pwdict, password, username, gecos);
-	
+
 	if (NULL == message) {
 		CRACKG(last_message) = estrdup("strong password");
 		RETURN_TRUE;
@@ -470,21 +341,13 @@
 	if (ZEND_NUM_ARGS() != 0) {
 		WRONG_PARAM_COUNT;
 	}
-	
+
 	if (NULL == CRACKG(last_message)) {
-#if ZEND_MODULE_API_NO >= 20021010
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "No obscure checks in this session");
-#else
-		php_error(E_WARNING, "No obscure checks in this session");
-#endif
+		php_error_docref(NULL, E_WARNING, "No obscure checks in this session");
 		RETURN_FALSE;
 	}
-	
-#if PHP_VERSION_ID >= 70000
+
 	RETURN_STRING(CRACKG(last_message));
-#else
-	RETURN_STRING(CRACKG(last_message), 1);
-#endif
 }
 /* }}} */
 
diff -aurN a/php_crack.h b/php_crack.h
--- a/php_crack.h	2021-04-15 13:57:12.174874906 -0400
+++ b/php_crack.h	2021-04-15 14:10:28.853298881 -0400
@@ -52,11 +52,7 @@
 ZEND_BEGIN_MODULE_GLOBALS(crack)
     char *default_dictionary;
 	char *last_message;
-#if PHP_VERSION_ID >= 70000
 	zend_resource *default_dict;
-#else
-	int default_dict;
-#endif
 ZEND_END_MODULE_GLOBALS(crack)
 
 #ifdef ZTS