88namespace OCA \Files_External \Lib \Backend ;
99
1010use Icewind \SMB \BasicAuth ;
11- use Icewind \SMB \KerberosApacheAuth ;
1211use Icewind \SMB \KerberosAuth ;
12+ use Icewind \SMB \KerberosTicket ;
1313use Icewind \SMB \Native \NativeServer ;
1414use Icewind \SMB \Wrapped \Server ;
1515use OCA \Files_External \Lib \Auth \AuthMechanism ;
@@ -59,10 +59,7 @@ public function __construct(IL10N $l, Password $legacyAuth) {
5959 ->setLegacyAuthMechanism ($ legacyAuth );
6060 }
6161
62- /**
63- * @return void
64- */
65- public function manipulateStorageConfig (StorageConfig &$ storage , ?IUser $ user = null ) {
62+ public function manipulateStorageConfig (StorageConfig &$ storage , ?IUser $ user = null ): void {
6663 $ auth = $ storage ->getAuthMechanism ();
6764 if ($ auth ->getScheme () === AuthMechanism::SCHEME_PASSWORD ) {
6865 if (!is_string ($ storage ->getBackendOption ('user ' )) || !is_string ($ storage ->getBackendOption ('password ' ))) {
@@ -84,33 +81,33 @@ public function manipulateStorageConfig(StorageConfig &$storage, ?IUser $user =
8481 throw new \InvalidArgumentException ('invalid authentication backend ' );
8582 }
8683 $ credentialsStore = $ auth ->getCredentialsStore ();
87- $ kerbAuth = new KerberosApacheAuth ();
84+ $ kerbAuth = new KerberosAuth ();
85+ $ kerbAuth ->setTicket (KerberosTicket::fromEnv ());
8886 // check if a kerberos ticket is available, else fallback to session credentials
89- if ($ kerbAuth ->checkTicket ()) {
87+ if ($ kerbAuth ->getTicket ()?->isValid ()) {
9088 $ smbAuth = $ kerbAuth ;
9189 } else {
9290 try {
9391 $ credentials = $ credentialsStore ->getLoginCredentials ();
94- $ user = $ credentials ->getLoginName ();
92+ $ loginName = $ credentials ->getLoginName ();
9593 $ pass = $ credentials ->getPassword ();
96- preg_match ('/(.*)@(.*)/ ' , $ user , $ matches );
94+ preg_match ('/(.*)@(.*)/ ' , $ loginName , $ matches );
9795 $ realm = $ storage ->getBackendOption ('default_realm ' );
9896 if (empty ($ realm )) {
9997 $ realm = 'WORKGROUP ' ;
10098 }
10199 if (count ($ matches ) === 0 ) {
102- $ username = $ user ;
100+ $ username = $ loginName ;
103101 $ workgroup = $ realm ;
104102 } else {
105- $ username = $ matches [1 ];
106- $ workgroup = $ matches [2 ];
103+ [, $ username , $ workgroup ] = $ matches ;
107104 }
108105 $ smbAuth = new BasicAuth (
109106 $ username ,
110107 $ workgroup ,
111108 $ pass
112109 );
113- } catch (\Exception $ e ) {
110+ } catch (\Exception ) {
114111 throw new InsufficientDataForMeaningfulAnswerException ('No session credentials saved ' );
115112 }
116113 }
@@ -124,7 +121,7 @@ public function manipulateStorageConfig(StorageConfig &$storage, ?IUser $user =
124121 $ storage ->setBackendOption ('auth ' , $ smbAuth );
125122 }
126123
127- public function checkDependencies () {
124+ public function checkDependencies (): array {
128125 $ system = \OCP \Server::get (SystemBridge::class);
129126 if (NativeServer::available ($ system )) {
130127 return [];
0 commit comments