@@ -126,24 +126,39 @@ export class Nfsv4OperationsNode implements Nfsv4Operations {
126126 request : msg . Nfsv4SetclientidConfirmRequest ,
127127 ctx : Nfsv4OperationCtx ,
128128 ) : Promise < msg . Nfsv4SetclientidConfirmResponse > {
129+ const { clients, pendingClients} = this ;
129130 const clientid = request . clientid ;
130131 const setclientidConfirm = request . setclientidConfirm . data ;
131- const pendingRecord = this . pendingClients . get ( clientid ) ;
132+ const pendingRecord = pendingClients . get ( clientid ) ;
132133 if ( ! pendingRecord ) {
133134 const confirmedRecord = this . clients . get ( clientid ) ;
134135 if ( confirmedRecord && cmpUint8Array ( confirmedRecord . setclientidConfirm , setclientidConfirm ) )
135136 return new msg . Nfsv4SetclientidConfirmResponse ( Nfsv4Stat . NFS4_OK ) ;
136137 return new msg . Nfsv4SetclientidConfirmResponse ( Nfsv4Stat . NFS4ERR_STALE_CLIENTID ) ;
137138 }
139+ const principal = ctx . getPrincipal ( ) ;
140+ if ( pendingRecord . principal !== principal )
141+ return new msg . Nfsv4SetclientidConfirmResponse ( Nfsv4Stat . NFS4ERR_CLID_INUSE ) ;
138142 if ( ! cmpUint8Array ( pendingRecord . setclientidConfirm , setclientidConfirm ) )
139143 return new msg . Nfsv4SetclientidConfirmResponse ( Nfsv4Stat . NFS4ERR_STALE_CLIENTID ) ;
140144 const oldConfirmed = this . findClientByIdString ( this . clients , pendingRecord . clientIdString ) ;
141145 if ( oldConfirmed ) {
142- this . clients . delete ( oldConfirmed [ 0 ] ) ;
146+ const clientid2 = oldConfirmed [ 0 ] ;
147+ this . clients . delete ( clientid2 ) ;
148+ pendingClients . delete ( clientid2 ) ;
143149 }
144- this . pendingClients . delete ( clientid ) ;
150+ this . clients . delete ( clientid ) ;
151+ pendingClients . delete ( clientid ) ;
152+
153+ // Remove any existing pending records with same ID string.
154+ const clientIdString = pendingRecord . clientIdString ;
155+ for ( const [ id , entry ] of pendingClients . entries ( ) )
156+ if ( cmpUint8Array ( entry . clientIdString , clientIdString ) ) pendingClients . delete ( id ) ;
157+ for ( const [ id , entry ] of clients . entries ( ) )
158+ if ( cmpUint8Array ( entry . clientIdString , clientIdString ) ) clients . delete ( id ) ;
159+
145160 this . enforceClientLimit ( ) ;
146- this . clients . set ( clientid , pendingRecord ) ;
161+ clients . set ( clientid , pendingRecord ) ;
147162 return new msg . Nfsv4SetclientidConfirmResponse ( Nfsv4Stat . NFS4_OK ) ;
148163 }
149164
0 commit comments