#include <afx.h>
/////////////////////////////////////////////////////////////////////////////
// Copyright (C) 1997 by Joerg Koenig and the ADG mbH, Mannheim, Germany
// All rights reserved
//
// Distribute freely, except: don't remove my name from the source or
// documentation (don't take credit for my work), mark your changes (don't
// get me blamed for your possible bugs), don't alter or remove this
// notice.
// No warrantee of any kind, express or implied, is included with this
// software; use at your own risk, responsibility for damages (if any) to
// anyone resulting from the use of this software rests entirely with the
// user.
//
// Send bug reports, bug fixes, enhancements, requests, flames, etc., and
// I'll try to keep a version up to date. I can be reached as follows:
// J.Koenig@adg.de (company site)
// Joerg.Koenig@rhein-neckar.de (private site)
/////////////////////////////////////////////////////////////////////////////
//
// MODIFIED BY TODD C. WILSON FOR THE ROAD RUNNER NT LOGIN SERVICE.
// HOWEVER, THESE MODIFICATIONS ARE BROADER IN SCOPE AND USAGE AND CAN BE USED
// IN OTHER PROJECTS WITH NO CHANGES.
// MODIFIED LINES FLAGGED/BRACKETED BY "//!! TCW MOD"
//
/////////////////////////////////////////////////////////////////////////////
// last revised: $Date: 11.05.98 21:09 $, $Revision: 3 $
/////////////////////////////////////////////////////////////////////////////
// Acknoledgements:
// o Thanks to Victor Vogelpoel (VictorV@Telic.nl) for his bug-fixes
// and enhancements.
// o Thanks to Todd C. Wilson (todd@mediatec.com) for the
// "service" on Win95
//
// Changes:
// 01/21/99
// o Bug fixed in "DeregisterApplicationLog()"
// thanks to Grahame Willis (grahamew@questsoftware.com.au):
//
// 04/30/98
// o Added two more switches to handle command line arguments:
// -e will force a running service to stop (corresponding
// method in this class: virtual BOOL EndService();) and
// -s will force the service to start (method:
// virtual BOOL StartupService())
//
// 02/05/98
// o Added the methods "RegisterApplicationLog()" and
// "DeregisterApplicationLog()" (both virtual). The first one will be
// called from "InstallService()" and creates some registry-entries
// for a better event-log. The second one removes these entries when
// the service will uninstall (see "RemoveService()")
// o The service now obtains the security identifier of the current user
// and uses this SID for event-logging.
// o The memory allocated by "CommandLineToArgvW()" will now release
// (UNICODE version only)
// o The service now uses a simple message catalogue for a nicer
// event logging
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <crtdbg.h>
#include <io.h> //!! TCW MOD
#include <fcntl.h> //!! TCW MOD
#include "NTService.h"
#include "NTServiceEventLogMsg.h"
#ifndef RSP_SIMPLE_SERVICE
#define RSP_SIMPLE_SERVICE 1
#endif
#ifndef RSP_UNREGISTER_SERVICE
#define RSP_UNREGISTER_SERVICE 0
#endif
BOOL CNTService :: m_bInstance = FALSE;
static CNTService * gpTheService = 0; // the one and only instance
CNTService * AfxGetService() { return gpTheService; }
static LPCTSTR gszAppRegKey = TEXT("SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\");
static LPCTSTR gszWin95ServKey=TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\RunServices"); //!! TCW MOD
/////////////////////////////////////////////////////////////////////////////
// class CNTService -- construction/destruction
CNTService :: CNTService( LPCTSTR lpServiceName, LPCTSTR lpDisplayName )
: m_lpServiceName(lpServiceName)
, m_lpDisplayName(lpDisplayName ? lpDisplayName : lpServiceName)
, m_dwCheckPoint(0)
, m_dwErr(0)
, m_bDebug(FALSE)
, m_sshStatusHandle(0)
, m_dwControlsAccepted(SERVICE_ACCEPT_STOP)
, m_pUserSID(0)
, m_fConsoleReady(FALSE)
// parameters to the "CreateService()" function:
, m_dwDesiredAccess(SERVICE_ALL_ACCESS)
, m_dwServiceType(SERVICE_WIN32_OWN_PROCESS)
, m_dwStartType(SERVICE_AUTO_START)
, m_dwErrorControl(SERVICE_ERROR_NORMAL)
, m_pszLoadOrderGroup(0)
, m_dwTagID(0)
, m_pszDependencies(0)
, m_pszStartName(0)
, m_pszPassword(0)
{
_ASSERTE( ! m_bInstance );
OSVERSIONINFO vi;
vi.dwOSVersionInfoSize=sizeof(vi); // init this.
GetVersionEx(&vi); //lint !e534
m_bWinNT = (vi.dwPlatformId == VER_PLATFORM_WIN32_NT);
m_bInstance = TRUE;
gpTheService = this;
// SERVICE_STATUS members that rarely change
m_ssStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
m_ssStatus.dwServiceSpecificExitCode = 0;
if( m_bWinNT ) {
/////////////////////////////////////////////////////////////////////////
// Providing a SID (security identifier) was contributed by Victor
// Vogelpoel (VictorV@Telic.nl).
// The code from Victor was slightly modified.
// Get security information of current user
BYTE security_identifier_buffer[ 4096 ];
DWORD dwSizeSecurityIdBuffer = sizeof( security_identifier_buffer );
PSID user_security_identifier = NULL;
TCHAR sUserName[ 256 ];
DWORD dwSizeUserName = 255;
TCHAR sDomainName[ 256 ];
DWORD dwSizeDomainName = 255;
SID_NAME_USE sidTypeSecurityId;
::ZeroMemory( sUserName, sizeof( sUserName ) );
::ZeroMemory( sDomainName, sizeof( sDomainName ) );
::ZeroMemory( security_identifier_buffer, dwSizeSecurityIdBuffer );
::GetUserName( sUserName, &dwSizeUserName );
if( ::LookupAccountName(
0,
sUserName,
&security_identifier_buffer,
&dwSizeSecurityIdBuffer,
sDomainName,
&dwSizeDomainName,
&sidTypeSecurityId
)) {
if( ::IsValidSid( PSID(security_identifier_buffer) ) ) {
DWORD dwSidLen = ::GetLengthSid(PSID(security_identifier_buffer));
m_pUserSID = PSID(new BYTE [dwSidLen]);
::CopySid(dwSidLen, m_pUserSID, security_identifier_buffer);
_ASSERTE(::EqualSid(m_pUserSID, security_identifier_buffer));
}
}
}
/////////////////////////////////////////////////////////////////////////
}
CNTService :: ~CNTService() {
_ASSERTE( m_bInstance );
delete [] LPBYTE(m_pUserSID);
m_bInstance = FALSE;
gpTheService = 0;
}
/////////////////////////////////////////////////////////////////////////////
// class CNTService -- overridables
#define NEXT_ARG ((((*Argv)[2])==TEXT('\0'))?(--Argc,*++Argv):(*Argv)+2)
BOOL CNTService :: RegisterService( int argc, char ** argv ) {
BOOL (CNTService::* fnc)() = &CNTService::StartDispatcher;
DWORD Argc;
LPTSTR * Argv;
#ifdef UNICODE
Argv = CommandLineToArgvW(GetCommandLineW(), &Argc );
#else
Argc = (DWORD) argc;
Argv = argv;
#endif
while( ++Argv, --Argc ) {
if( Argv[0][0] == TEXT('-') ) {
switch( Argv[0][1] ) {
case TEXT('i'): // install the service
fnc = &CNTService::InstallService;
break;
case TEXT('l'): // login-account (only useful with -i)
m_pszStartName = NEXT_ARG;
break;
case TEXT('p'): // password (only useful with -i)
m_pszPassword = NEXT_ARG;
break;
case TEXT('u'): // uninstall the service
fnc = &CNTService::RemoveService;
break;
case TEXT('s'): // start the service
fnc = &CNTService::StartupService;
break;
case TEXT('e'): // end the service
fnc = &CNTService::EndService;
break;
case TEXT('d'): // debug the service
case TEXT('f'): //!! TCW MOD faceless non-service (Win95) mode
#ifdef UNICODE
::GlobalFree(HGLOBAL)Argv);
#endif
m_bDebug = TRUE;
// pass original parameters to DebugService()
return DebugService(argc, argv,(Argv[0][1]==TEXT('f'))); //!! TCW MOD faceless non-service (Win95) mode
}
}
}
#ifdef UNICODE
::GlobalFree(HGLOBAL)Argv);
#endif
//!! TCW MOD START - if Win95, run as faceless app.
if( fnc == &CNTSer
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
cvery_676059.rar (69个子文件)
TelnetClient
CTelnetView.h 3KB
CTelnet.001 5KB
HostDialog.h 1KB
CTelnet.clw 3KB
Release
CTelnet.rc 11KB
res
CTelnet.ico 1KB
CTelnet.rc2 399B
CTelnetDoc.ico 1KB
Toolbar.bmp 358B
下载说明.htm 5KB
CTelnetDoc.cpp 2KB
CTelnet.ncb 113KB
CTelnet.dsp 5KB
CTelnetView.cpp 11KB
ClientSocket.h 1KB
CTelnet.dsw 539B
HostDialog.cpp 986B
StdAfx.cpp 205B
MainFrm.cpp 2KB
resource.h 685B
CTelnet.plg 2KB
CTelnet.cpp 4KB
MainFrm.h 2KB
StdAfx.h 987B
CTelnetDoc.h 1KB
Debug
CTelnet.h 1KB
CTelnet.aps 30KB
CTelnet.opt 62KB
ClientSocket.cpp 1KB
TelnetSvrNT
CTelnetView.h 3KB
CTelnet.001 5KB
HostDialog.h 1KB
NTServiceEventLogMsg.rc 37B
CTelnet.clw 3KB
TelnetServer_NT.dsw 555B
Release
TelnetServer_NT.opt 62KB
telnetd.cpp 17KB
CTelnet.rc 11KB
res
CTelnet.ico 1KB
CTelnet.rc2 399B
CTelnetDoc.ico 1KB
Toolbar.bmp 358B
下载说明.htm 5KB
NTService.h 13KB
CTelnetDoc.cpp 2KB
CTelnet.ncb 113KB
CTelnetView.cpp 11KB
ClientSocket.h 1KB
MSG00000.bin 100B
TelnetServer_NT.plg 2KB
HostDialog.cpp 986B
NTServiceEventLogMsg.h 2KB
StdAfx.cpp 205B
MainFrm.cpp 2KB
resource.h 685B
CTelnet.plg 2KB
CTelnet.cpp 4KB
TelnetServer_NT.001 4KB
MainFrm.h 2KB
StdAfx.h 987B
CTelnetDoc.h 1KB
TelnetServer_NT.dsp 3KB
TelnetServer_NT.ncb 81KB
Debug
CTelnet.h 1KB
NTService.cpp 32KB
Main.cpp 3KB
CTelnet.aps 30KB
CTelnet.opt 63KB
ClientSocket.cpp 1KB
共 69 条
- 1
xujianlane
- 粉丝: 6
- 资源: 29
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页