@@ -22,7 +22,7 @@ |
||
| 22 | 22 | /** |
| 23 | 23 | * Constructor. |
| 24 | 24 | * |
| 25 | - * @param object $configuration Configuration object |
|
| 25 | + * @param Configuration $configuration Configuration object |
|
| 26 | 26 | * @return void |
| 27 | 27 | */ |
| 28 | 28 | public function __construct(Configuration $configuration) |
@@ -56,7 +56,7 @@ |
||
| 56 | 56 | /** |
| 57 | 57 | * Constructor. |
| 58 | 58 | * |
| 59 | - * @param object $configuration Configuration object |
|
| 59 | + * @param Configuration $configuration Configuration object |
|
| 60 | 60 | * @return void |
| 61 | 61 | */ |
| 62 | 62 | public function __construct(Configuration $configuration) |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | /** |
| 22 | 22 | * Constructor. |
| 23 | 23 | * |
| 24 | - * @param object $configuration Configuration object |
|
| 24 | + * @param Configuration $configuration Configuration object |
|
| 25 | 25 | * @return void |
| 26 | 26 | */ |
| 27 | 27 | public function __construct(Configuration $configuration) |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | /** |
| 30 | 30 | * Constructor. |
| 31 | 31 | * |
| 32 | - * @param object $configuration Configuration object |
|
| 32 | + * @param Configuration $configuration Configuration object |
|
| 33 | 33 | * @return void |
| 34 | 34 | */ |
| 35 | 35 | public function __construct(Configuration $configuration) |
@@ -43,7 +43,7 @@ |
||
| 43 | 43 | /** |
| 44 | 44 | * Constructor. |
| 45 | 45 | * |
| 46 | - * @param object $configuration Configuration object |
|
| 46 | + * @param Configuration $configuration Configuration object |
|
| 47 | 47 | * @return void |
| 48 | 48 | */ |
| 49 | 49 | public function __construct(Configuration $configuration) |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * Set command line prefix. |
| 50 | 50 | * |
| 51 | 51 | * @param string $prefix command line prefix |
| 52 | - * @return object class object |
|
| 52 | + * @return Builder class object |
|
| 53 | 53 | */ |
| 54 | 54 | final public function setPrefix($prefix) |
| 55 | 55 | { |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * Set command line options |
| 62 | 62 | * |
| 63 | 63 | * @param array $opts command line options |
| 64 | - * @return object class object |
|
| 64 | + * @return Builder class object |
|
| 65 | 65 | */ |
| 66 | 66 | final public function setOptions(array $opts) |
| 67 | 67 | { |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * Set command line arguments |
| 86 | 86 | * |
| 87 | 87 | * @param array $args command line arguments |
| 88 | - * @return object class object |
|
| 88 | + * @return Builder class object |
|
| 89 | 89 | */ |
| 90 | 90 | final public function setArguments(array $args) |
| 91 | 91 | { |
@@ -11,21 +11,21 @@ discard block |
||
| 11 | 11 | class Builder |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 14 | + /** |
|
| 15 | 15 | * Command prefix. |
| 16 | 16 | * |
| 17 | 17 | * @var string |
| 18 | 18 | */ |
| 19 | - public $prefix; |
|
| 19 | + public $prefix; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 21 | + /** |
|
| 22 | 22 | * Command options. |
| 23 | 23 | * |
| 24 | 24 | * @var array |
| 25 | 25 | */ |
| 26 | 26 | public $options; |
| 27 | 27 | |
| 28 | - /** |
|
| 28 | + /** |
|
| 29 | 29 | * Command arguments. |
| 30 | 30 | * |
| 31 | 31 | * @var array |
@@ -67,16 +67,16 @@ discard block |
||
| 67 | 67 | { |
| 68 | 68 | $this->options = []; |
| 69 | 69 | foreach ($opts as $key => $value) |
| 70 | - { |
|
| 71 | - if (preg_match('/^-.*$/', $key, $matches)) |
|
| 72 | - { |
|
| 73 | - $this->options[] = is_bool($value) ? $key : str_pad($key, strlen($key) + 1, ' ', STR_PAD_RIGHT) . $value; |
|
| 74 | - } |
|
| 75 | - if (preg_match('/^-.*$/', $value, $matches)) |
|
| 76 | - { |
|
| 77 | - $this->options[] = $value; |
|
| 78 | - } |
|
| 79 | - } |
|
| 70 | + { |
|
| 71 | + if (preg_match('/^-.*$/', $key, $matches)) |
|
| 72 | + { |
|
| 73 | + $this->options[] = is_bool($value) ? $key : str_pad($key, strlen($key) + 1, ' ', STR_PAD_RIGHT) . $value; |
|
| 74 | + } |
|
| 75 | + if (preg_match('/^-.*$/', $value, $matches)) |
|
| 76 | + { |
|
| 77 | + $this->options[] = $value; |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | 80 | $this->options = implode(' ', array_filter($this->options, 'strlen')); |
| 81 | 81 | return $this; |
| 82 | 82 | } |
@@ -89,19 +89,19 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | final public function setArguments(array $args) |
| 91 | 91 | { |
| 92 | - $this->arguments = []; |
|
| 92 | + $this->arguments = []; |
|
| 93 | 93 | foreach ($args as $key => $value) |
| 94 | - { |
|
| 95 | - if (preg_match('/^-.*$/', $key, $matches)) |
|
| 96 | - { |
|
| 97 | - $this->arguments[] = is_bool($value) ? $key : str_pad($key, strlen($key) + 1, ' ', STR_PAD_RIGHT) . $value; |
|
| 98 | - } |
|
| 99 | - else |
|
| 100 | - { |
|
| 101 | - $this->arguments[] = is_array($value) ? implode(' ', $value) : $value; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - $this->arguments = implode(' ', array_filter($this->arguments, 'strlen')); |
|
| 94 | + { |
|
| 95 | + if (preg_match('/^-.*$/', $key, $matches)) |
|
| 96 | + { |
|
| 97 | + $this->arguments[] = is_bool($value) ? $key : str_pad($key, strlen($key) + 1, ' ', STR_PAD_RIGHT) . $value; |
|
| 98 | + } |
|
| 99 | + else |
|
| 100 | + { |
|
| 101 | + $this->arguments[] = is_array($value) ? implode(' ', $value) : $value; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + $this->arguments = implode(' ', array_filter($this->arguments, 'strlen')); |
|
| 105 | 105 | return $this; |
| 106 | 106 | } |
| 107 | 107 | } |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | * Sets username. |
| 93 | 93 | * |
| 94 | 94 | * @param string $username username |
| 95 | - * @return object \LibSSH2\Configuration object |
|
| 95 | + * @return Configuration \LibSSH2\Configuration object |
|
| 96 | 96 | */ |
| 97 | 97 | final public function set_username($username) |
| 98 | 98 | { |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * Sets user password. |
| 105 | 105 | * |
| 106 | 106 | * @param string $password password |
| 107 | - * @return object \LibSSH2\Configuration object |
|
| 107 | + * @return Configuration \LibSSH2\Configuration object |
|
| 108 | 108 | */ |
| 109 | 109 | final public function set_password($password) |
| 110 | 110 | { |
@@ -115,8 +115,8 @@ discard block |
||
| 115 | 115 | /** |
| 116 | 116 | * Sets RSA public key. |
| 117 | 117 | * |
| 118 | - * @param string $publickey RSA public key |
|
| 119 | - * @return object \LibSSH2\Configuration object |
|
| 118 | + * @param string $public_key RSA public key |
|
| 119 | + * @return Configuration \LibSSH2\Configuration object |
|
| 120 | 120 | */ |
| 121 | 121 | final public function set_publickey($public_key) |
| 122 | 122 | { |
@@ -127,8 +127,8 @@ discard block |
||
| 127 | 127 | /** |
| 128 | 128 | * Sets RSA private key. |
| 129 | 129 | * |
| 130 | - * @param string $privatekey RSA private key |
|
| 131 | - * @return object \LibSSH2\Configuration object |
|
| 130 | + * @param string $private_key RSA private key |
|
| 131 | + * @return Configuration \LibSSH2\Configuration object |
|
| 132 | 132 | */ |
| 133 | 133 | final public function set_privatekey($private_key) |
| 134 | 134 | { |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * Sets passphrase. |
| 141 | 141 | * |
| 142 | 142 | * @param string $passphrase passphrase |
| 143 | - * @return object \LibSSH2\Configuration object |
|
| 143 | + * @return Configuration \LibSSH2\Configuration object |
|
| 144 | 144 | */ |
| 145 | 145 | final public function set_passphrase($passphrase) |
| 146 | 146 | { |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | * Sets hostname. |
| 153 | 153 | * |
| 154 | 154 | * @param string $host hostname |
| 155 | - * @return object \LibSSH2\Configuration object |
|
| 155 | + * @return Configuration \LibSSH2\Configuration object |
|
| 156 | 156 | */ |
| 157 | 157 | final public function set_host($host) |
| 158 | 158 | { |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | * Sets port. |
| 165 | 165 | * |
| 166 | 166 | * @param int $port port |
| 167 | - * @return object \LibSSH2\Configuration object |
|
| 167 | + * @return Configuration \LibSSH2\Configuration object |
|
| 168 | 168 | */ |
| 169 | 169 | final public function set_port($port) |
| 170 | 170 | { |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | * Sets methods. |
| 177 | 177 | * |
| 178 | 178 | * @param array $methods remote connection methods |
| 179 | - * @return object \LibSSH2\Configuration object |
|
| 179 | + * @return Configuration \LibSSH2\Configuration object |
|
| 180 | 180 | */ |
| 181 | 181 | final public function set_methods(array $methods = null) |
| 182 | 182 | { |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | /** |
| 191 | 191 | * Sets tunnel. |
| 192 | 192 | * |
| 193 | - * @return object \LibSSH2\Configuration object |
|
| 193 | + * @return Configuration \LibSSH2\Configuration object |
|
| 194 | 194 | */ |
| 195 | 195 | final public function set_tunnel() |
| 196 | 196 | { |
@@ -201,8 +201,7 @@ discard block |
||
| 201 | 201 | /** |
| 202 | 202 | * Sets tunnel hostname. |
| 203 | 203 | * |
| 204 | - * @param string $hostname hostname |
|
| 205 | - * @return object \LibSSH2\Configuration object |
|
| 204 | + * @return Configuration \LibSSH2\Configuration object |
|
| 206 | 205 | */ |
| 207 | 206 | final public function set_tunnel_host($host) |
| 208 | 207 | { |
@@ -215,7 +214,7 @@ discard block |
||
| 215 | 214 | * Sets tunnel port. |
| 216 | 215 | * |
| 217 | 216 | * @param int $port port |
| 218 | - * @return object \LibSSH2\Configuration object |
|
| 217 | + * @return Configuration \LibSSH2\Configuration object |
|
| 219 | 218 | */ |
| 220 | 219 | final public function set_tunnel_port($port) |
| 221 | 220 | { |
@@ -11,35 +11,35 @@ discard block |
||
| 11 | 11 | class Configuration |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 14 | + /** |
|
| 15 | 15 | * Username. |
| 16 | 16 | * |
| 17 | 17 | * @var string |
| 18 | 18 | */ |
| 19 | 19 | protected $username = null; |
| 20 | 20 | |
| 21 | - /** |
|
| 21 | + /** |
|
| 22 | 22 | * User password. |
| 23 | 23 | * |
| 24 | 24 | * @var string |
| 25 | 25 | */ |
| 26 | 26 | protected $password = null; |
| 27 | 27 | |
| 28 | - /** |
|
| 28 | + /** |
|
| 29 | 29 | * RSA public key. |
| 30 | 30 | * |
| 31 | 31 | * @var string |
| 32 | 32 | */ |
| 33 | 33 | protected $publickey = null; |
| 34 | 34 | |
| 35 | - /** |
|
| 35 | + /** |
|
| 36 | 36 | * RSA private key. |
| 37 | 37 | * |
| 38 | 38 | * @var string |
| 39 | 39 | */ |
| 40 | 40 | protected $privatekey = null; |
| 41 | 41 | |
| 42 | - /** |
|
| 42 | + /** |
|
| 43 | 43 | * Passphrase. |
| 44 | 44 | * |
| 45 | 45 | * @var string |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | protected $methods = []; |
| 69 | 69 | |
| 70 | - /** |
|
| 70 | + /** |
|
| 71 | 71 | * SSH tunnel requested. |
| 72 | 72 | * |
| 73 | 73 | * @var boolean |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | protected $tunnel_port = 22; |
| 90 | 90 | |
| 91 | - /** |
|
| 91 | + /** |
|
| 92 | 92 | * Sets username. |
| 93 | 93 | * |
| 94 | 94 | * @param string $username username |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | return $this; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - /** |
|
| 103 | + /** |
|
| 104 | 104 | * Sets user password. |
| 105 | 105 | * |
| 106 | 106 | * @param string $password password |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | return $this; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - /** |
|
| 115 | + /** |
|
| 116 | 116 | * Sets RSA public key. |
| 117 | 117 | * |
| 118 | 118 | * @param string $publickey RSA public key |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | return $this; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - /** |
|
| 127 | + /** |
|
| 128 | 128 | * Sets RSA private key. |
| 129 | 129 | * |
| 130 | 130 | * @param string $privatekey RSA private key |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | return $this; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - /** |
|
| 139 | + /** |
|
| 140 | 140 | * Sets passphrase. |
| 141 | 141 | * |
| 142 | 142 | * @param string $passphrase passphrase |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | return $this; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - /** |
|
| 190 | + /** |
|
| 191 | 191 | * Sets tunnel. |
| 192 | 192 | * |
| 193 | 193 | * @return object \LibSSH2\Configuration object |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | */ |
| 207 | 207 | final public function set_tunnel_host($host) |
| 208 | 208 | { |
| 209 | - $this->set_tunnel(); |
|
| 209 | + $this->set_tunnel(); |
|
| 210 | 210 | $this->tunnel_host = $host; |
| 211 | 211 | return $this; |
| 212 | 212 | } |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | return $this; |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - /** |
|
| 226 | + /** |
|
| 227 | 227 | * Returns username. |
| 228 | 228 | * |
| 229 | 229 | * @return string username |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | return $this->username; |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - /** |
|
| 240 | + /** |
|
| 241 | 241 | * Returns user's password. |
| 242 | 242 | * |
| 243 | 243 | * @return string password |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | return $this->password; |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - /** |
|
| 254 | + /** |
|
| 255 | 255 | * Returns RSA public key. |
| 256 | 256 | * |
| 257 | 257 | * @return string RSA public key |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | return $this->publickey; |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - /** |
|
| 268 | + /** |
|
| 269 | 269 | * Returns RSA private key. |
| 270 | 270 | * |
| 271 | 271 | * @return string privatekey |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | return $this->privatekey; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - /** |
|
| 282 | + /** |
|
| 283 | 283 | * Returns passphrase. |
| 284 | 284 | * |
| 285 | 285 | * @return string passphrase |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | } |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - /** |
|
| 329 | + /** |
|
| 330 | 330 | * Returns tunnel. |
| 331 | 331 | * |
| 332 | 332 | * @return boolean |
@@ -22,9 +22,8 @@ discard block |
||
| 22 | 22 | /** |
| 23 | 23 | * Constructor. |
| 24 | 24 | * |
| 25 | - * @param instance $configuration Configuration class instance |
|
| 26 | - * @param instance $authentication Authentication class instance |
|
| 27 | - * @param boolean $tunnel require SSH tunnel |
|
| 25 | + * @param Configuration $configuration Configuration class instance |
|
| 26 | + * @param Authentication $authentication Authentication class instance |
|
| 28 | 27 | * @return void |
| 29 | 28 | */ |
| 30 | 29 | public function __construct(Configuration $configuration, Authentication $authentication) |
@@ -56,7 +55,7 @@ discard block |
||
| 56 | 55 | /** |
| 57 | 56 | * Create remote connection resource. |
| 58 | 57 | * |
| 59 | - * @param resource $configuration \LibSSH2\Configuration object |
|
| 58 | + * @param Configuration $configuration \LibSSH2\Configuration object |
|
| 60 | 59 | * @return void |
| 61 | 60 | */ |
| 62 | 61 | final public function connect(Configuration $configuration) |
@@ -71,8 +70,6 @@ discard block |
||
| 71 | 70 | /** |
| 72 | 71 | * Create remote tunnel connection resource. |
| 73 | 72 | * |
| 74 | - * @param string $host hostname |
|
| 75 | - * @param int $port port (default=22) |
|
| 76 | 73 | * @return void |
| 77 | 74 | */ |
| 78 | 75 | final public function tunnel(Configuration $configuration) |
@@ -87,7 +84,7 @@ discard block |
||
| 87 | 84 | /** |
| 88 | 85 | * Authenticate remote connection resource. |
| 89 | 86 | * |
| 90 | - * @param resource $authentication \LibSSH2\Authentication\Authentication interface object |
|
| 87 | + * @param Authentication $authentication \LibSSH2\Authentication\Authentication interface object |
|
| 91 | 88 | * @return void |
| 92 | 89 | */ |
| 93 | 90 | final public function authenticate(Authentication $authentication) |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | public function __construct(Configuration $configuration, Authentication $authentication) |
| 31 | 31 | { |
| 32 | - if (extension_loaded('ssh2') == false) |
|
| 32 | + if (extension_loaded('ssh2') == false) |
|
| 33 | 33 | { |
| 34 | 34 | throw new \RuntimeException('The libssh2 extension is not loaded.'); |
| 35 | 35 | } |
@@ -24,8 +24,8 @@ discard block |
||
| 24 | 24 | /** |
| 25 | 25 | * Constructor. |
| 26 | 26 | * |
| 27 | - * @param instance $configuration Configuration instance |
|
| 28 | - * @param instance $authentication Authentication instance |
|
| 27 | + * @param Configuration $configuration Configuration instance |
|
| 28 | + * @param Authentication $authentication Authentication instance |
|
| 29 | 29 | * @return void |
| 30 | 30 | */ |
| 31 | 31 | public function __construct(Configuration $configuration, Authentication $authentication) |
@@ -131,6 +131,7 @@ discard block |
||
| 131 | 131 | * Execute Kerberos command. |
| 132 | 132 | * |
| 133 | 133 | * @param string $command command to be executed |
| 134 | + * @param boolean $strict |
|
| 134 | 135 | * @return array return code and STDOUT |
| 135 | 136 | */ |
| 136 | 137 | final private function _exec($command, $strict) |
@@ -17,11 +17,11 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | class Kerberos |
| 19 | 19 | { |
| 20 | - private $configuration; |
|
| 20 | + private $configuration; |
|
| 21 | 21 | |
| 22 | - private $authentication; |
|
| 22 | + private $authentication; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 24 | + /** |
|
| 25 | 25 | * Constructor. |
| 26 | 26 | * |
| 27 | 27 | * @param instance $configuration Configuration instance |
@@ -31,121 +31,121 @@ discard block |
||
| 31 | 31 | public function __construct(Configuration $configuration, Authentication $authentication) |
| 32 | 32 | { |
| 33 | 33 | if (get_class($authentication) != 'LibSSH2\Authentication\Password') |
| 34 | - { |
|
| 35 | - throw new \RuntimeException("Kerberos authentication requires Password authentication to remote server."); |
|
| 36 | - } |
|
| 37 | - $this->configuration = $configuration; |
|
| 38 | - $this->authentication = $authentication; |
|
| 34 | + { |
|
| 35 | + throw new \RuntimeException("Kerberos authentication requires Password authentication to remote server."); |
|
| 36 | + } |
|
| 37 | + $this->configuration = $configuration; |
|
| 38 | + $this->authentication = $authentication; |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * kcreate creates a Kerberos credential (ticket) cache and sets the |
|
| 43 | - * KRB5CCNAME environmental variable. |
|
| 44 | - * |
|
| 45 | - * @return string Kerberos credential cache |
|
| 46 | - */ |
|
| 47 | - final public function kcreate($principle) |
|
| 48 | - { |
|
| 49 | - $username = $this->configuration->get_username(); |
|
| 50 | - $command = (new Builder()) |
|
| 51 | - ->setPrefix('kinit') |
|
| 52 | - ->setArguments([$principle]); |
|
| 41 | + /** |
|
| 42 | + * kcreate creates a Kerberos credential (ticket) cache and sets the |
|
| 43 | + * KRB5CCNAME environmental variable. |
|
| 44 | + * |
|
| 45 | + * @return string Kerberos credential cache |
|
| 46 | + */ |
|
| 47 | + final public function kcreate($principle) |
|
| 48 | + { |
|
| 49 | + $username = $this->configuration->get_username(); |
|
| 50 | + $command = (new Builder()) |
|
| 51 | + ->setPrefix('kinit') |
|
| 52 | + ->setArguments([$principle]); |
|
| 53 | 53 | |
| 54 | - $shell = new Shell($this->configuration, $this->authentication); |
|
| 55 | - $shell |
|
| 56 | - ->shell() |
|
| 57 | - ->write("export KRB5CCNAME=`mktemp /tmp/krb5cc_{$username}_XXXXXXXXXXXXX`;") |
|
| 58 | - ->write($command) |
|
| 59 | - ->write($this->configuration->get_password()) |
|
| 60 | - ->write('echo KRB5CCNAME:$KRB5CCNAME', true) |
|
| 61 | - ->output(); |
|
| 54 | + $shell = new Shell($this->configuration, $this->authentication); |
|
| 55 | + $shell |
|
| 56 | + ->shell() |
|
| 57 | + ->write("export KRB5CCNAME=`mktemp /tmp/krb5cc_{$username}_XXXXXXXXXXXXX`;") |
|
| 58 | + ->write($command) |
|
| 59 | + ->write($this->configuration->get_password()) |
|
| 60 | + ->write('echo KRB5CCNAME:$KRB5CCNAME', true) |
|
| 61 | + ->output(); |
|
| 62 | 62 | |
| 63 | - if (!preg_match("/KRB5CCNAME:(\/tmp\/krb5cc_.*)/", $shell->get_output(), $matches)) |
|
| 64 | - { |
|
| 65 | - throw new \RuntimeException('Failed to create the Kerberos credential cache and set the KRB5CCNAME environmental variable.'); |
|
| 66 | - } |
|
| 67 | - return $matches[1]; |
|
| 68 | - } |
|
| 63 | + if (!preg_match("/KRB5CCNAME:(\/tmp\/krb5cc_.*)/", $shell->get_output(), $matches)) |
|
| 64 | + { |
|
| 65 | + throw new \RuntimeException('Failed to create the Kerberos credential cache and set the KRB5CCNAME environmental variable.'); |
|
| 66 | + } |
|
| 67 | + return $matches[1]; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * The kdestroy utility destroys the user’s active Kerberos |
|
| 72 | - * authorization tickets by overwriting and deleting the |
|
| 73 | - * credentials cache that contains them. If the credentials |
|
| 74 | - * cache is not specified, the default credentials cache is |
|
| 75 | - * destroyed. |
|
| 76 | - * |
|
| 77 | - * @param array $options klist command line options |
|
| 78 | - * @param array $arguments klist command line arguments |
|
| 79 | - * @return int return code (exit status code) |
|
| 80 | - */ |
|
| 81 | - final public function kdestroy(array $options = [], array $arguments = [], $strict = true) |
|
| 82 | - { |
|
| 83 | - $command = (new Builder()) |
|
| 84 | - ->setPrefix('kdestroy') |
|
| 85 | - ->setOptions($options) |
|
| 86 | - ->setArguments($arguments); |
|
| 87 | - list($retval, $output) = $this->_exec($command, $strict); |
|
| 88 | - return $retval; |
|
| 89 | - } |
|
| 70 | + /** |
|
| 71 | + * The kdestroy utility destroys the user’s active Kerberos |
|
| 72 | + * authorization tickets by overwriting and deleting the |
|
| 73 | + * credentials cache that contains them. If the credentials |
|
| 74 | + * cache is not specified, the default credentials cache is |
|
| 75 | + * destroyed. |
|
| 76 | + * |
|
| 77 | + * @param array $options klist command line options |
|
| 78 | + * @param array $arguments klist command line arguments |
|
| 79 | + * @return int return code (exit status code) |
|
| 80 | + */ |
|
| 81 | + final public function kdestroy(array $options = [], array $arguments = [], $strict = true) |
|
| 82 | + { |
|
| 83 | + $command = (new Builder()) |
|
| 84 | + ->setPrefix('kdestroy') |
|
| 85 | + ->setOptions($options) |
|
| 86 | + ->setArguments($arguments); |
|
| 87 | + list($retval, $output) = $this->_exec($command, $strict); |
|
| 88 | + return $retval; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * klist lists the Kerberos principal and Kerberos tickets held |
|
| 93 | - * in a credentials cache, or the keys held in a keytab file. |
|
| 94 | - * |
|
| 95 | - * @param array $options klist command line options |
|
| 96 | - * @param array $arguments klist command line arguments |
|
| 97 | - * @return string klist results |
|
| 98 | - */ |
|
| 99 | - final public function klist(array $options = [], array $arguments = [], $strict = true) |
|
| 100 | - { |
|
| 101 | - $command = (new Builder()) |
|
| 102 | - ->setPrefix('klist') |
|
| 103 | - ->setOptions($options) |
|
| 104 | - ->setArguments($arguments); |
|
| 105 | - list($retval, $output) = $this->_exec($command, $strict); |
|
| 106 | - return $output; |
|
| 107 | - } |
|
| 91 | + /** |
|
| 92 | + * klist lists the Kerberos principal and Kerberos tickets held |
|
| 93 | + * in a credentials cache, or the keys held in a keytab file. |
|
| 94 | + * |
|
| 95 | + * @param array $options klist command line options |
|
| 96 | + * @param array $arguments klist command line arguments |
|
| 97 | + * @return string klist results |
|
| 98 | + */ |
|
| 99 | + final public function klist(array $options = [], array $arguments = [], $strict = true) |
|
| 100 | + { |
|
| 101 | + $command = (new Builder()) |
|
| 102 | + ->setPrefix('klist') |
|
| 103 | + ->setOptions($options) |
|
| 104 | + ->setArguments($arguments); |
|
| 105 | + list($retval, $output) = $this->_exec($command, $strict); |
|
| 106 | + return $output; |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * kinit obtains and caches an initial ticket-granting ticket for |
|
| 111 | - * principal. If principal is absent, kinit chooses an appropriate |
|
| 112 | - * principal name based on existing credential cache contents or |
|
| 113 | - * the local username of the user invoking kinit. Some options |
|
| 114 | - * modify the choice of principal name. |
|
| 115 | - * |
|
| 116 | - * @param array $options kinit command line options |
|
| 117 | - * @param array $arguments kinit command line arguments |
|
| 118 | - * @return int exit status code |
|
| 119 | - */ |
|
| 120 | - final public function kinit(array $options = [], array $arguments = [], $strict = true) |
|
| 121 | - { |
|
| 122 | - $command = (new Builder()) |
|
| 123 | - ->setPrefix('kinit') |
|
| 124 | - ->setOptions($options) |
|
| 125 | - ->setArguments($arguments); |
|
| 126 | - list($retval, $output) = $this->_exec($command, $strict); |
|
| 127 | - return $retval; |
|
| 128 | - } |
|
| 109 | + /** |
|
| 110 | + * kinit obtains and caches an initial ticket-granting ticket for |
|
| 111 | + * principal. If principal is absent, kinit chooses an appropriate |
|
| 112 | + * principal name based on existing credential cache contents or |
|
| 113 | + * the local username of the user invoking kinit. Some options |
|
| 114 | + * modify the choice of principal name. |
|
| 115 | + * |
|
| 116 | + * @param array $options kinit command line options |
|
| 117 | + * @param array $arguments kinit command line arguments |
|
| 118 | + * @return int exit status code |
|
| 119 | + */ |
|
| 120 | + final public function kinit(array $options = [], array $arguments = [], $strict = true) |
|
| 121 | + { |
|
| 122 | + $command = (new Builder()) |
|
| 123 | + ->setPrefix('kinit') |
|
| 124 | + ->setOptions($options) |
|
| 125 | + ->setArguments($arguments); |
|
| 126 | + list($retval, $output) = $this->_exec($command, $strict); |
|
| 127 | + return $retval; |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Execute Kerberos command. |
|
| 132 | - * |
|
| 133 | - * @param string $command command to be executed |
|
| 134 | - * @return array return code and STDOUT |
|
| 135 | - */ |
|
| 136 | - final private function _exec($command, $strict) |
|
| 137 | - { |
|
| 138 | - $ssh = new SSH($this->configuration, $this->authentication); |
|
| 139 | - $ssh->exec($command); |
|
| 130 | + /** |
|
| 131 | + * Execute Kerberos command. |
|
| 132 | + * |
|
| 133 | + * @param string $command command to be executed |
|
| 134 | + * @return array return code and STDOUT |
|
| 135 | + */ |
|
| 136 | + final private function _exec($command, $strict) |
|
| 137 | + { |
|
| 138 | + $ssh = new SSH($this->configuration, $this->authentication); |
|
| 139 | + $ssh->exec($command); |
|
| 140 | 140 | |
| 141 | - $output = $ssh->get_output(); |
|
| 142 | - $error = $ssh->get_error(); |
|
| 143 | - $retval = $ssh->get_exitstatus(); |
|
| 141 | + $output = $ssh->get_output(); |
|
| 142 | + $error = $ssh->get_error(); |
|
| 143 | + $retval = $ssh->get_exitstatus(); |
|
| 144 | 144 | |
| 145 | - if ($strict && $retval != 0 ) |
|
| 146 | - { |
|
| 147 | - throw new \RuntimeException($error); |
|
| 148 | - } |
|
| 149 | - return [$retval, $output]; |
|
| 150 | - } |
|
| 145 | + if ($strict && $retval != 0 ) |
|
| 146 | + { |
|
| 147 | + throw new \RuntimeException($error); |
|
| 148 | + } |
|
| 149 | + return [$retval, $output]; |
|
| 150 | + } |
|
| 151 | 151 | } |