summaryrefslogtreecommitdiffstats
path: root/lib/libnt
diff options
context:
space:
mode:
authorcvsadm <cvsadm>2005-01-21 00:44:34 +0000
committercvsadm <cvsadm>2005-01-21 00:44:34 +0000
commitb2093e3016027d6b5cf06b3f91f30769bfc099e2 (patch)
treecf58939393a9032182c4fbc4441164a9456e82f8 /lib/libnt
downloadds-b2093e3016027d6b5cf06b3f91f30769bfc099e2.tar.gz
ds-b2093e3016027d6b5cf06b3f91f30769bfc099e2.tar.xz
ds-b2093e3016027d6b5cf06b3f91f30769bfc099e2.zip
Moving NSCP Directory Server from DirectoryBranch to TRUNK, initial drop. (foxworth)ldapserver7x
Diffstat (limited to 'lib/libnt')
-rw-r--r--lib/libnt/Makefile27
-rw-r--r--lib/libnt/info.c81
-rw-r--r--lib/libnt/path.c266
-rw-r--r--lib/libnt/pmddeml.c375
-rw-r--r--lib/libnt/registry.c242
-rw-r--r--lib/libnt/service.c375
-rw-r--r--lib/libnt/tcpip.c145
7 files changed, 1511 insertions, 0 deletions
diff --git a/lib/libnt/Makefile b/lib/libnt/Makefile
new file mode 100644
index 00000000..2f12fe5b
--- /dev/null
+++ b/lib/libnt/Makefile
@@ -0,0 +1,27 @@
+#
+# BEGIN COPYRIGHT BLOCK
+# Copyright 2001 Sun Microsystems, Inc.
+# Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+# All rights reserved.
+# END COPYRIGHT BLOCK
+#
+#! gmake
+
+DEPTH = ../..
+
+CSRCS = info.c \
+ path.c \
+ pmddeml.c \
+ registry.c \
+ service.c \
+ tcpip.c \
+ $(NULL)
+
+OBJS = $(CSRCS:.c=.o)
+
+LIBRARY = libnt.$(LIB_SUFFIX)
+
+include $(DEPTH)/config/rules.mk
+
+export:: $(TARGETS)
+ $(INSTALL) -m 444 $(LIBRARY) $(DIST)/lib
diff --git a/lib/libnt/info.c b/lib/libnt/info.c
new file mode 100644
index 00000000..618b95c7
--- /dev/null
+++ b/lib/libnt/info.c
@@ -0,0 +1,81 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright 2001 Sun Microsystems, Inc.
+ * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+ * All rights reserved.
+ * END COPYRIGHT BLOCK **/
+#include <windows.h>
+#include "nt/ntos.h"
+
+OS_TYPE NS_WINAPI INFO_GetOperatingSystem ()
+{
+ OSVERSIONINFO versionInfo;
+ versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ GetVersionEx( &versionInfo );
+
+ switch ( versionInfo.dwPlatformId ) {
+ case VER_PLATFORM_WIN32s:
+ return OS_WIN32S;
+ case VER_PLATFORM_WIN32_WINDOWS:
+ return OS_WIN95;
+ case VER_PLATFORM_WIN32_NT:
+ return OS_WINNT;
+ default:
+ break;
+ }
+ return OS_UNKNOWN;
+}
+DWORD NS_WINAPI INFO_GetOSMajorVersion ()
+{
+ OSVERSIONINFO versionInfo;
+ versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ GetVersionEx( &versionInfo );
+
+ return versionInfo.dwMajorVersion;
+}
+DWORD NS_WINAPI INFO_GetOSMinorVersion ()
+{
+ OSVERSIONINFO versionInfo;
+ versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ GetVersionEx( &versionInfo );
+
+ return versionInfo.dwMinorVersion;
+}
+DWORD NS_WINAPI INFO_GetOSServicePack ()
+{
+ OSVERSIONINFO versionInfo;
+ char * servicePackString = "Service Pack ";
+ int servicePackStringLng = strlen(servicePackString);
+ int servicePackNumber = 0;
+
+ versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ GetVersionEx( &versionInfo );
+ if ( strncmp ( versionInfo.szCSDVersion, servicePackString, servicePackStringLng ) == 0 )
+ servicePackNumber = atoi ( &versionInfo.szCSDVersion[servicePackStringLng] );
+
+ return servicePackNumber;
+}
+void NS_WINAPI OS_GetComputerName (LPTSTR computerName, int nComputerNameLength )
+{
+ DWORD computerNameLength = nComputerNameLength;
+ GetComputerName( computerName, &computerNameLength );
+}
+
+PROCESSOR_TYPE NS_WINAPI OS_GetProcessor ()
+{
+ SYSTEM_INFO systemInfo;
+ GetSystemInfo( &systemInfo);
+
+ switch ( systemInfo.wProcessorArchitecture ) {
+ case PROCESSOR_ARCHITECTURE_INTEL:
+ return PROCESSOR_I386;
+ case PROCESSOR_ARCHITECTURE_MIPS:
+ return PROCESSOR_MIPS;
+ case PROCESSOR_ARCHITECTURE_ALPHA:
+ return PROCESSOR_ALPHA;
+ case PROCESSOR_ARCHITECTURE_PPC:
+ return PROCESSOR_PPC;
+ default:
+ break;
+ }
+ return PROCESSOR_UNKNOWN;
+}
diff --git a/lib/libnt/path.c b/lib/libnt/path.c
new file mode 100644
index 00000000..6691bc98
--- /dev/null
+++ b/lib/libnt/path.c
@@ -0,0 +1,266 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright 2001 Sun Microsystems, Inc.
+ * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+ * All rights reserved.
+ * END COPYRIGHT BLOCK **/
+/***********************************************************
+ * Path functions - removing ../ from path
+ **********************************************************/
+#include <windows.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <io.h> /* For _findfirst */
+#include <direct.h> /* For _rmdir */
+#include <errno.h>
+#include "nt/ntos.h"
+
+DWORD NS_WINAPI
+PATH_RemoveRelative ( char * path )
+{
+ char * src;
+ char * dst;
+
+ src = path;
+ dst = path;
+ while ( *src ) {
+ if ( *src == '.' ) {
+ if ( *(src+1) == '.' ) {
+ /* strip off the "../" */
+ src += 2;
+
+ /* back off least significant directory */
+ dst--;
+ if ( ( *dst == '\\' ) || ( *dst == '/' ) )
+ *dst--;
+ while ( dst > path ) {
+ if ( ( *dst == '\\' ) || ( *dst == '/' ) )
+ break;
+ dst--;
+ }
+ } else {
+ // remove single "."
+ }
+
+ } else
+ *dst++ = *src++;
+ }
+ *dst = '\0';
+
+ return TRUE;
+}
+DWORD NS_WINAPI
+PATH_ConvertNtSlashesToUnix( LPCTSTR lpszNtPath, LPSTR lpszUnixPath )
+{
+ if ( lpszNtPath == NULL )
+ return 0;
+
+ /* create reverse slashes and escape them */
+ while ( *lpszNtPath ) {
+ if ( *lpszNtPath == '\\' )
+ *lpszUnixPath = '/';
+ else
+ *lpszUnixPath = *lpszNtPath;
+ lpszNtPath++;
+ lpszUnixPath++;
+ }
+ *lpszUnixPath = '\0';
+ return 0;
+}
+
+static DWORD
+PATH_DeleteRecursivelyFoundFile ( char * fullFileName, char * path, char * fileName )
+{
+ if ( strcmp ( fileName, "." ) == 0)
+ return TRUE;
+
+ if ( strcmp ( fileName, ".." ) == 0)
+ return TRUE;
+
+ strcpy ( fullFileName, path );
+ strcat ( fullFileName, "\\" );
+ strcat ( fullFileName, fileName );
+ return PATH_DeleteRecursively ( fullFileName );
+}
+
+/* if the path specified is a file name, the file is deleted
+ * If the path specifies a directory, the directory is deleted
+ */
+DWORD NS_WINAPI
+PATH_DeleteRecursively ( char * path )
+{
+ int result;
+ unsigned short fileStatus;
+ struct _stat buf;
+ struct _finddata_t fileFound;
+ long hFile;
+ DWORD retStatus = TRUE;
+ char fullFileName[_MAX_PATH];
+ int error;
+
+ /* Check if statistics are valid: */
+ result = _stat( path, &buf );
+ if( result != 0 )
+ return TRUE; // file or directory does not exist
+
+ fileStatus = buf.st_mode & _S_IFMT;
+
+ /* check if regular file */
+ if ( fileStatus & _S_IFREG ) {
+ if ( remove ( path ) == -1 ) {
+ error = errno;
+ switch ( error ) {
+ case ENOENT:
+ break;
+
+ case EACCES:
+ break;
+
+ default:
+ break;
+ }
+
+ return FALSE;
+ }
+ return TRUE;
+ }
+ if ( (fileStatus & _S_IFDIR) == 0 )
+ return FALSE;
+
+
+ /* path contains a directory, delete all files recursively */
+ /* Find first .c file in current directory */
+ strcpy ( fullFileName, path );
+ strcat ( fullFileName, "\\*.*");
+ if( (hFile = _findfirst( fullFileName, &fileFound )) != -1L ) { /* directory contain files? */
+ if ( !PATH_DeleteRecursivelyFoundFile ( fullFileName, path, fileFound.name ) )
+ retStatus = FALSE;
+
+ /* Find the rest of the .c files */
+ while( _findnext( hFile, &fileFound ) == 0 ) {
+ if ( !PATH_DeleteRecursivelyFoundFile ( fullFileName, path, fileFound.name ) )
+ retStatus = FALSE;
+ }
+ _findclose( hFile );
+ }
+
+ /* remove the directory, now that it is empty */
+ if ( _rmdir( path ) == -1 )
+ retStatus = FALSE;
+ return retStatus;
+}
+/* GetNextFileInDirectory - gets next file in the directory
+ * Set hFile to zero, when you call it. The routine returns the
+ * next value for hFile. When the routine returns NULL, there is
+ * no more files
+ *
+ */
+DWORD NS_WINAPI
+PATH_GetNextFileInDirectory ( long hFile, char * path, char * lpFileName )
+{
+ int result;
+ unsigned short fileStatus;
+ struct _stat buf;
+ struct _finddata_t fileFound;
+ DWORD retStatus = TRUE;
+ char fullFileName[_MAX_PATH];
+
+ if ( hFile == 0 ) {
+ /* Check if statistics are valid: */
+ result = _stat( path, &buf );
+ if( result != 0 )
+ return 0; // file or directory does not exist
+
+ fileStatus = buf.st_mode & _S_IFMT;
+ if ( (fileStatus & _S_IFDIR) == 0 )
+ return 0;
+
+
+ /* path contains a directory, delete all files recursively */
+ /* Find first .c file in current directory */
+ strcpy ( fullFileName, path );
+ strcat ( fullFileName, "\\*.*");
+ if( (hFile = _findfirst( fullFileName, &fileFound )) == -1L )
+ return 0;
+ if ( ( strcmp ( fileFound.name , "." ) != 0)
+ && ( strcmp ( fileFound.name , ".." ) != 0) ) {
+ strcpy ( lpFileName, fileFound.name );
+ return hFile;
+ }
+ }
+
+ /* Find the rest of the .c files */
+ while( _findnext( hFile, &fileFound ) == 0 ) {
+ if ( ( strcmp ( fileFound.name , "." ) != 0)
+ && ( strcmp ( fileFound.name , ".." ) != 0) ) {
+ strcpy ( lpFileName, fileFound.name );
+ return hFile;
+ }
+ }
+
+ _findclose( hFile );
+ return 0;
+}
+/*---------------------------------------------------------------------------*\
+ *
+ * Function: PATH_GetNextSubDirectory
+ *
+ * Purpose: Gets next sub directory in the path
+ *
+ * Input:
+ * hFile: set to zero first time called; use return value for subsequent calls
+ * path: directory containing sub directories
+ * lpSubDirectoryName: buffer to store sub directorie name
+ * lpSubDirectoryPrefix: chars to exactly match begining of directory name
+ *
+ * Returns:
+ * hFile to be used on subsequent call (0, if no more directories)
+ *
+ * Comments:
+\*---------------------------------------------------------------------------*/
+DWORD NS_WINAPI
+PATH_GetNextSubDirectory( long hFile, char * path, char * lpSubDirectoryName, char * lpSubDirectoryPrefix )
+{
+ int result;
+ unsigned short fileStatus;
+ struct _stat buf;
+ char * subDirectoryPrefix;
+ char * p;
+ char fullFileName[_MAX_PATH];
+ BOOL bSubDirectoryFound;
+
+ do {
+ hFile = PATH_GetNextFileInDirectory ( hFile, path, lpSubDirectoryName );
+ if ( hFile == 0 )
+ return 0;
+
+ /* Check if file is a directory */
+ strcpy ( fullFileName, path );
+ strcat ( fullFileName, "\\" );
+ strcat ( fullFileName, lpSubDirectoryName );
+ result = _stat( fullFileName, &buf );
+ if( result == 0 ) {
+ fileStatus = buf.st_mode & _S_IFMT;
+ if ( (fileStatus & _S_IFDIR) == _S_IFDIR ) {
+
+ /* check if sub directory matches prefix */
+ bSubDirectoryFound = TRUE;
+ if ( lpSubDirectoryPrefix ) {
+ p = lpSubDirectoryName;
+ subDirectoryPrefix = lpSubDirectoryPrefix;
+ while ( *subDirectoryPrefix ) {
+ if ( *subDirectoryPrefix++ != *p++ ) {
+ bSubDirectoryFound = FALSE;
+ break;
+ }
+ }
+ }
+ if ( bSubDirectoryFound )
+ return hFile;
+ }
+ }
+ } while ( hFile );
+
+ return 0; // no more sub directories
+}
+
diff --git a/lib/libnt/pmddeml.c b/lib/libnt/pmddeml.c
new file mode 100644
index 00000000..cee541a1
--- /dev/null
+++ b/lib/libnt/pmddeml.c
@@ -0,0 +1,375 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright 2001 Sun Microsystems, Inc.
+ * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+ * All rights reserved.
+ * END COPYRIGHT BLOCK **/
+/****************************************************************************
+ PROGRAM: pmddeml.c
+
+ PURPOSE: DDEML interface with ProgMan
+
+****************************************************************************/
+
+#include <windows.h> // required for all Windows applications
+#include <ddeml.h> // required for DDEML
+#include <stdio.h> // required for strcpy and strlen
+#include "nt/ntos.h" // specific to this program
+
+BOOL PMDDEML_SendShellCommand (DWORD idInst, LPSTR lpCommand);
+
+HDDEDATA CALLBACK PMDDEML_DdeCallback( UINT uType, // transaction type
+ UINT uFmt, // clipboard data format
+ HCONV hconv, // handle of the conversation
+ HSZ hsz1, // handle of a string
+ HSZ hsz2, // handle of a string
+ HDDEDATA hdata,// handle of a global memory object
+ DWORD dwData1, // transaction-specific data
+ DWORD dwData2 // transaction-specific data
+ );
+/****************************************************************************
+ FUNCTION: PMDDEML_Open()
+
+ PURPOSE: Open PMDDEML interface
+
+ PARAMETERS:
+
+ RETURNS:
+ DWORD handle used in subsequent calls
+****************************************************************************/
+
+DWORD PMDDEML_Open ( void )
+{
+ DWORD idInst = 0L; // instance identifier
+
+ // register this app with the DDEML
+ if (DdeInitialize(&idInst, // receives instance ID
+ (PFNCALLBACK)PMDDEML_DdeCallback, // address of callback function
+ APPCMD_CLIENTONLY, // this is a client app
+ 0L)) // reserved
+ return 0;
+ return idInst;
+}
+/****************************************************************************
+ FUNCTION: PMDDEML_Close()
+
+ PURPOSE: Closes PMDDEML interface
+
+ PARAMETERS:
+ DWORD idInst handle returned by PMDDEML_Open
+
+ RETURNS:
+ TRUE, if successful
+****************************************************************************/
+
+BOOL PMDDEML_Close ( DWORD idInst )
+{
+ // free all DDEML resources associated with this app
+ return DdeUninitialize ( idInst );
+}
+/****************************************************************************
+ FUNCTION: PMDDEML_CreateProgramManagerGroup()
+
+ PURPOSE: Creates a program group
+
+ PARAMETERS:
+ DWORD idInst handle returned by PMDDEML_Open
+ LPCTSTR lpszGroupNamee name of group
+
+ RETURNS:
+ TRUE, if successful
+****************************************************************************/
+
+BOOL PMDDEML_CreateProgramManagerGroup ( DWORD idInst, LPCTSTR lpszGroupName )
+{
+ char szDDEMsg[256]; // instance identifier
+
+ if ( lpszGroupName == NULL )
+ return FALSE;
+
+ sprintf ( szDDEMsg, "[CreateGroup(%s)]", lpszGroupName );
+
+ if ( !PMDDEML_SendShellCommand(idInst, (LPSTR)szDDEMsg ) )
+ return FALSE;
+ return TRUE;
+}
+/****************************************************************************
+ FUNCTION: PMDDEML_DeleteProgramManagerGroup()
+
+ PURPOSE: Deletes a program group
+
+ PARAMETERS:
+ DWORD idInst handle returned by PMDDEML_Open
+ LPCTSTR lpszGroupNamee name of group
+
+ RETURNS:
+ TRUE, if successful
+****************************************************************************/
+
+BOOL PMDDEML_DeleteProgramManagerGroup ( DWORD idInst, LPCTSTR lpszGroupName )
+{
+ char szDDEMsg[256]; // instance identifier
+
+ if ( lpszGroupName == NULL )
+ return FALSE;
+
+ sprintf ( szDDEMsg, "[DeleteGroup(%s)]", lpszGroupName );
+
+ if ( !PMDDEML_SendShellCommand(idInst, (LPSTR)szDDEMsg ) )
+ return FALSE;
+ return TRUE;
+}
+
+BOOL PMDDEML_DeleteProgramCommonManagerGroup ( DWORD idInst,
+ LPCTSTR lpszGroupName )
+{
+ char szDDEMsg[256]; // instance identifier
+
+ if ( lpszGroupName == NULL )
+ return FALSE;
+
+ sprintf ( szDDEMsg, "[DeleteGroup(%s,1)]", lpszGroupName );
+
+ if ( !PMDDEML_SendShellCommand(idInst, (LPSTR)szDDEMsg ) )
+ return FALSE;
+ return TRUE;
+}
+
+/****************************************************************************
+ FUNCTION: PMDDEML_ShowProgramManagerGroup()
+
+ PURPOSE: Deletes a program group
+
+ PARAMETERS:
+ DWORD idInst handle returned by PMDDEML_Open
+ LPCTSTR lpszGroupNamee name of group
+
+ RETURNS:
+ TRUE, if successful
+****************************************************************************/
+
+BOOL PMDDEML_ShowProgramManagerGroup ( DWORD idInst, LPCTSTR lpszGroupName )
+{
+ char szDDEMsg[256]; // instance identifier
+
+ if ( lpszGroupName == NULL )
+ return FALSE;
+
+ sprintf ( szDDEMsg, "[ShowGroup(%s,1)]", lpszGroupName );
+
+ if ( !PMDDEML_SendShellCommand(idInst, (LPSTR)szDDEMsg ) )
+ return FALSE;
+ return TRUE;
+}
+
+BOOL PMDDEML_ShowProgramManagerCommonGroup ( DWORD idInst,
+ LPCTSTR lpszGroupName )
+{
+ char szDDEMsg[256]; // instance identifier
+
+ if ( lpszGroupName == NULL )
+ return FALSE;
+
+ sprintf ( szDDEMsg, "[ShowGroup(%s,1,1)]", lpszGroupName );
+
+ if ( !PMDDEML_SendShellCommand(idInst, (LPSTR)szDDEMsg ) )
+ return FALSE;
+ return TRUE;
+}
+
+/****************************************************************************
+ FUNCTION: PMDDEML_AddIconToProgramManagerGroup()
+
+ PURPOSE: Deletes icon a program group
+
+ PARAMETERS:
+ DWORD idInst handle returned by PMDDEML_Open
+ LPCTSTR lpszCmdLine title of icon in group
+ LPCTSTR lpszTitle title of icon in group
+ LPCTSTR lpszWorkingDir title of icon in group
+ BOOL bReplace True, if icon should be replaced
+
+ RETURNS:
+ TRUE, if successful
+****************************************************************************/
+
+BOOL PMDDEML_AddIconToProgramManagerGroup ( DWORD idInst, LPCTSTR lpszCmdLine,
+ LPCTSTR lpszTitle, LPCTSTR lpszIconPath, LPCTSTR lpszWorkingDir, BOOL bReplace )
+{
+ char szDDEMsg[256]; // instance identifier
+
+ if ( ( lpszCmdLine == NULL ) || ( lpszTitle == NULL ) || ( lpszWorkingDir == NULL ) )
+ return FALSE;
+
+ if ( bReplace ) {
+ sprintf ( szDDEMsg, "[ReplaceItem(%s)]", lpszTitle );
+ PMDDEML_SendShellCommand(idInst, (LPSTR)szDDEMsg );
+ }
+
+ sprintf ( szDDEMsg, "[AddItem(%s,%s,%s,,,,%s)]", lpszCmdLine, lpszTitle,
+ lpszIconPath, lpszWorkingDir );
+
+ if ( !PMDDEML_SendShellCommand(idInst, (LPSTR)szDDEMsg ) )
+ return FALSE;
+ return TRUE;
+}
+
+/****************************************************************************
+ FUNCTION: PMDDEML_DeleteIconInProgramManagerGroup()
+
+ PURPOSE: Deletes icon a program group
+
+ PARAMETERS:
+ DWORD idInst handle returned by PMDDEML_Open
+ LPCTSTR lpszTitle title of icon in group
+
+ RETURNS:
+ TRUE, if successful
+****************************************************************************/
+
+BOOL PMDDEML_DeleteIconInProgramManagerGroup ( DWORD idInst, LPCTSTR lpszTitle )
+{
+ char szDDEMsg[256]; // instance identifier
+
+ if ( lpszTitle == NULL )
+ return FALSE;
+
+ sprintf ( szDDEMsg, "[DeleteItem(%s)]", lpszTitle );
+
+ if ( !PMDDEML_SendShellCommand(idInst, (LPSTR)szDDEMsg ) )
+ return FALSE;
+ return TRUE;
+}
+
+/****************************************************************************
+ FUNCTION: PMDDEML_DdeCallback()
+
+ PURPOSE: Processes messages for DDEML conversation
+
+ PARAMETERS:
+ UINT uType, // transaction type
+ UINT uFmt, // clipboard data format
+ HCONV hconv, // handle of the conversation
+ HSZ hsz1, // handle of a string
+ HSZ hsz2, // handle of a string
+ HDDEDATA hdata,// handle of a global memory object
+ DWORD dwData1, // transaction-specific data
+ DWORD dwData2 // transaction-specific data
+
+ RETURNS:
+ HDDEDATA
+****************************************************************************/
+
+HDDEDATA CALLBACK PMDDEML_DdeCallback( UINT uType, // transaction type
+ UINT uFmt, // clipboard data format
+ HCONV hconv, // handle of the conversation
+ HSZ hsz1, // handle of a string
+ HSZ hsz2, // handle of a string
+ HDDEDATA hdata,// handle of a global memory object
+ DWORD dwData1, // transaction-specific data
+ DWORD dwData2 // transaction-specific data
+ )
+{
+ // Nothing need be done here...
+ return (HDDEDATA)NULL;
+}
+
+
+/****************************************************************************
+ FUNCTION: PMDDEML_SendShellCommand()
+
+ PURPOSE: Sends the given command string to Program Manager
+
+ PARAMETERS:
+ LPSTR - pointer to command string
+
+ RETURNS:
+ BOOL - TRUE if this function succeeds, FALSE otherwise
+****************************************************************************/
+
+BOOL PMDDEML_SendShellCommand (DWORD idInst, // instance identifier
+ LPSTR lpCommand) // command string to execute
+{
+ HSZ hszServTop; // Service and Topic name are "PROGMAN"
+ HCONV hconv; // handle of conversation
+ int nLen; // length of command string
+ HDDEDATA hData; // return value of DdeClientTransaction
+ DWORD dwResult; // result of transaction
+ BOOL bResult=FALSE; // TRUE if this function is successful
+
+ // create string handle to service/topic
+ hszServTop = DdeCreateStringHandle(idInst, "PROGMAN", CP_WINANSI);
+
+ // attempt to start conversation with server app
+ if ((hconv = DdeConnect(idInst, hszServTop, hszServTop, NULL))!= NULL)
+ {
+ // get length of the command string
+ nLen = lstrlen((LPSTR)lpCommand);
+
+ // send command to server app
+ hData = DdeClientTransaction((LPBYTE)lpCommand, // data to pass
+ nLen + 1, // length of data
+ hconv, // handle of conversation
+ NULL, // handle of name-string
+ CF_TEXT, // clipboard format
+ XTYP_EXECUTE, // transaction type
+ 1000, // timeout duration
+ &dwResult); // points to transaction result
+
+ if (hData)
+ bResult = TRUE;
+
+ // end conversation
+ DdeDisconnect(hconv);
+ }
+
+ // free service/topic string handle
+ DdeFreeStringHandle(idInst, hszServTop);
+
+ return bResult;
+}
+
+
+/****************************************************************************
+ FUNCTION: PMDDEML_GetProgramGroupInfo()
+
+ PURPOSE: Gets group info from progman
+
+ PARAMETERS:
+ LPSTR - pointer to command string
+
+ RETURNS:
+ BOOL - TRUE if this function succeeds, FALSE otherwise
+****************************************************************************/
+BOOL PMDDEML_GetProgramGroupInfo(DWORD idInst, LPSTR lpProgramGroup, char *szBuffer, DWORD cbBuffer)
+{
+ HSZ hszServTop; // Service and Topic name are "PROGMAN"
+ HSZ hszTopic; // Topic name is the lpRequest
+ HCONV hconv; // handle of conversation
+ HDDEDATA hData = 0; // return value of DdeClientTransaction
+ DWORD dwResult; // result of transaction
+ BOOL bResult=FALSE; // TRUE if this function is successful
+
+ hszServTop = DdeCreateStringHandle(idInst, "PROGMAN", CP_WINANSI);
+ hszTopic = DdeCreateStringHandle(idInst, lpProgramGroup, CP_WINANSI);
+
+ if((hconv = DdeConnect(idInst, hszServTop, hszServTop, NULL)) != NULL)
+ {
+ hData = DdeClientTransaction((LPBYTE)NULL, // data to pass
+ 0L, // length of data
+ hconv, // handle of conversation
+ hszTopic, // handle of name-string
+ CF_TEXT, // clipboard format
+ XTYP_REQUEST, // transaction type
+ 5000, // timeout duration
+ &dwResult); // points to transaction result
+
+ bResult = (BOOL)DdeGetData(hData, (void FAR*)szBuffer, cbBuffer, 0);
+ DdeDisconnect(hconv);
+ }
+
+ // free service/topic string handle
+ DdeFreeStringHandle(idInst, hszServTop);
+ DdeFreeStringHandle(idInst, hszTopic);
+
+ return bResult;
+}
diff --git a/lib/libnt/registry.c b/lib/libnt/registry.c
new file mode 100644
index 00000000..2e6ec639
--- /dev/null
+++ b/lib/libnt/registry.c
@@ -0,0 +1,242 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright 2001 Sun Microsystems, Inc.
+ * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+ * All rights reserved.
+ * END COPYRIGHT BLOCK **/
+// ERROR.C
+//
+// This file contains the functions needed to install the httpd server.
+// They are as follows.
+//
+// getreg.c
+//
+// This file has the function needed to get a particular value of a key from the registry...
+// 1/16/95 aruna
+//
+
+#include <windows.h>
+#include "nt/ntos.h"
+
+BOOL NS_WINAPI
+REG_CheckIfKeyExists( HKEY hKey, LPCTSTR key )
+{
+ HKEY hQueryKey;
+
+ if (RegOpenKeyEx(hKey, key, 0, KEY_ALL_ACCESS,
+ &hQueryKey) != ERROR_SUCCESS) {
+ return FALSE;
+ }
+
+ RegCloseKey(hQueryKey);
+ return TRUE;
+}
+
+BOOL NS_WINAPI
+REG_GetRegistryParameter(
+ HKEY hKey,
+ LPCTSTR registryKey,
+ LPTSTR QueryValueName,
+ LPDWORD ValueType,
+ LPBYTE ValueBuffer,
+ LPDWORD ValueBufferSize
+ )
+{
+ HKEY hQueryKey;
+
+ if (RegOpenKeyEx(hKey, registryKey, 0, KEY_ALL_ACCESS,
+ &hQueryKey) != ERROR_SUCCESS) {
+
+ return FALSE;
+ }
+
+ if (RegQueryValueEx(hQueryKey, QueryValueName, 0,
+ ValueType, ValueBuffer, ValueBufferSize) != ERROR_SUCCESS) {
+ RegCloseKey(hQueryKey);
+ return FALSE;
+ }
+
+ RegCloseKey(hQueryKey);
+ return TRUE;
+}
+
+BOOL NS_WINAPI
+REG_CreateKey( HKEY hKey, LPCTSTR registryKey )
+{
+ HKEY hNewKey;
+
+ if ( RegCreateKey (hKey, registryKey, &hNewKey) != ERROR_SUCCESS) {
+ return FALSE;
+ }
+
+ RegCloseKey(hNewKey);
+ return TRUE;
+}
+
+BOOL NS_WINAPI
+REG_DeleteKey( HKEY hKey, LPCTSTR registryKey )
+{
+ HKEY hQueryKey;
+ DWORD dwNumberOfSubKeys;
+ char registrySubKey[256];
+ DWORD i;
+
+ /* if key does not exist, then consider it deleted */
+ if ( !REG_CheckIfKeyExists( hKey, registryKey ) )
+ return TRUE;
+
+ if ( !REG_GetSubKeysInfo( hKey, registryKey, &dwNumberOfSubKeys, NULL ) )
+ return FALSE;
+
+ if ( dwNumberOfSubKeys ) {
+ if (RegOpenKeyEx(hKey, registryKey, 0, KEY_ALL_ACCESS,
+ &hQueryKey) != ERROR_SUCCESS) {
+ return FALSE;
+ }
+
+ // loop through all sub keys and delete the subkeys (recursion)
+ for ( i=0; i<dwNumberOfSubKeys; i++ ) {
+ if ( RegEnumKey( hQueryKey, 0, registrySubKey, sizeof(registrySubKey) ) != ERROR_SUCCESS) {
+ RegCloseKey(hQueryKey);
+ return FALSE;
+ }
+ if ( !REG_DeleteKey( hQueryKey, registrySubKey ) ) {
+ RegCloseKey(hQueryKey);
+ return FALSE;
+ }
+ }
+ RegCloseKey(hQueryKey);
+ }
+
+ if ( RegDeleteKey (hKey, registryKey) != ERROR_SUCCESS) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+BOOL NS_WINAPI
+REG_GetSubKey( HKEY hKey, LPCTSTR registryKey, DWORD nSubKeyIndex, LPTSTR registrySubKeyBuffer, DWORD subKeyBufferSize )
+{
+ HKEY hQueryKey;
+
+ if (RegOpenKeyEx(hKey, registryKey, 0, KEY_ALL_ACCESS,
+ &hQueryKey) != ERROR_SUCCESS) {
+ return FALSE;
+ }
+
+ if ( RegEnumKey( hQueryKey, nSubKeyIndex, registrySubKeyBuffer, subKeyBufferSize ) != ERROR_SUCCESS) {
+ RegCloseKey(hQueryKey);
+ return FALSE;
+ }
+
+ RegCloseKey(hQueryKey);
+ return TRUE;
+}
+
+BOOL NS_WINAPI
+REG_GetSubKeysInfo( HKEY hKey, LPCTSTR registryKey, LPDWORD lpdwNumberOfSubKeys, LPDWORD lpdwMaxSubKeyLength )
+{
+ HKEY hQueryKey;
+ char szClass[256]; // address of buffer for class string
+ DWORD cchClass; // address of size of class string buffer
+ DWORD cSubKeys; // address of buffer for number of subkeys
+ DWORD cchMaxSubkey; // address of buffer for longest subkey name length
+ DWORD cchMaxClass; // address of buffer for longest class string length
+ DWORD cValues; // address of buffer for number of value entries
+ DWORD cchMaxValueName; // address of buffer for longest value name length
+ DWORD cbMaxValueData; // address of buffer for longest value data length
+ DWORD cbSecurityDescriptor; // address of buffer for security descriptor length
+ FILETIME ftLastWriteTime; // address of buffer for last write time
+
+
+ if (RegOpenKeyEx(hKey, registryKey, 0, KEY_ALL_ACCESS,
+ &hQueryKey) != ERROR_SUCCESS) {
+ return FALSE;
+ }
+
+ if ( RegQueryInfoKey( hQueryKey, // handle of key to query
+ (char*)&szClass, // address of buffer for class string
+ &cchClass, // address of size of class string buffer
+ NULL, // reserved
+ &cSubKeys, // address of buffer for number of subkeys
+ &cchMaxSubkey, // address of buffer for longest subkey name length
+ &cchMaxClass, // address of buffer for longest class string length
+ &cValues, // address of buffer for number of value entries
+ &cchMaxValueName, // address of buffer for longest value name length
+ &cbMaxValueData, // address of buffer for longest value data length
+ &cbSecurityDescriptor, // address of buffer for security descriptor length
+ &ftLastWriteTime // address of buffer for last write time
+ ) != ERROR_SUCCESS) {
+ RegCloseKey(hQueryKey);
+ return FALSE;
+ }
+
+ // return desired information
+ if ( lpdwNumberOfSubKeys )
+ *lpdwNumberOfSubKeys = cSubKeys;
+ if ( lpdwMaxSubKeyLength )
+ *lpdwMaxSubKeyLength = cchMaxSubkey;
+
+ RegCloseKey(hQueryKey);
+ return TRUE;
+}
+
+BOOL NS_WINAPI
+REG_SetRegistryParameter(
+ HKEY hKey,
+ LPCTSTR registryKey,
+ LPTSTR valueName,
+ DWORD valueType,
+ LPCTSTR ValueString,
+ DWORD valueStringLength
+ )
+{
+ HKEY hQueryKey;
+
+ if (RegOpenKeyEx(hKey, registryKey, 0, KEY_ALL_ACCESS,
+ &hQueryKey) != ERROR_SUCCESS) {
+ return FALSE;
+ }
+
+ if ( RegSetValueEx( hQueryKey, valueName, 0, valueType, (CONST BYTE *)ValueString,
+ valueStringLength ) != ERROR_SUCCESS) {
+ RegCloseKey(hQueryKey);
+ return FALSE;
+ }
+
+ RegCloseKey(hQueryKey);
+ return TRUE;
+}
+
+
+
+
+BOOL NS_WINAPI
+REG_DeleteValue( HKEY hKey, LPCTSTR registryKey, LPCSTR valueName )
+{
+ HKEY hQueryKey;
+ DWORD ValueBufferSize = 256;
+ char ValueBuffer[256];
+ DWORD i, ValueType;
+
+ /* if key does not exist, then consider it deleted */
+ if (RegOpenKeyEx(hKey, registryKey, 0, KEY_ALL_ACCESS,
+ &hQueryKey) != ERROR_SUCCESS) {
+ return FALSE;
+ }
+
+ /* if valuename does not exist, then consider it deleted */
+ if (RegQueryValueEx(hQueryKey, valueName, 0,
+ &ValueType, ValueBuffer, &ValueBufferSize) != ERROR_SUCCESS) {
+ RegCloseKey(hQueryKey);
+ return TRUE;
+ }
+
+ if (RegDeleteValue(hQueryKey, valueName) != ERROR_SUCCESS) {
+ RegCloseKey(hQueryKey);
+ return FALSE;
+ }
+
+ RegCloseKey(hQueryKey);
+ return TRUE;
+}
diff --git a/lib/libnt/service.c b/lib/libnt/service.c
new file mode 100644
index 00000000..1bfc5a5e
--- /dev/null
+++ b/lib/libnt/service.c
@@ -0,0 +1,375 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright 2001 Sun Microsystems, Inc.
+ * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+ * All rights reserved.
+ * END COPYRIGHT BLOCK **/
+#include <windows.h>
+#include "nt/ntos.h"
+
+#define SERVRET_ERROR 0
+#define SERVRET_INSTALLED 1
+#define SERVRET_STARTING 2
+#define SERVRET_STARTED 3
+#define SERVRET_STOPPING 4
+#define SERVRET_REMOVED 5
+
+
+DWORD NS_WINAPI
+SERVICE_GetNTServiceStatus(LPCTSTR szServiceName, LPDWORD lpLastError )
+{
+ SERVICE_STATUS ServiceStatus;
+ SC_HANDLE schService = NULL;
+ SC_HANDLE schSCManager = NULL;
+ DWORD lastError = 0;
+ int ret = 0;
+
+ //ereport(LOG_INFORM, "open SC Manager");
+ if ((schSCManager = OpenSCManager(
+ NULL, // machine (NULL == local)
+ NULL, // database (NULL == default)
+ SC_MANAGER_ALL_ACCESS // access required
+ )) == NULL ) {
+ lastError = GetLastError();
+ ret = SERVRET_ERROR;
+ goto finish;
+ }
+
+ schService = OpenService(schSCManager, szServiceName, SERVICE_ALL_ACCESS);
+
+ if (schService == NULL ) {
+ lastError = GetLastError();
+ if (lastError == ERROR_SERVICE_DOES_NOT_EXIST) {
+ lastError = 0;
+ ret = SERVRET_REMOVED;
+ } else
+ ret = SERVRET_ERROR;
+ goto finish;
+ }
+
+ ret = ControlService(schService, SERVICE_CONTROL_INTERROGATE, &ServiceStatus);
+
+ if ( !ret ) {
+ lastError = GetLastError();
+ if ( lastError == ERROR_SERVICE_NOT_ACTIVE ) {
+ lastError = 0;
+ ret = SERVRET_INSTALLED;
+ } else
+ ret = SERVRET_ERROR;
+ goto finish;
+ }
+
+ switch ( ServiceStatus.dwCurrentState ) {
+ case SERVICE_STOPPED: ret = SERVRET_INSTALLED; break;
+ case SERVICE_START_PENDING: ret = SERVRET_STARTING; break;
+ case SERVICE_STOP_PENDING: ret = SERVRET_STOPPING; break;
+ case SERVICE_RUNNING: ret = SERVRET_STARTED; break;
+ case SERVICE_CONTINUE_PENDING: ret = SERVRET_STARTED; break;
+ case SERVICE_PAUSE_PENDING: ret = SERVRET_STARTED; break;
+ case SERVICE_PAUSED: ret = SERVRET_STARTED; break;
+ default: ret = SERVRET_ERROR; break;
+ }
+
+finish:
+ if ( schService)
+ CloseServiceHandle(schService);
+ if ( schSCManager)
+ CloseServiceHandle(schSCManager);
+ if ( lpLastError )
+ *lpLastError = lastError;
+ return ret;
+}
+
+DWORD NS_WINAPI
+SERVICE_InstallNTService(LPCTSTR szServiceName, LPCTSTR szServiceDisplayName, LPCTSTR szServiceExe )
+{
+ LPCTSTR lpszBinaryPathName = szServiceExe;
+ SC_HANDLE schService = NULL;
+ SC_HANDLE schSCManager = NULL;
+ int lastError = 0;
+ int ret = 0;
+
+
+ //ereport(LOG_INFORM, "open SC Manager");
+ if ((schSCManager = OpenSCManager(
+ NULL, // machine (NULL == local)
+ NULL, // database (NULL == default)
+ SC_MANAGER_ALL_ACCESS // access required
+ )) == NULL ) {
+ lastError = GetLastError();
+ goto finish;
+ }
+
+ /* check if service already exists */
+ schService = OpenService( schSCManager,
+ szServiceName,
+ SERVICE_ALL_ACCESS
+ );
+ if (schService) {
+ lastError = ERROR_SERVICE_EXISTS;
+ goto finish;
+ }
+
+ schService = CreateService(
+ schSCManager, // SCManager database
+ szServiceName, // name of service
+ szServiceDisplayName, // name to display
+ SERVICE_ALL_ACCESS, // desired access
+ SERVICE_WIN32_OWN_PROCESS |
+ SERVICE_INTERACTIVE_PROCESS, // service type
+ SERVICE_AUTO_START, //SERVICE_DEMAND_START, // start type
+ SERVICE_ERROR_NORMAL, // error control type
+ lpszBinaryPathName, // service's binary
+ NULL, // no load ordering group
+ NULL, // no tag identifier
+ NULL, // no dependencies
+ NULL, // LocalSystem account
+ NULL); // no password
+
+ if (schService == NULL) {
+ lastError = GetLastError();
+ }
+
+ // successfully installed service
+
+finish:
+ if ( schService)
+ CloseServiceHandle(schService);
+ if ( schSCManager)
+ CloseServiceHandle(schSCManager);
+ return lastError;
+}
+
+
+DWORD NS_WINAPI
+SERVICE_RemoveNTService(LPCTSTR szServiceName)
+{
+ SC_HANDLE schService = NULL;
+ SC_HANDLE schSCManager = NULL;
+ int lastError = 0;
+ int ret = 0;
+
+ //ereport(LOG_INFORM, "open SC Manager");
+ if ((schSCManager = OpenSCManager(
+ NULL, // machine (NULL == local)
+ NULL, // database (NULL == default)
+ SC_MANAGER_ALL_ACCESS // access required
+ )) == NULL ) {
+ lastError = GetLastError();
+ goto finish;
+ }
+
+ schService = OpenService(schSCManager, szServiceName, SERVICE_ALL_ACCESS);
+
+ if (schService == NULL ) {
+ lastError = GetLastError();
+ goto finish;
+ }
+
+ ret = DeleteService(schService);
+
+ if ( !ret) {
+ lastError = GetLastError();
+ goto finish;
+ }
+
+ // successfully removed service
+
+finish:
+ if ( schService)
+ CloseServiceHandle(schService);
+ if ( schSCManager)
+ CloseServiceHandle(schSCManager);
+ return lastError;
+}
+
+DWORD NS_WINAPI
+SERVICE_StartNTService(LPCTSTR szServiceName)
+{
+ SC_HANDLE schService = NULL;
+ SC_HANDLE schSCManager = NULL;
+ int lastError = 0;
+ int ret = 0;
+
+ //ereport(LOG_INFORM, "open SC Manager");
+ if ((schSCManager = OpenSCManager(
+ NULL, // machine (NULL == local)
+ NULL, // database (NULL == default)
+ SC_MANAGER_ALL_ACCESS // access required
+ )) == NULL ) {
+ lastError = GetLastError();
+ goto finish;
+ }
+
+ schService = OpenService(schSCManager, szServiceName, SERVICE_ALL_ACCESS);
+
+ if (schService == NULL ) {
+ lastError = GetLastError();
+ goto finish;
+ }
+
+ ret = StartService(schService, 0, NULL);
+
+ if ( !ret ) {
+ lastError = GetLastError();
+ goto finish;
+ }
+
+ // successfully started service
+
+
+finish:
+ if ( schService)
+ CloseServiceHandle(schService);
+ if ( schSCManager)
+ CloseServiceHandle(schSCManager);
+ return lastError;
+}
+
+DWORD NS_WINAPI
+SERVICE_StartNTServiceAndWait(LPCTSTR szServiceName, LPDWORD lpdwLastError)
+{
+ DWORD dwLastError;
+ DWORD dwStatus;
+ int i;
+
+ /* check if service is running */
+ dwStatus = SERVICE_GetNTServiceStatus( szServiceName, &dwLastError );
+ if ( dwStatus == SERVRET_STARTED )
+ return TRUE;
+
+ dwLastError = SERVICE_StartNTService( szServiceName );
+ if ( dwLastError != 0 ) {
+ goto errorExit;
+ }
+
+ for ( i=0; i<5; i++ ) {
+ // make sure the service got installed
+ dwStatus = SERVICE_GetNTServiceStatus( szServiceName, &dwLastError );
+ if ( dwStatus == SERVRET_ERROR) {
+ if ( dwLastError != ERROR_SERVICE_CANNOT_ACCEPT_CTRL )
+ goto errorExit;
+ } else if ( dwStatus == SERVRET_STARTED )
+ return TRUE;
+
+ Sleep ( 1000 );
+ }
+
+ dwLastError = 0;
+
+errorExit:
+ if ( lpdwLastError )
+ *lpdwLastError = dwLastError;
+ return FALSE;
+}
+
+DWORD NS_WINAPI
+SERVICE_StopNTService(LPCTSTR szServiceName)
+{
+ SC_HANDLE schService = NULL;
+ SC_HANDLE schSCManager = NULL;
+ int lastError = 0;
+ int ret = 0;
+ SERVICE_STATUS ServiceStatus;
+
+ //ereport(LOG_INFORM, "open SC Manager");
+ if ((schSCManager = OpenSCManager(
+ NULL, // machine (NULL == local)
+ NULL, // database (NULL == default)
+ SC_MANAGER_ALL_ACCESS // access required
+ )) == NULL ) {
+ lastError = GetLastError();
+ goto finish;
+ }
+
+ schService = OpenService(schSCManager, szServiceName, SERVICE_ALL_ACCESS);
+
+ if (schService == NULL ) {
+ lastError = GetLastError();
+ goto finish;
+ }
+
+ ret = ControlService(schService, SERVICE_CONTROL_STOP, &ServiceStatus);
+
+ if ( !ret ) {
+ lastError = GetLastError();
+ goto finish;
+ }
+
+ // server is stopping
+
+finish:
+ if ( schService)
+ CloseServiceHandle(schService);
+ if ( schSCManager)
+ CloseServiceHandle(schSCManager);
+ return lastError;
+}
+
+DWORD NS_WINAPI
+SERVICE_StopNTServiceAndWait(LPCTSTR szServiceName, LPDWORD lpdwLastError)
+{
+ DWORD dwLastError;
+ DWORD dwStatus;
+ int i;
+
+ /* check if service is running */
+ dwStatus = SERVICE_GetNTServiceStatus( szServiceName, &dwLastError );
+ if ( dwStatus != SERVRET_STARTED )
+ return TRUE;
+
+ for ( i=0; i<30; i++ ) {
+ dwLastError = SERVICE_StopNTService( szServiceName );
+ Sleep ( 1000 );
+
+ // make sure the service is stoppped and just installed
+ dwStatus = SERVICE_GetNTServiceStatus( szServiceName, &dwLastError );
+ Sleep ( 1000 );
+ if ( dwStatus == SERVRET_INSTALLED ) {
+ Sleep ( 1000 );
+ return TRUE;
+ }
+ }
+
+ if ( lpdwLastError )
+ *lpdwLastError = dwLastError;
+ return FALSE;
+}
+
+DWORD NS_WINAPI
+SERVICE_ReinstallNTService(LPCTSTR szServiceName, LPCTSTR szServiceDisplayName, LPCTSTR szServiceExe )
+{
+ DWORD dwLastError;
+ DWORD dwStatus;
+ int i;
+
+ for ( i=0; i< 5; i++ ) {
+
+ /* if service is running, stop it */
+ dwStatus = SERVICE_GetNTServiceStatus( szServiceName, &dwLastError );
+ if ( dwStatus == SERVRET_STARTED )
+ SERVICE_StopNTServiceAndWait( szServiceName, &dwLastError );
+
+ /* if service is installed, remove it */
+ dwStatus = SERVICE_GetNTServiceStatus( szServiceName, &dwLastError );
+ if ( dwStatus == SERVRET_INSTALLED )
+ SERVICE_RemoveNTService( szServiceName );
+
+ /* try and install the service again */
+ dwStatus = SERVICE_GetNTServiceStatus( szServiceName, &dwLastError );
+ if ( dwStatus == SERVRET_REMOVED )
+ SERVICE_InstallNTService( szServiceName, szServiceDisplayName, szServiceExe );
+
+ /* try and start the service again */
+ dwStatus = SERVICE_GetNTServiceStatus( szServiceName, &dwLastError );
+ if ( dwStatus == SERVRET_INSTALLED ) {
+ return NO_ERROR;
+ }
+ }
+
+ /* if no error reported, force an error */
+ if ( dwLastError == NO_ERROR )
+ dwLastError = (DWORD)-1;
+
+ return dwLastError;
+}
+
diff --git a/lib/libnt/tcpip.c b/lib/libnt/tcpip.c
new file mode 100644
index 00000000..e15ccdba
--- /dev/null
+++ b/lib/libnt/tcpip.c
@@ -0,0 +1,145 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright 2001 Sun Microsystems, Inc.
+ * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+ * All rights reserved.
+ * END COPYRIGHT BLOCK **/
+#include <windows.h>
+#include "nt/ntos.h"
+
+/*---------------------------------------------------------------------------*\
+ *
+ * Function: GetServerDefaultHostName
+ *
+ * Purpose: This function gets the default host name
+ *
+ * Input:
+ *
+ * Returns:
+ *
+ * Comments:
+\*---------------------------------------------------------------------------*/
+DWORD NS_WINAPI
+TCPIP_GetDefaultHostName( LPTSTR lpszFullHostName, LPTSTR lpszHostName, LPTSTR lpszDomainName )
+{
+ char * szKey;
+ char * szName;
+ DWORD dwValueType;
+ DWORD dwIpHostSize = 256;
+ char szIpHost[256];
+ DWORD dwIpDomainSize = 256;
+ char szIpDomain[256];
+ BOOL bWinNT;
+
+ /* get operating system */
+ switch ( INFO_GetOperatingSystem() ) {
+ case OS_WIN95: bWinNT = FALSE; break;
+ case OS_WINNT: bWinNT = TRUE; break;
+ default: return TCPIP_UNSUPPORTED_OS;
+ }
+
+
+#if 0
+ int lastError;
+ WSADATA WSAData;
+ if ( WSAStartup( 0x0101, &WSAData ) != 0 ) {
+ lastError = WSAGetLastError();
+ m_pMainWnd->MessageBox ( "TCP/IP must be installed.\nUse the Network Icon in Control Panel" );
+ return FALSE;
+ }
+ lastError = gethostname ( szIpHost, sizeof(szIpHost) );
+#endif
+
+ /* get list of all keys under Netscape */
+ if ( bWinNT )
+ szKey = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters";
+ else
+ szKey = "SYSTEM\\CurrentControlSet\\Services\\Vxd\\MSTCP";
+
+ if( !REG_CheckIfKeyExists( HKEY_LOCAL_MACHINE, szKey ) ) {
+ return TCPIP_NO_TCPIP;
+ }
+
+ /* get host name for computer. May have to get DHCP host name if empty */
+ szName = "Hostname";
+ if( !REG_GetRegistryParameter( HKEY_LOCAL_MACHINE, szKey, szName, &dwValueType, (LPBYTE)szIpHost, &dwIpHostSize ) ) {
+ szIpHost[0] = '\0';
+ }
+
+ /* get domain name for computer. May have to get DHCP host name if empty */
+ szName = "Domain";
+ if( !REG_GetRegistryParameter( HKEY_LOCAL_MACHINE, szKey, szName, &dwValueType, (LPBYTE)szIpDomain, &dwIpDomainSize ) ) {
+ dwIpDomainSize = 0;
+ }
+ if ( dwIpDomainSize == 0 ) {
+ szName = "DhcpDomain";
+ if( !REG_GetRegistryParameter( HKEY_LOCAL_MACHINE, szKey, szName, &dwValueType, (LPBYTE)szIpDomain, &dwIpDomainSize ) ) {
+ dwIpDomainSize = 0;
+ }
+ }
+
+ if ( lpszHostName )
+ strcpy ( lpszHostName, szIpHost );
+
+ strcpy ( lpszFullHostName, szIpHost );
+ if ( lpszDomainName ) {
+ if ( dwIpDomainSize == 0 )
+ *lpszDomainName = '\0';
+ else {
+ strcpy ( lpszDomainName, szIpDomain );
+ strcat ( lpszFullHostName, "." );
+ strcat ( lpszFullHostName, lpszDomainName );
+ }
+ }
+
+ return TCPIP_NO_ERROR;
+}
+/*---------------------------------------------------------------------------*\
+ *
+ * Function: TCPIP_VerifyHostName
+ *
+ * Purpose: This function validates the host name
+ *
+ * Input:
+ *
+ * Returns:
+ *
+ * Comments:
+\*---------------------------------------------------------------------------*/
+DWORD NS_WINAPI
+TCPIP_VerifyHostName( LPCTSTR lpszHostName )
+{
+ struct hostent *ent;
+ WSADATA wsd;
+ int lastError;
+
+ if(WSAStartup(MAKEWORD(1, 1), &wsd) != 0)
+ return TCPIP_NO_WINSOCK_DLL;
+
+ ent = gethostbyname ( lpszHostName );
+ lastError = WSAGetLastError();
+ WSACleanup();
+
+ if ( ent == NULL ) {
+ switch ( lastError ) {
+ case WSANOTINITIALISED: // A successful WSAStartup must occur before using this function.
+ break;
+ case WSAENETDOWN: // The Windows Sockets implementation has detected that the network subsystem has failed.
+ return TCPIP_NETWORK_DOWN;
+ case WSAHOST_NOT_FOUND: // Authoritative Answer Host not found.
+ return TCPIP_HOST_NOT_FOUND;
+ case WSATRY_AGAIN: // Non-Authoritative Host not found, or SERVERFAIL.
+ return TCPIP_HOST_SERVER_DOWN;
+ case WSANO_RECOVERY: // Nonrecoverable errors: FORMERR, REFUSED, NOTIMP.
+ return TCPIP_NETWORK_ERROR;
+ case WSANO_DATA: // Valid name, no data record of requested type.
+ return TCPIP_HOST_VALID_NAME;
+ case WSAEINPROGRESS: // A blocking Windows Sockets operation is in progress.
+ return TCPIP_NETWORK_ERROR;
+ case WSAEINTR: // The (blocking) call was canceled using
+ return TCPIP_NETWORK_ERROR;
+ default:
+ return TCPIP_NETWORK_ERROR;
+ }
+ }
+ return TCPIP_NO_ERROR;
+}