// sessions.cpp : Implementation of CnntpadmApp and DLL registration. #include "stdafx.h" #include "nntpcmn.h" #include "oleutil.h" #include "sessions.h" #include "nntptype.h" #include "nntpapi.h" #include // Must define THIS_FILE_* macros to use NntpCreateException() #define THIS_FILE_HELP_CONTEXT 0 #define THIS_FILE_PROG_ID _T("Nntpadm.Sessions.1") #define THIS_FILE_IID IID_INntpAdminSessions ///////////////////////////////////////////////////////////////////////////// // // // Use a macro to define all the default methods // DECLARE_METHOD_IMPLEMENTATION_FOR_STANDARD_EXTENSION_INTERFACES(NntpAdminSessions, CNntpAdminSessions, IID_INntpAdminSessions) STDMETHODIMP CNntpAdminSessions::InterfaceSupportsErrorInfo(REFIID riid) { static const IID* arr[] = { &IID_INntpAdminSessions, }; for (int i=0;i= m_cCount ) { return NntpCreateException ( IDS_NNTPEXCEPTION_INVALID_INDEX ); } // // Copy the properties from m_pSessionInfo [ lIndex ] to member variables: // // ( CComBSTR handles free-ing of old properties ) FileTimeToLocalFileTime ( &m_pSessionInfo[ lIndex ].SessionStartTime, &ftLocal ); FileTimeToSystemTime ( &ftLocal, &st ); SystemTimeToVariantTime ( &st, &m_dateStartTime ); m_dwIpAddress = m_pSessionInfo[ lIndex ].IPAddress; m_dwAuthenticationType = m_pSessionInfo[ lIndex ].AuthenticationType; m_dwPort = m_pSessionInfo[ lIndex ].PortConnected; m_fIsAnonymous = m_pSessionInfo[ lIndex ].fAnonymous; cchCopied = MultiByteToWideChar ( CP_ACP, MB_PRECOMPOSED | MB_USEGLYPHCHARS, m_pSessionInfo[ lIndex ].UserName, -1, wszUsername, MAX_USER_NAME_LENGTH ); m_strUsername = wszUsername; if ( m_strUsername == NULL ) { hr = E_OUTOFMEMORY; goto Exit; } InetAddressToString ( m_dwIpAddress, wszIpAddress, 256 ); m_strIpAddress = wszIpAddress; if ( m_strIpAddress == NULL ) { hr = E_OUTOFMEMORY; goto Exit; } // GetNth sets the cursor: m_fSetCursor = TRUE; Exit: TRACE_HRESULT(hr); TraceFunctLeave (); return hr; } STDMETHODIMP CNntpAdminSessions::Terminate ( ) { TraceFunctEnter ( "CNntpAdminSessions::Terminate" ); HRESULT hr = NOERROR; DWORD err = NOERROR; char szAnsiUsername[ MAX_USER_NAME_LENGTH + 1]; char szAnsiIpAddress[ 50 ]; DWORD cchCopied; szAnsiUsername[0] = NULL; szAnsiIpAddress[0] = NULL; // Validate Server & Service Instance: if ( m_iadsImpl.QueryInstance() == 0 ) { return NntpCreateException ( IDS_NNTPEXCEPTION_SERVICE_INSTANCE_CANT_BE_ZERO ); } // Check Username & IpAddress parameters: if ( m_strUsername == NULL && m_strIpAddress == NULL ) { return NntpCreateException ( IDS_NNTPEXCEPTION_MUST_SUPPLY_USERNAME_OR_IPADDRESS ); } // Translate the username & ipaddress to ANSI. if ( m_strUsername != NULL ) { cchCopied = WideCharToMultiByte ( CP_ACP, 0, m_strUsername, -1, szAnsiUsername, MAX_USER_NAME_LENGTH, NULL, NULL ); } if ( m_strIpAddress != NULL ) { cchCopied = WideCharToMultiByte ( CP_ACP, 0, m_strIpAddress, -1, szAnsiIpAddress, 50, NULL, NULL ); } // Call the TerminateSession RPC: err = NntpTerminateSession ( m_iadsImpl.QueryComputer(), m_iadsImpl.QueryInstance(), m_strUsername ? szAnsiUsername : NULL, m_strIpAddress ? szAnsiIpAddress : NULL ); if ( err != NOERROR ) { hr = RETURNCODETOHRESULT ( err ); goto Exit; } Exit: TRACE_HRESULT(hr); TraceFunctLeave (); return hr; } STDMETHODIMP CNntpAdminSessions::TerminateAll ( ) { TraceFunctEnter ( "CNntpAdminSessions::TerminateAll" ); // Did we enumerate first? HRESULT hr = NOERROR; DWORD ErrResult = NOERROR; DWORD Err = NOERROR; DWORD i; // Validate Server & Service Instance: if ( m_iadsImpl.QueryInstance() == 0 ) { return NntpCreateException ( IDS_NNTPEXCEPTION_SERVICE_INSTANCE_CANT_BE_ZERO ); } #if 0 // Make sure the user has enumerated: if ( m_pSessionInfo == NULL ) { return NntpCreateException ( IDS_NNTPEXCEPTION_DIDNT_ENUMERATE ); } #endif // For Each Session: for ( i = 0; i < m_cCount; i++ ) { // Call the terminate session RPC: Err = NntpTerminateSession ( m_iadsImpl.QueryComputer(), m_iadsImpl.QueryInstance(), m_pSessionInfo[ i ].UserName, NULL ); if ( Err != 0 && ErrResult == 0 ) { ErrResult = Err; } } if ( ErrResult != NOERROR ) { hr = RETURNCODETOHRESULT ( ErrResult ); goto Exit; } Exit: TRACE_HRESULT(hr); TraceFunctLeave (); return hr; }