3.1.4.6 NetrSessionDel (Opnum 13)

The NetrSessionDel method MUST end one or more network sessions between a server and a client.

 NET_API_STATUS NetrSessionDel(
   [in, string, unique] SRVSVC_HANDLE ServerName,
   [in, string, unique] WCHAR* ClientName,
   [in, string, unique] WCHAR* UserName
 );

ServerName: An SRVSVC_HANDLE (section 2.2.1.1) pointer that identifies the server. The client MUST map this structure to an RPC binding handle (see [C706] sections 4.3.5 and 5.1.5.2). The server MUST ignore this parameter.

ClientName: A pointer to a null-terminated UTF-16 string that specifies the computer name of the client whose sessions are to be disconnected. This string MUST be one of the following: a NULL (zero-length) string; or a string that MUST begin with \\.

UserName: A pointer to a null-terminated UTF-16 string that specifies the user name whose sessions are to be terminated.

Return Values: This method returns 0x00000000 (NERR_Success) to indicate success; otherwise, it returns a nonzero error code. This method can take any specific error code value, as specified in [MS-ERREF] section 2.2. The most common error codes are listed in the following table.

Return value/code

Description

0x00000000

NERR_Success

The client request succeeded.

0x00000005

ERROR_ACCESS_DENIED

Access is denied.

0x00000057

ERROR_INVALID_PARAMETER

The parameter is incorrect.

0x00000008

ERROR_NOT_ENOUGH_MEMORY

Not enough storage is available to process this command.

0x00000908

NERR_ClientNameNotFound

A session does not exist with the computer name.

In response to a NetrSessionDel message, the server ends network sessions between the server and a workstation.

The server SHOULD<54> enforce security measures to verify that the caller has the required permissions to execute this routine. If the caller does not have the required credentials, the server SHOULD<55> fail the call.

The ClientName parameter specifies the computer name of the client to disconnect. If a ClientName is specified, it MUST start with "\\"; otherwise, the server MUST fail the call with an NERR_ClientNameNotFound error code. If a ClientName is specified and it contains more than 1,024 characters, including the terminating null character, the server MUST fail the call with an ERROR_INVALID_PARAMETER error code.

The UserName parameter specifies the name of the user whose session is to be terminated. If a UserName is specified and the length of the UserName string, including the terminating null character, is greater than 1,024, the server MUST fail the call with an ERROR_INVALID_PARAMETER error code.

If both ClientName and UserName are unspecified (a NULL (zero-length) string), the server MUST fail the call with a NERR_ClientNameNotFound or an ERROR_INVALID_PARAMETER error code.

The server MUST enumerate all Session entries in SessionList. For each entry, the server MUST query session properties by invoking the underlying server events as specified in [MS-CIFS] section 3.3.4.14 and [MS-SMB2] section 3.3.4.18, providing Session.GlobalSessionId as the input parameter. If the server receives a STATUS_SUCCESS for a Session.GlobalSessionId from either a CIFS or an SMB2 server, and the received SESSION_INFO_502.sesi502_cname matches the ClientName (if it is specified) and SESSION_INFO_502.sesi502_username matches the UserName (if it is specified), the server MUST close the session by invoking the underlying server event as specified in [MS-CIFS] section 3.3.4.8 or [MS-SMB2] section 3.3.4.12, providing Session.GlobalSessionId as input parameter. The server MUST continue to query all other sessions and close all the matching sessions.

If no matching session is found with the ClientName and UserName, the server MUST fail the call with error code NERR_ClientNameNotFound.