Initial win32 support
This commit is contained in:
34
bin/named/win32/include/named/ntservice.h
Normal file
34
bin/named/win32/include/named/ntservice.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 1999-2001 Internet Software Consortium.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
|
||||
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: ntservice.h,v 1.1 2001/07/18 03:43:18 mayer Exp $ */
|
||||
|
||||
#ifndef NTSERVICE_H
|
||||
#define NTSERVICE_H
|
||||
|
||||
#include <winsvc.h>
|
||||
|
||||
#define BIND_DISPLAY_NAME "ISC BIND"
|
||||
#define BIND_SERVICE_NAME "named"
|
||||
|
||||
void
|
||||
ntservice_init();
|
||||
void UpdateSCM(DWORD);
|
||||
void ServiceControl(DWORD dwCtrlCode);
|
||||
void
|
||||
ntservice_shutdown();
|
||||
#endif
|
||||
49
bin/named/win32/include/named/os.h
Normal file
49
bin/named/win32/include/named/os.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 1999-2001 Internet Software Consortium.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
|
||||
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: os.h,v 1.1 2001/07/18 03:43:18 mayer Exp $ */
|
||||
|
||||
#ifndef NS_OS_H
|
||||
#define NS_OS_H 1
|
||||
|
||||
#include <isc/types.h>
|
||||
|
||||
void
|
||||
ns_os_init(const char *progname);
|
||||
|
||||
void
|
||||
ns_os_daemonize(void);
|
||||
|
||||
void
|
||||
ns_os_chroot(const char *root);
|
||||
|
||||
void
|
||||
ns_os_inituserinfo(const char *username);
|
||||
|
||||
void
|
||||
ns_os_changeuser(void);
|
||||
|
||||
void
|
||||
ns_os_minprivs(void);
|
||||
|
||||
void
|
||||
ns_os_writepidfile(const char *filename);
|
||||
|
||||
void
|
||||
ns_os_shutdown(void);
|
||||
|
||||
#endif /* NS_OS_H */
|
||||
323
bin/named/win32/named.dsp
Normal file
323
bin/named/win32/named.dsp
Normal file
@@ -0,0 +1,323 @@
|
||||
# Microsoft Developer Studio Project File - Name="named" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=named - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "named.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "named.mak" CFG="named - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "named - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "named - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "named - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /MD /W3 /GX /O2 /I "./" /I "../../../" /I "../win32/include" /I "../include" /I "../../../lib/isc/win32" /I "../../../lib/isc/win32/include" /I "../../../lib/isc/include" /I "../../../lib/dns/win32/include" /I "../../../lib/dns/include" /I "../../../lib/dns/sec/dst/include" /I "../../../lib/isccc/include" /I "../../../lib/lwres/win32/include" /I "../../../lib/lwres/include" /I "../../../lib/isccfg/include" /D "WIN32" /D "NDEBUG" /D "__STDC__" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 user32.lib advapi32.lib kernel32.lib ws2_32.lib ../../../lib/isc/win32/Release/libisc.lib ../../../lib/dns/win32/Release/libdns.lib ../../../lib/isccc/win32/Release/libisccc.lib ../../../lib/lwres/win32/Release/liblwres.lib ../../../lib/isccfg/win32/Release/libisccfg.lib /nologo /subsystem:console /machine:I386 /out:"../../../Build/Release/named.exe"
|
||||
|
||||
!ELSEIF "$(CFG)" == "named - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "./" /I "../../../" /I "../win32/include" /I "../include" /I "../../../lib/isc/win32" /I "../../../lib/isc/win32/include" /I "../../../lib/isc/include" /I "../../../lib/dns/win32/include" /I "../../../lib/dns/include" /I "../../../lib/dns/sec/dst/include" /I "../../../lib/isccc/include" /I "../../../lib/lwres/win32/include" /I "../../../lib/lwres/include" /I "../../../lib/isccfg/include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "i386" /FR /FD /GZ /c
|
||||
# SUBTRACT CPP /X /YX
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 user32.lib advapi32.lib kernel32.lib ws2_32.lib ../../../lib/isc/win32/Debug/libisc.lib ../../../lib/dns/win32/Debug/libdns.lib ../../../lib/isccc/win32/Debug/libisccc.lib ../../../lib/lwres/win32/Debug/liblwres.lib ../../../lib/isccfg/win32/Debug/libisccfg.lib /nologo /subsystem:console /map /debug /machine:I386 /out:"../../../Build/Debug/named.exe" /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "named - Win32 Release"
|
||||
# Name "named - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\aclconf.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\client.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\config.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\control.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\controlconf.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\interfacemgr.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\listenlist.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\log.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\logconf.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\lwaddr.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\lwdclient.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\lwderror.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\lwdgabn.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\lwdgnba.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\lwdgrbn.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\lwdnoop.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\lwresd.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\lwsearch.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\main.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\notify.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ntservice.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\os.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\query.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\server.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\sortlist.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\tkeyconf.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\tsigconf.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\update.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\xfrout.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\zoneconf.c
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\include\named\aclconf.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\include\named\client.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\include\named\config.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\include\named\globals.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\include\named\interfacemgr.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\include\named\listenlist.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\include\named\log.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\include\named\logconf.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\include\named\lwaddr.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\include\named\lwdclient.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\include\named\lwresd.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\include\named\lwsearch.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\include\named\main.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\include\named\notify.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\include\named\ntservice.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\include\named\omapi.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\include\named\os.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\include\named\query.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\include\named\server.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\include\named\sortlist.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\include\named\tkeyconf.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\include\named\tsigconf.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\include\named\types.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\include\named\update.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\include\named\xfrout.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\include\named\zoneconf.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
29
bin/named/win32/named.dsw
Normal file
29
bin/named/win32/named.dsw
Normal file
@@ -0,0 +1,29 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "named"=".\named.dsp" - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
232
bin/named/win32/ntservice.c
Normal file
232
bin/named/win32/ntservice.c
Normal file
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* Copyright (C) 1999-2001 Internet Software Consortium.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
|
||||
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: ntservice.c,v 1.1 2001/07/18 03:43:18 mayer Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
#include <stdio.h>
|
||||
#include <isc/log.h>
|
||||
#include <named/ntservice.h>
|
||||
#include <named/main.h>
|
||||
|
||||
/* Handle to SCM for updating service status */
|
||||
static SERVICE_STATUS_HANDLE hServiceStatus = 0;
|
||||
static int foreground = FALSE;
|
||||
static char ConsoleTitle[128];
|
||||
|
||||
/*
|
||||
* Forward declarations
|
||||
*/
|
||||
void ServiceControl(DWORD dwCtrlCode);
|
||||
void GetArgs(int *, char ***, char ***);
|
||||
int main(int, char *[], char *[]); /* From ns_main.c */
|
||||
|
||||
/*
|
||||
* Here we change the entry point for the executable to bindmain() from main()
|
||||
* This allows us to invoke as a service or from the command line easily.
|
||||
*/
|
||||
#pragma comment(linker, "/entry:bindmain")
|
||||
|
||||
/*
|
||||
* This is the entry point for the executable
|
||||
* We can now call main() explicitly or via StartServiceCtrlDispatcher()
|
||||
* as we need to.
|
||||
*/
|
||||
int bindmain()
|
||||
{
|
||||
int rc,
|
||||
i = 1;
|
||||
|
||||
int argc;
|
||||
char **envp, **argv;
|
||||
|
||||
/*
|
||||
* We changed the entry point function, so we must initialize argv,
|
||||
* etc. ourselves. Ick.
|
||||
*/
|
||||
GetArgs(&argc, &argv, &envp);
|
||||
|
||||
/* Command line users should put -f in the options */
|
||||
while (argv[i]) {
|
||||
if(!strcmp(argv[i], "-f") || !strcmp(argv[i], "/f")) {
|
||||
foreground = TRUE;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (foreground) {
|
||||
/* run in console window */
|
||||
exit(main(argc, argv, envp));
|
||||
}
|
||||
else {
|
||||
/* Start up as service */
|
||||
char *SERVICE_NAME = BIND_SERVICE_NAME;
|
||||
|
||||
SERVICE_TABLE_ENTRY dispatchTable[] =
|
||||
{
|
||||
{ TEXT(SERVICE_NAME), (LPSERVICE_MAIN_FUNCTION)main},
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
rc = StartServiceCtrlDispatcher(dispatchTable);
|
||||
if (!rc)
|
||||
{
|
||||
fprintf(stderr, "Use -f to run from the command line.\n");
|
||||
exit(GetLastError());
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
/*
|
||||
* Initialize the Service by registering it
|
||||
*/
|
||||
void
|
||||
ntservice_init() {
|
||||
|
||||
if (!foreground) {
|
||||
/* Register handler with the SCM */
|
||||
hServiceStatus = RegisterServiceCtrlHandler(BIND_SERVICE_NAME,
|
||||
(LPHANDLER_FUNCTION)ServiceControl);
|
||||
if (!hServiceStatus) {
|
||||
ns_main_earlyfatal(
|
||||
"Could not register service control handler");
|
||||
UpdateSCM(SERVICE_STOPPED);
|
||||
exit(1);
|
||||
}
|
||||
UpdateSCM(SERVICE_RUNNING);
|
||||
}
|
||||
else {
|
||||
strcpy(ConsoleTitle, "BIND Version ");
|
||||
strcat(ConsoleTitle, VERSION);
|
||||
SetConsoleTitle(ConsoleTitle);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ntservice_shutdown() {
|
||||
UpdateSCM(SERVICE_STOPPED);
|
||||
}
|
||||
|
||||
/*
|
||||
* ServiceControl(): Handles requests from the SCM and passes them on
|
||||
* to named via signals
|
||||
*/
|
||||
void
|
||||
ServiceControl(DWORD dwCtrlCode) {
|
||||
/* Handle the requested control code */
|
||||
switch(dwCtrlCode) {
|
||||
|
||||
case SERVICE_CONTROL_INTERROGATE:
|
||||
UpdateSCM(0);
|
||||
break;
|
||||
|
||||
case SERVICE_CONTROL_STOP:
|
||||
UpdateSCM(SERVICE_STOPPED);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tell the Service Control Manager the state of the service
|
||||
*/
|
||||
void UpdateSCM(DWORD state) {
|
||||
SERVICE_STATUS ss;
|
||||
static DWORD dwState = SERVICE_STOPPED;
|
||||
|
||||
if (hServiceStatus) {
|
||||
if (state)
|
||||
dwState = state;
|
||||
|
||||
memset(&ss, 0, sizeof(SERVICE_STATUS));
|
||||
ss.dwServiceType |= SERVICE_WIN32_OWN_PROCESS;
|
||||
ss.dwCurrentState = dwState;
|
||||
ss.dwControlsAccepted = SERVICE_ACCEPT_STOP |
|
||||
SERVICE_ACCEPT_SHUTDOWN;
|
||||
ss.dwCheckPoint = 0;
|
||||
ss.dwServiceSpecificExitCode = 0;
|
||||
ss.dwWin32ExitCode = NO_ERROR;
|
||||
ss.dwWaitHint = dwState == SERVICE_STOP_PENDING ? 10000 : 1000;
|
||||
|
||||
if (!SetServiceStatus(hServiceStatus, &ss)) {
|
||||
ss.dwCurrentState = SERVICE_STOPPED;
|
||||
SetServiceStatus(hServiceStatus, &ss);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* C-runtime stuff used to initialize the app and
|
||||
* get argv, argc, envp
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int newmode;
|
||||
} _startupinfo;
|
||||
|
||||
_CRTIMP void __cdecl __set_app_type(int);
|
||||
_CRTIMP void __cdecl __getmainargs(int *, char ***, char ***, int,
|
||||
_startupinfo *);
|
||||
void __cdecl _setargv(void);
|
||||
|
||||
#ifdef _M_IX86
|
||||
/* Pentium FDIV adjustment */
|
||||
extern int _adjust_fdiv;
|
||||
extern int * _imp___adjust_fdiv;
|
||||
/* Floating point precision */
|
||||
extern void _setdefaultprecision();
|
||||
#endif
|
||||
|
||||
extern int _newmode; /* malloc new() handler mode */
|
||||
extern int _dowildcard; /* passed to __getmainargs() */
|
||||
|
||||
typedef void (__cdecl *_PVFV)(void);
|
||||
extern void __cdecl _initterm(_PVFV *, _PVFV *);
|
||||
extern _PVFV *__onexitbegin;
|
||||
extern _PVFV *__onexitend;
|
||||
extern _CRTIMP char **__initenv;
|
||||
|
||||
/*
|
||||
* Do the work that mainCRTStartup() would normally do
|
||||
*/
|
||||
void GetArgs(int *argc, char ***argv, char ***envp)
|
||||
{
|
||||
_startupinfo startinfo;
|
||||
|
||||
/*
|
||||
* Set the app type to Console (check CRT/SRC/INTERNAL.H:
|
||||
* #define _CONSOLE_APP 1)
|
||||
*/
|
||||
__set_app_type(1);
|
||||
|
||||
/* Mark this module as an EXE file */
|
||||
__onexitbegin = __onexitend = (_PVFV *)(-1);
|
||||
|
||||
startinfo.newmode = _newmode;
|
||||
__getmainargs(argc, argv, envp, _dowildcard, &startinfo);
|
||||
__initenv = *envp;
|
||||
|
||||
#ifdef _M_IX86
|
||||
_adjust_fdiv = * _imp___adjust_fdiv;
|
||||
_setdefaultprecision();
|
||||
#endif
|
||||
}
|
||||
219
bin/named/win32/os.c
Normal file
219
bin/named/win32/os.c
Normal file
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
* Copyright (C) 1999-2001 Internet Software Consortium.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
|
||||
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: os.c,v 1.1 2001/07/18 03:43:18 mayer Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <io.h>
|
||||
#include <process.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include <isc/print.h>
|
||||
#include <isc/result.h>
|
||||
#include <isc/string.h>
|
||||
#include <isc/ntpaths.h>
|
||||
|
||||
#include <named/main.h>
|
||||
#include <named/os.h>
|
||||
#include <named/globals.h>
|
||||
#include <named/ntservice.h>
|
||||
|
||||
|
||||
static char *pidfile = NULL;
|
||||
|
||||
static BOOL Initialized = FALSE;
|
||||
|
||||
void
|
||||
ns_paths_init()
|
||||
{
|
||||
if (!Initialized) {
|
||||
isc_ntpaths_init();
|
||||
}
|
||||
ns_g_conffile = isc_ntpaths_get(NAMED_CONF_PATH);
|
||||
lwresd_g_conffile = isc_ntpaths_get(LWRES_CONF_PATH);
|
||||
lwresd_g_resolvconffile = isc_ntpaths_get(RESOLV_CONF_PATH);
|
||||
ns_g_conffile = isc_ntpaths_get(NAMED_CONF_PATH);
|
||||
ns_g_defaultpidfile = isc_ntpaths_get(NAMED_PID_PATH);
|
||||
lwresd_g_defaultpidfile = isc_ntpaths_get(LWRESD_PID_PATH);
|
||||
|
||||
Initialized = TRUE;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
setup_syslog(const char *progname) {
|
||||
int options;
|
||||
|
||||
options = LOG_PID;
|
||||
#ifdef LOG_NDELAY
|
||||
options |= LOG_NDELAY;
|
||||
#endif
|
||||
|
||||
openlog(progname, options, LOG_DAEMON);
|
||||
}
|
||||
|
||||
void
|
||||
ns_os_init(const char *progname) {
|
||||
ns_paths_init();
|
||||
setup_syslog(progname);
|
||||
ntservice_init();
|
||||
}
|
||||
|
||||
void
|
||||
ns_os_daemonize(void) {
|
||||
int fd;
|
||||
|
||||
/*
|
||||
* Try to set stdin, stdout, and stderr to /dev/null, but press
|
||||
* on even if it fails.
|
||||
*
|
||||
* XXXMLG The close() calls here are unneeded on all but NetBSD, but
|
||||
* are harmless to include everywhere. dup2() is supposed to close
|
||||
* the FD if it is in use, but unproven-pthreads-0.16 is broken
|
||||
* and will end up closing the wrong FD. This will be fixed eventually,
|
||||
* and these calls will be removed.
|
||||
*/
|
||||
fd = open("NUL", O_RDWR, 0);
|
||||
if (fd != -1) {
|
||||
close(_fileno(stdin));
|
||||
(void)_dup2(fd, _fileno(stdin));
|
||||
close(_fileno(stdout));
|
||||
(void)_dup2(fd, _fileno(stdout));
|
||||
close(_fileno(stderr));
|
||||
(void)_dup2(fd, _fileno(stderr));
|
||||
if (fd != _fileno(stdin) &&
|
||||
fd != _fileno(stdout) &&
|
||||
fd != _fileno(stderr))
|
||||
(void)close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
static isc_boolean_t
|
||||
all_digits(const char *s) {
|
||||
if (*s == '\0')
|
||||
return (ISC_FALSE);
|
||||
while (*s != '\0') {
|
||||
if (!isdigit((*s)&0xff))
|
||||
return (ISC_FALSE);
|
||||
s++;
|
||||
}
|
||||
return (ISC_TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
ns_os_chroot(const char *root) {
|
||||
}
|
||||
|
||||
void
|
||||
ns_os_inituserinfo(const char *username) {
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
ns_os_changeuser(void) {
|
||||
}
|
||||
|
||||
void
|
||||
ns_os_minprivs(void) {
|
||||
}
|
||||
|
||||
static int
|
||||
safe_open(const char *filename, isc_boolean_t append) {
|
||||
int fd;
|
||||
struct stat sb;
|
||||
|
||||
if (stat(filename, &sb) == -1) {
|
||||
if (errno != ENOENT)
|
||||
return (-1);
|
||||
} else if ((sb.st_mode & S_IFREG) == 0)
|
||||
return (-1);
|
||||
|
||||
if (append)
|
||||
fd = open(filename, O_WRONLY|O_CREAT|O_APPEND,
|
||||
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
|
||||
else {
|
||||
(void)unlink(filename);
|
||||
fd = open(filename, O_WRONLY|O_CREAT|O_EXCL,
|
||||
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
|
||||
}
|
||||
return (fd);
|
||||
}
|
||||
|
||||
static void
|
||||
cleanup_pidfile(void) {
|
||||
if (pidfile != NULL) {
|
||||
(void)unlink(pidfile);
|
||||
free(pidfile);
|
||||
}
|
||||
pidfile = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
ns_os_writepidfile(const char *filename) {
|
||||
int fd;
|
||||
FILE *lockfile;
|
||||
size_t len;
|
||||
pid_t pid;
|
||||
|
||||
/*
|
||||
* The caller must ensure any required synchronization.
|
||||
*/
|
||||
|
||||
cleanup_pidfile();
|
||||
|
||||
len = strlen(filename);
|
||||
pidfile = malloc(len + 1);
|
||||
if (pidfile == NULL)
|
||||
ns_main_earlyfatal("couldn't malloc '%s': %s",
|
||||
filename, strerror(errno));
|
||||
/* This is safe. */
|
||||
strcpy(pidfile, filename);
|
||||
|
||||
fd = safe_open(filename, ISC_FALSE);
|
||||
if (fd < 0)
|
||||
ns_main_earlyfatal("couldn't open pid file '%s': %s",
|
||||
filename, strerror(errno));
|
||||
lockfile = fdopen(fd, "w");
|
||||
if (lockfile == NULL)
|
||||
ns_main_earlyfatal("could not fdopen() pid file '%s': %s",
|
||||
filename, strerror(errno));
|
||||
|
||||
pid = getpid();
|
||||
if (fprintf(lockfile, "%ld\n", (long)pid) < 0)
|
||||
ns_main_earlyfatal("fprintf() to pid file '%s' failed",
|
||||
filename);
|
||||
if (fflush(lockfile) == EOF)
|
||||
ns_main_earlyfatal("fflush() to pid file '%s' failed",
|
||||
filename);
|
||||
(void)fclose(lockfile);
|
||||
}
|
||||
|
||||
void
|
||||
ns_os_shutdown(void) {
|
||||
closelog();
|
||||
cleanup_pidfile();
|
||||
ntservice_shutdown(); /* This MUST be the last thing done */
|
||||
}
|
||||
Reference in New Issue
Block a user