PluginProbe
VikBooking Hotel Booking Engine & PMS / trunk
VikBooking Hotel Booking Engine & PMS vtrunk
1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 All 36 releases
vikbooking / site / class / sasl.php

sasl.php in VikBooking Hotel Booking Engine & PMS trunk, at site/class/sasl.php

426 lines 11.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage com_vikbooking
5 * @author Alessio Gaggii - e4j - Extensionsforjoomla.com
6 * @copyright Copyright (C) 2018 e4j - Extensionsforjoomla.com. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 * @link https://vikwp.com
9 */
10
11 defined('ABSPATH') or die('No script kiddies please!');
12
13 define("SASL_INTERACT", 2);
14 define("SASL_CONTINUE", 1);
15 define("SASL_OK", 0);
16 define("SASL_FAIL", -1);
17 define("SASL_NOMECH", -4);
18
19 class sasl_interact_class
20 {
21 var $id;
22 var $challenge;
23 var $prompt;
24 var $default_result;
25 var $result;
26 };
27
28 /*
29 {metadocument}<?xml version="1.0" encoding="ISO-8859-1" ?>
30 <class>
31
32 <package>net.manuellemos.sasl</package>
33
34 <version>@(#) $Id: sasl.php,v 1.11 2005/10/31 18:43:27 mlemos Exp $</version>
35 <copyright>Copyright � (C) Manuel Lemos 2004</copyright>
36 <title>Simple Authentication and Security Layer client</title>
37 <author>Manuel Lemos</author>
38 <authoraddress>mlemos-at-acm.org</authoraddress>
39
40 <documentation>
41 <idiom>en</idiom>
42 <purpose>Provide a common interface to plug-in driver classes that
43 implement different mechanisms for authentication used by clients of
44 standard protocols like SMTP, POP3, IMAP, HTTP, etc.. Currently the
45 supported authentication mechanisms are: <tt>PLAIN</tt>,
46 <tt>LOGIN</tt>, <tt>CRAM-MD5</tt>, <tt>Digest</tt> and <tt>NTML</tt>
47 (Windows or Samba).</purpose>
48 <usage>.</usage>
49 </documentation>
50
51 {/metadocument}
52 */
53
54 class sasl_client_class
55 {
56 /* Public variables */
57
58 /*
59 {metadocument}
60 <variable>
61 <name>error</name>
62 <type>STRING</type>
63 <value></value>
64 <documentation>
65 <purpose>Store the message that is returned when an error
66 occurs.</purpose>
67 <usage>Check this variable to understand what happened when a call to
68 any of the class functions has failed.<paragraphbreak />
69 This class uses cumulative error handling. This means that if one
70 class functions that may fail is called and this variable was
71 already set to an error message due to a failure in a previous call
72 to the same or other function, the function will also fail and does
73 not do anything.<paragraphbreak />
74 This allows programs using this class to safely call several
75 functions that may fail and only check the failure condition after
76 the last function call.<paragraphbreak />
77 Just set this variable to an empty string to clear the error
78 condition.</usage>
79 </documentation>
80 </variable>
81 {/metadocument}
82 */
83 var $error='';
84
85 /*
86 {metadocument}
87 <variable>
88 <name>mechanism</name>
89 <type>STRING</type>
90 <value></value>
91 <documentation>
92 <purpose>Store the name of the mechanism that was selected during the
93 call to the <functionlink>Start</functionlink> function.</purpose>
94 <usage>You can access this variable but do not change it.</usage>
95 </documentation>
96 </variable>
97 {/metadocument}
98 */
99 var $mechanism='';
100
101 /*
102 {metadocument}
103 <variable>
104 <name>encode_response</name>
105 <type>BOOLEAN</type>
106 <value>1</value>
107 <documentation>
108 <purpose>Let the drivers inform the applications whether responses
109 need to be encoded.</purpose>
110 <usage>Applications should check this variable before sending
111 authentication responses to the server to determine if the
112 responses need to be encoded, eventually with base64 algorithm.</usage>
113 </documentation>
114 </variable>
115 {/metadocument}
116 */
117 var $encode_response=1;
118
119 /* Private variables */
120
121 var $driver;
122 var $drivers=array(
123 "Digest" => array("digest_sasl_client_class", "digest_sasl_client.php" ),
124 "CRAM-MD5" => array("cram_md5_sasl_client_class", "cram_md5_sasl_client.php" ),
125 "LOGIN" => array("login_sasl_client_class", "login_sasl_client.php" ),
126 "NTLM" => array("ntlm_sasl_client_class", "ntlm_sasl_client.php" ),
127 "PLAIN" => array("plain_sasl_client_class", "plain_sasl_client.php" ),
128 "Basic" => array("basic_sasl_client_class", "basic_sasl_client.php" )
129 );
130 var $credentials=array();
131
132 /* Public functions */
133
134 /*
135 {metadocument}
136 <function>
137 <name>SetCredential</name>
138 <type>VOID</type>
139 <documentation>
140 <purpose>Store the value of a credential that may be used by any of
141 the supported mechanisms to process the authentication messages and
142 responses.</purpose>
143 <usage>Call this function before starting the authentication dialog
144 to pass all the credential values that be needed to use the type
145 of authentication that the applications may need.</usage>
146 <returnvalue>.</returnvalue>
147 </documentation>
148 <argument>
149 <name>key</name>
150 <type>STRING</type>
151 <documentation>
152 <purpose>Specify the name of the credential key.</purpose>
153 </documentation>
154 </argument>
155 <argument>
156 <name>value</name>
157 <type>STRING</type>
158 <documentation>
159 <purpose>Specify the value for the credential.</purpose>
160 </documentation>
161 </argument>
162 <do>
163 {/metadocument}
164 */
165 Function SetCredential($key,$value)
166 {
167 $this->credentials[$key]=$value;
168 }
169 /*
170 {metadocument}
171 </do>
172 </function>
173 {/metadocument}
174 */
175
176 /*
177 {metadocument}
178 <function>
179 <name>GetCredentials</name>
180 <type>INTEGER</type>
181 <documentation>
182 <purpose>Retrieve the values of one or more credentials to be used by
183 the authentication mechanism classes.</purpose>
184 <usage>This is meant to be used by authentication mechanism driver
185 classes to retrieve the credentials that may be neede.</usage>
186 <returnvalue>The function may return <tt>SASL_CONTINUE</tt> if it
187 succeeded, or <tt>SASL_NOMECH</tt> if it was not possible to
188 retrieve one of the requested credentials.</returnvalue>
189 </documentation>
190 <argument>
191 <name>credentials</name>
192 <type>HASH</type>
193 <documentation>
194 <purpose>Reference to an associative array variable with all the
195 credentials that are being requested. The function initializes
196 this associative array values.</purpose>
197 </documentation>
198 </argument>
199 <argument>
200 <name>defaults</name>
201 <type>HASH</type>
202 <documentation>
203 <purpose>Associative arrays with default values for credentials
204 that may have not been defined.</purpose>
205 </documentation>
206 </argument>
207 <argument>
208 <name>interactions</name>
209 <type>ARRAY</type>
210 <documentation>
211 <purpose>Not yet in use. It is meant to provide context
212 information to retrieve credentials that may be obtained
213 interacting with the user.</purpose>
214 </documentation>
215 </argument>
216 <do>
217 {/metadocument}
218 */
219 Function GetCredentials(&$credentials,$defaults,&$interactions)
220 {
221 Reset($credentials);
222 $end=(GetType($key=Key($credentials))!="string");
223 for(;!$end;)
224 {
225 if(!IsSet($this->credentials[$key]))
226 {
227 if(IsSet($defaults[$key]))
228 $credentials[$key]=$defaults[$key];
229 else
230 {
231 $this->error="the requested credential ".$key." is not defined";
232 return(SASL_NOMECH);
233 }
234 }
235 else
236 $credentials[$key]=$this->credentials[$key];
237 Next($credentials);
238 $end=(GetType($key=Key($credentials))!="string");
239 }
240 return(SASL_CONTINUE);
241 }
242 /*
243 {metadocument}
244 </do>
245 </function>
246 {/metadocument}
247 */
248
249 /*
250 {metadocument}
251 <function>
252 <name>Start</name>
253 <type>INTEGER</type>
254 <documentation>
255 <purpose>Process the initial authentication step initializing the
256 driver class that implements the first of the list of requested
257 mechanisms that is supported by this SASL client library
258 implementation.</purpose>
259 <usage>Call this function specifying a list of mechanisms that the
260 server supports. If the <argumentlink>
261 <argument>message</argument>
262 <function>Start</function>
263 </argumentlink> argument returns a string, it should be sent to
264 the server as initial message. Check the
265 <variablelink>encode_response</variablelink> variable to determine
266 whether the initial message needs to be encoded, eventually with
267 base64 algorithm, before it is sent to the server.</usage>
268 <returnvalue>The function may return <tt>SASL_CONTINUE</tt> if it
269 could start one of the requested authentication mechanisms. It
270 may return <tt>SASL_NOMECH</tt> if it was not possible to start
271 any of the requested mechanisms. It returns <tt>SASL_FAIL</tt> or
272 other value in case of error.</returnvalue>
273 </documentation>
274 <argument>
275 <name>mechanisms</name>
276 <type>ARRAY</type>
277 <inout />
278 <documentation>
279 <purpose>Define the list of names of authentication mechanisms
280 supported by the that should be tried.</purpose>
281 </documentation>
282 </argument>
283 <argument>
284 <name>message</name>
285 <type>STRING</type>
286 <out />
287 <documentation>
288 <purpose>Return the initial message that should be sent to the
289 server to start the authentication dialog. If this value is
290 undefined, no message should be sent to the server.</purpose>
291 </documentation>
292 </argument>
293 <argument>
294 <name>interactions</name>
295 <type>ARRAY</type>
296 <documentation>
297 <purpose>Not yet in use. It is meant to provide context
298 information to interact with the end user.</purpose>
299 </documentation>
300 </argument>
301 <do>
302 {/metadocument}
303 */
304 Function Start($mechanisms, &$message, &$interactions)
305 {
306 if(strlen($this->error))
307 return(SASL_FAIL);
308 if(IsSet($this->driver))
309 return($this->driver->Start($this,$message,$interactions));
310 $no_mechanism_error="";
311 for($m=0;$m<count($mechanisms);$m++)
312 {
313 $mechanism=$mechanisms[$m];
314 if(IsSet($this->drivers[$mechanism]))
315 {
316 if(!class_exists($this->drivers[$mechanism][0]))
317 require(dirname(__FILE__)."/".$this->drivers[$mechanism][1]);
318 $this->driver=new $this->drivers[$mechanism][0];
319 if($this->driver->Initialize($this))
320 {
321 $this->encode_response=1;
322 $status=$this->driver->Start($this,$message,$interactions);
323 switch($status)
324 {
325 case SASL_NOMECH:
326 Unset($this->driver);
327 if(strlen($no_mechanism_error)==0)
328 $no_mechanism_error=$this->error;
329 $this->error="";
330 break;
331 case SASL_CONTINUE:
332 $this->mechanism=$mechanism;
333 return($status);
334 default:
335 Unset($this->driver);
336 $this->error="";
337 return($status);
338 }
339 }
340 else
341 {
342 Unset($this->driver);
343 if(strlen($no_mechanism_error)==0)
344 $no_mechanism_error=$this->error;
345 $this->error="";
346 }
347 }
348 }
349 $this->error=(strlen($no_mechanism_error) ? $no_mechanism_error : "it was not requested any of the authentication mechanisms that are supported");
350 return(SASL_NOMECH);
351 }
352 /*
353 {metadocument}
354 </do>
355 </function>
356 {/metadocument}
357 */
358
359 /*
360 {metadocument}
361 <function>
362 <name>Step</name>
363 <type>INTEGER</type>
364 <documentation>
365 <purpose>Process the authentication steps after the initial step,
366 until the authetication iteration dialog is complete.</purpose>
367 <usage>Call this function iteratively after a successful initial
368 step calling the <functionlink>Start</functionlink> function.</usage>
369 <returnvalue>The function returns <tt>SASL_CONTINUE</tt> if step was
370 processed successfully, or returns <tt>SASL_FAIL</tt> in case of
371 error.</returnvalue>
372 </documentation>
373 <argument>
374 <name>response</name>
375 <type>STRING</type>
376 <in />
377 <documentation>
378 <purpose>Pass the response returned by the server to the previous
379 step.</purpose>
380 </documentation>
381 </argument>
382 <argument>
383 <name>message</name>
384 <type>STRING</type>
385 <out />
386 <documentation>
387 <purpose>Return the message that should be sent to the server to
388 continue the authentication dialog. If this value is undefined,
389 no message should be sent to the server.</purpose>
390 </documentation>
391 </argument>
392 <argument>
393 <name>interactions</name>
394 <type>ARRAY</type>
395 <documentation>
396 <purpose>Not yet in use. It is meant to provide context
397 information to interact with the end user.</purpose>
398 </documentation>
399 </argument>
400 <do>
401 {/metadocument}
402 */
403 Function Step($response, &$message, &$interactions)
404 {
405 if(strlen($this->error))
406 return(SASL_FAIL);
407 return($this->driver->Step($this,$response,$message,$interactions));
408 }
409 /*
410 {metadocument}
411 </do>
412 </function>
413 {/metadocument}
414 */
415
416 };
417
418 /*
419
420 {metadocument}
421 </class>
422 {/metadocument}
423
424 */
425
426 ?>