Project

General

Profile

« Previous | Next » 

Revision ddd54e83

Added by Pi Ba about 8 years ago

auth_check, move the cmp_page_matches() to its own file so it can be shared by both auth_check.inc and priv.inc

View differences:

src/etc/inc/auth_check.inc
18 18
 * See the License for the specific language governing permissions and
19 19
 * limitations under the License.
20 20
 */
21
/*
22
 * Light weight authentication check thats ment as a substitute for guiconfig.inc
23
 * in cases where frequent automatic requests are made like graphs and widget pages.
24
 */
21 25

  
22
// this function is a duplicate from cmp_page_matches() in priv.inc
23
// however unconditionally including priv.inc takes significant more time/cpu
24
function cmp_page_matches2($page, & $matches, $fullwc = true) {
25

  
26
//	$dbg_matches = implode(",", $matches);
27
//	log_error("debug: checking page {$page} match with {$dbg_matches}");
28

  
29
	if (!is_array($matches)) {
30
		return false;
31
	}
32

  
33
	/* skip any leading fwdslash */
34
	$test = strpos($page, "/");
35
	if ($test !== false && $test == 0) {
36
		$page = substr($page, 1);
37
	}
38

  
39
	/* look for a match */
40
	foreach ($matches as $match) {
41

  
42
		/* possibly ignore full wildcard match */
43
		if (!$fullwc && !strcmp($match , "*")) {
44
			continue;
45
		}
46

  
47
		/* compare exact or wildcard match */
48
		$match = str_replace(array(".", "*", "?"), array("\.", ".*", "\?"), $match);
49
		$result = preg_match("@^/{$match}$@", "/{$page}");
50

  
51
		if ($result) {
52
			return true;
53
		}
54
	}
55

  
56
	return false;
57
}
26
require_once("auth_func.inc");
58 27

  
59 28
function session_read_single_var($varname) {
60 29
	$session_started = false;
......
73 42
$session_pagematch = session_read_single_var("page-match");
74 43

  
75 44
$pageuri = $_SERVER['REQUEST_URI'];
76
if (cmp_page_matches2($pageuri, $session_pagematch)) {	
45
if (cmp_page_matches($pageuri, $session_pagematch)) {	
77 46
	return; // auth OK
78 47
}
79 48
require_once("authgui.inc");
src/etc/inc/auth_func.inc
1
<?php
2
/*
3
 * auth_func.inc
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7
 * Copyright (c) 2005-2006 Bill Marquette <bill.marquette@gmail.com>
8
 * Copyright (c) 2006 Paul Taylor <paultaylor@winn-dixie.com>.
9
 * Copyright (c) 2008 Shrew Soft Inc
10
 * Copyright (c) 2003-2006 Manuel Kasper <mk@neon1.net>.
11
 * All rights reserved.
12
 *
13
 * Licensed under the Apache License, Version 2.0 (the "License");
14
 * you may not use this file except in compliance with the License.
15
 * You may obtain a copy of the License at
16
 *
17
 * http://www.apache.org/licenses/LICENSE-2.0
18
 *
19
 * Unless required by applicable law or agreed to in writing, software
20
 * distributed under the License is distributed on an "AS IS" BASIS,
21
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
 * See the License for the specific language governing permissions and
23
 * limitations under the License.
24
 */
25

  
26
/*
27
 * Function put in seperate file to avoid processing priv.inc which is cpu intensive
28
 * cmp_page_matches is used by both auth_check.inc and priv.inc which is used by guiconfig.inc
29
 */
30

  
31
function cmp_page_matches($page, & $matches, $fullwc = true) {
32

  
33
//	$dbg_matches = implode(",", $matches);
34
//	log_error("debug: checking page {$page} match with {$dbg_matches}");
35

  
36
	if (!is_array($matches)) {
37
		return false;
38
	}
39

  
40
	/* skip any leading fwdslash */
41
	$test = strpos($page, "/");
42
	if ($test !== false && $test == 0) {
43
		$page = substr($page, 1);
44
	}
45

  
46
	/* look for a match */
47
	foreach ($matches as $match) {
48

  
49
		/* possibly ignore full wildcard match */
50
		if (!$fullwc && !strcmp($match , "*")) {
51
			continue;
52
		}
53

  
54
		/* compare exact or wildcard match */
55
		$match = str_replace(array(".", "*", "?"), array("\.", ".*", "\?"), $match);
56
		$result = preg_match("@^/{$match}$@", "/{$page}");
57

  
58
		if ($result) {
59
			return true;
60
		}
61
	}
62

  
63
	return false;
64
}
src/etc/inc/priv.inc
24 24
 */
25 25

  
26 26
require_once("priv.defs.inc");
27
require_once("auth_func.inc");
27 28

  
28 29
/* Load and process custom privs. */
29 30
function get_priv_files($directory) {
......
89 90
	uksort($privs, "cmp_privkeys");
90 91
}
91 92

  
92
function cmp_page_matches($page, & $matches, $fullwc = true) {
93

  
94
//	$dbg_matches = implode(",", $matches);
95
//	log_error("debug: checking page {$page} match with {$dbg_matches}");
96

  
97
	if (!is_array($matches)) {
98
		return false;
99
	}
100

  
101
	/* skip any leading fwdslash */
102
	$test = strpos($page, "/");
103
	if ($test !== false && $test == 0) {
104
		$page = substr($page, 1);
105
	}
106

  
107
	/* look for a match */
108
	foreach ($matches as $match) {
109

  
110
		/* possibly ignore full wildcard match */
111
		if (!$fullwc && !strcmp($match , "*")) {
112
			continue;
113
		}
114

  
115
		/* compare exact or wildcard match */
116
		$match = str_replace(array(".", "*", "?"), array("\.", ".*", "\?"), $match);
117
		$result = preg_match("@^/{$match}$@", "/{$page}");
118

  
119
		if ($result) {
120
			return true;
121
		}
122
	}
123

  
124
	return false;
125
}
126

  
127 93
function map_page_privname($page) {
128 94
	global $priv_list;
129 95

  

Also available in: Unified diff