Codebase list php-net-sieve / 16aa775
Parametrize GSSAPI CName Aleksander Machniak 6 years ago
1 changed file(s) with 37 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
197197 *
198198 * @var string
199199 */
200 var $_servicePrincipal = null;
200 var $_gssapiPrincipal = null;
201
202 /**
203 * Kerberos service cname to use for GSSAPI authentication.
204 *
205 * @var string
206 */
207 var $_gssapiCN = null;
201208
202209 /**
203210 * Constructor.
223230 * @param mixed $handler A callback handler for the debug output.
224231 * @param string $principal Kerberos service principal to use
225232 * with GSSAPI authentication.
233 * @param string $cname Kerberos service cname to use
234 * with GSSAPI authentication.
226235 */
227236 function __construct($user = null, $pass = null, $host = 'localhost',
228237 $port = 2000, $logintype = '', $euser = '',
229238 $debug = false, $bypassAuth = false, $useTLS = true,
230 $options = null, $handler = null, $principal = null
239 $options = null, $handler = null, $principal = null, $cname = null
231240 ) {
232241 $this->_pear = new PEAR();
233242 $this->_state = NET_SIEVE_STATE_DISCONNECTED;
241250 $this->_bypassAuth = $bypassAuth;
242251 $this->_useTLS = $useTLS;
243252 $this->_options = (array) $options;
244 $this->_servicePrincipal = $principal;
253 $this->_gssapiPrincipal = $principal;
254 $this->_gssapiCN = $cname;
245255
246256 $this->setDebug($debug, $handler);
247257
295305 */
296306 function setServicePrincipal($principal)
297307 {
298 $this->_servicePrincipal = $principal;
308 $this->_gssapiPrincipal = $principal;
309 }
310
311 /**
312 * Sets the Kerberos service CName for use with GSSAPI
313 * authentication.
314 *
315 * @param string $cname The Kerberos service principal
316 *
317 * @return void
318 */
319 function setServiceCN($cname)
320 {
321 $this->_gssapiCN = $cname;
299322 }
300323
301324 /**
711734 /**
712735 * Authenticates the user using the GSSAPI method.
713736 *
714 * @note the PHP krb5 extension is required and the service principal must have been set.
737 * @note the PHP krb5 extension is required and the service principal and cname
738 * must have been set.
715739 * @see setServicePrincipal()
716740 *
717741 * @return void
722746 return $this->_pear->raiseError('The krb5 extension is required for GSSAPI authentication', 2);
723747 }
724748
725 if (!$this->_servicePrincipal) {
749 if (!$this->_gssapiPrincipal) {
726750 return $this->_pear->raiseError('No Kerberos service principal set', 2);
727751 }
728752
729 putenv('KRB5CCNAME=' . $_SERVER['KRB5CCNAME']);
753 if (!$this->_gssapiCN) {
754 return $this->_pear->raiseError('No Kerberos service CName set', 2);
755 }
756
757 putenv('KRB5CCNAME=' . $this->_gssapiCN);
730758
731759 try {
732760 $ccache = new KRB5CCache();
733 $ccahe->open($_SERVER['KRB5CCNAME']);
761 $ccahe->open($this->_gssapiCN);
734762
735763 $gssapicontext = new GSSAPIContext();
736764 $gssapicontext->acquireCredentials($ccache);
737765
738766 $token = '';
739 $success = $gssapicontext->initSecContext($this->_servicePrincipal, null, null, null, $token);
767 $success = $gssapicontext->initSecContext($this->_gssapiPrincipal, null, null, null, $token);
740768 $token = base64_encode($token);
741769 }
742770 catch (Exception $e) {