summaryrefslogtreecommitdiffstats
path: root/ldap/libraries/libutil
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 /ldap/libraries/libutil
downloadds-ldapserver7x.tar.gz
ds-ldapserver7x.tar.xz
ds-ldapserver7x.zip
Moving NSCP Directory Server from DirectoryBranch to TRUNK, initial drop. (foxworth)ldapserver7x
Diffstat (limited to 'ldap/libraries/libutil')
-rw-r--r--ldap/libraries/libutil/Makefile70
-rw-r--r--ldap/libraries/libutil/getopt.c109
-rw-r--r--ldap/libraries/libutil/ntdebug.c51
-rw-r--r--ldap/libraries/libutil/ntevent.c183
-rw-r--r--ldap/libraries/libutil/ntreg.c105
-rw-r--r--ldap/libraries/libutil/ntresource.h31
-rw-r--r--ldap/libraries/libutil/ntstubs.c40
7 files changed, 589 insertions, 0 deletions
diff --git a/ldap/libraries/libutil/Makefile b/ldap/libraries/libutil/Makefile
new file mode 100644
index 00000000..6920ec86
--- /dev/null
+++ b/ldap/libraries/libutil/Makefile
@@ -0,0 +1,70 @@
+#
+# BEGIN COPYRIGHT BLOCK
+# Copyright 2001 Sun Microsystems, Inc.
+# Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+# All rights reserved.
+# END COPYRIGHT BLOCK
+#
+#
+# GNU Makefile for libutil
+#
+
+LDAP_SRC = ../..
+MCOM_ROOT = ../../../..
+
+NOSTDCLEAN=true # don't let nsconfig.mk define target clean
+NOSTDSTRIP=true # don't let nsconfig.mk define target strip
+NSPR20=true # probably should be defined somewhere else (not sure where)
+
+OBJDEST = $(OBJDIR)/lib/libutil
+LIBDIR = $(LDAP_LIBDIR)
+
+include $(MCOM_ROOT)/ldapserver/nsdefs.mk
+include $(MCOM_ROOT)/ldapserver/nsconfig.mk
+include $(LDAP_SRC)/nsldap.mk
+
+#
+# ntdebug.c currently not used
+#
+LIBUTIL_OBJS= getopt.o ntevent.o \
+ ntreg.o ntstubs.o
+
+ifeq ($(ARCH), WINNT)
+LIBUTIL_OBJS += crypt.o
+endif
+
+OBJS = $(addprefix $(OBJDEST)/, $(LIBUTIL_OBJS))
+
+LIBUTIL= $(addprefix $(LIBDIR)/, libutil.$(LIB_SUFFIX))
+
+INCLUDES += -I$(LDAP_SRC)/servers/slapd -I$(OBJDIR)/include
+
+SLAPDMESSAGES_H=$(MCOM_ROOT)/ldapserver/ldap/include/ntslapdmessages.h
+
+ifeq ($(LDAP_NO_LIBLCACHE),1)
+CFLAGS+=-DNO_LIBLCACHE
+endif
+
+clientSDK: all
+
+all: $(OBJDEST) $(SLAPDMESSAGES_H) $(LIBDIR) $(OBJS) $(LIBUTIL)
+
+$(LIBDIR):
+ $(MKDIR) $(LIBDIR)
+
+$(LIBUTIL): $(OBJS)
+ $(LINK_LIB)
+
+$(SLAPDMESSAGES_H):
+ @echo target: $@
+ cd $(MCOM_ROOT)/ldapserver/ldap/servers/slapd/ntmsgdll; $(MAKE) $(MFLAGS)
+
+veryclean: clean
+
+clean:
+ $(RM) $(OBJS)
+ $(RM) $(LIBUTIL)
+
+$(OBJDEST):
+ $(MKDIR) $(OBJDEST)
+
diff --git a/ldap/libraries/libutil/getopt.c b/ldap/libraries/libutil/getopt.c
new file mode 100644
index 00000000..612d78fe
--- /dev/null
+++ b/ldap/libraries/libutil/getopt.c
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 1987 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that: (1) source distributions retain this entire copyright
+ * notice and comment, and (2) distributions including binaries display
+ * the following acknowledgement: ``This product includes software
+ * developed by the University of California, Berkeley and its contributors''
+ * in the documentation or other materials provided with the distribution
+ * and in all advertising materials mentioning features or use of this
+ * software. Neither the name of the University nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#ifdef _WINDOWS
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)getopt.c 4.12 (Berkeley) 6/1/90";
+#endif /* LIBC_SCCS and not lint */
+
+#include <windows.h>
+#include <stdio.h>
+#include <string.h>
+#include "lber.h"
+#define index strchr
+#define rindex strrchr
+
+/*
+ * get option letter from argument vector
+ */
+int opterr = 1, /* if error message should be printed */
+ optind = 1, /* index into parent argv vector */
+ optopt; /* character checked for validity */
+char *optarg; /* argument associated with option */
+
+#define BADCH (int)'?'
+#define EMSG ""
+
+int getopt(int nargc, char *const *nargv, const char *ostr)
+{
+ static char *place = EMSG; /* option letter processing */
+ register char *oli; /* option letter list index */
+ char *p;
+
+ if (!*place) { /* update scanning pointer */
+ if (optind >= nargc || *(place = nargv[optind]) != '-') {
+ place = EMSG;
+ return(EOF);
+ }
+ if (place[1] && *++place == '-') { /* found "--" */
+ ++optind;
+ place = EMSG;
+ return(EOF);
+ }
+ } /* option letter okay? */
+ if ((optopt = (int)*place++) == (int)':' ||
+ !(oli = index(ostr, optopt))) {
+ /*
+ * if the user didn't specify '-' as an option,
+ * assume it means EOF.
+ */
+ if (optopt == (int)'-')
+ return(EOF);
+ if (!*place)
+ ++optind;
+ if (opterr) {
+ if (!(p = rindex(*nargv, '/')))
+ p = *nargv;
+ else
+ ++p;
+ (void)fprintf(stderr, "%s: illegal option -- %c\n",
+ p, optopt);
+ }
+ return(BADCH);
+ }
+ if (*++oli != ':') { /* don't need argument */
+ optarg = NULL;
+ if (!*place)
+ ++optind;
+ }
+ else { /* need an argument */
+ if (*place) /* no white space */
+ optarg = place;
+ else if (nargc <= ++optind) { /* no arg */
+ place = EMSG;
+ if (!(p = rindex(*nargv, '/')))
+ p = *nargv;
+ else
+ ++p;
+ if (opterr)
+ (void)fprintf(stderr,
+ "%s: option requires an argument -- %c\n",
+ p, optopt);
+ return(BADCH);
+ }
+ else /* white space */
+ optarg = nargv[optind];
+ place = EMSG;
+ ++optind;
+ }
+ return(optopt); /* dump back option letter */
+}
+
+#endif
diff --git a/ldap/libraries/libutil/ntdebug.c b/ldap/libraries/libutil/ntdebug.c
new file mode 100644
index 00000000..d0347e2d
--- /dev/null
+++ b/ldap/libraries/libutil/ntdebug.c
@@ -0,0 +1,51 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright 2001 Sun Microsystems, Inc.
+ * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+ * All rights reserved.
+ * END COPYRIGHT BLOCK **/
+/******************************************************
+ *
+ * ntdebug.c - Sends debug output to window and stdout
+ * on Win32 platforms.
+ *
+ ******************************************************/
+
+#if defined( _WIN32 )
+#include <windows.h>
+#include <time.h>
+#include <stdio.h>
+#if defined( SLAPD_LOGGING )
+#include "slap.h"
+#include "proto-slap.h"
+#else
+#include "ldap.h"
+#include "ldaplog.h"
+#endif
+int slapd_ldap_debug = LDAP_DEBUG_ANY;
+FILE *error_logfp = NULL;
+
+void LDAPDebug( int level, char *fmt, ... )
+{
+ va_list arg_ptr;
+ va_start( arg_ptr, fmt );
+ if ( slapd_ldap_debug & level )
+ {
+ char szFormattedString[512];
+ _vsnprintf( szFormattedString, sizeof( szFormattedString ), fmt, arg_ptr );
+
+#if defined( LDAP_DEBUG )
+ /* Send to debug window ...*/
+ OutputDebugString( szFormattedString );
+
+ /* ... and to stderr */
+ fprintf( stderr, szFormattedString );
+#endif
+#if defined( SLAPD_LOGGING )
+ if ( error_logfp != NULL )
+ slapd_log_error( error_logfp, szFormattedString );
+#endif
+ }
+ va_end( arg_ptr );
+
+}
+#endif
diff --git a/ldap/libraries/libutil/ntevent.c b/ldap/libraries/libutil/ntevent.c
new file mode 100644
index 00000000..2b05dd9d
--- /dev/null
+++ b/ldap/libraries/libutil/ntevent.c
@@ -0,0 +1,183 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright 2001 Sun Microsystems, Inc.
+ * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+ * All rights reserved.
+ * END COPYRIGHT BLOCK **/
+
+#ifdef _WIN32
+
+#include <windows.h>
+#include <stdio.h>
+#include "ldap.h"
+#include "regparms.h"
+
+HANDLE hSlapdEventSource;
+LPTSTR pszServerName;
+
+void ReportSlapdEvent(WORD wEventType, DWORD dwIdEvent, WORD wNumInsertStrings,
+ char *pszStrings)
+{
+ LPCTSTR lpszStrings[64];
+ BOOL bSuccess;
+
+ if( hSlapdEventSource )
+ {
+ if( pszServerName )
+ lpszStrings[0] = (LPCTSTR)pszServerName;
+
+ if( pszStrings != NULL)
+ lpszStrings[1] = (LPCTSTR)pszStrings;
+
+ wNumInsertStrings++;
+
+ /* Now report the event, which will add this event to the event log */
+ bSuccess = ReportEvent(hSlapdEventSource, /* event-log handle */
+ wEventType, /* event type */
+ 0, /* category zero */
+ dwIdEvent, /* event ID */
+ NULL, /* no user SID */
+ wNumInsertStrings, /* number of substr */
+ 0, /* no binary data */
+ lpszStrings, /* string array */
+ NULL); /* address of data */
+ }
+
+} /* ReportSlapdEvent */
+
+BOOL ReportSlapdStatusToSCMgr(
+ SERVICE_STATUS *serviceStatus,
+ SERVICE_STATUS_HANDLE serviceStatusHandle,
+ HANDLE Event,
+ DWORD dwCurrentState,
+ DWORD dwWin32ExitCode,
+ DWORD dwCheckPoint,
+ DWORD dwWaitHint)
+{
+ /* Disable control requests until the service is started. */
+ if (dwCurrentState == SERVICE_START_PENDING)
+ serviceStatus->dwControlsAccepted = 0;
+ else
+ serviceStatus->dwControlsAccepted = SERVICE_ACCEPT_STOP |
+ SERVICE_ACCEPT_PAUSE_CONTINUE;
+
+ serviceStatus->dwCurrentState = dwCurrentState;
+ serviceStatus->dwWin32ExitCode = dwWin32ExitCode;
+ serviceStatus->dwCheckPoint = dwCheckPoint;
+
+ serviceStatus->dwWaitHint = dwWaitHint;
+
+ /* Report the status of the service to the service control manager. */
+ return SetServiceStatus( serviceStatusHandle, serviceStatus);
+
+} /* ReportSlapdStatusToSCMgr */
+
+// This is a routine that we use to check for multiple instances of a server with
+// the same id. We cannot use a shared data section to keep count of instances since
+// there will be multiple instances of the server running. MS recommends using a
+// sync object to do this. Thus we attempt to create an object with same NAME
+// but different TYPE as the server "Done" event.We have a small race condition
+// between the check and the creation of the "Done" event.
+
+BOOL
+MultipleInstances()
+{
+ HANDLE hServDoneSemaphore;
+ DWORD result;
+ CHAR ErrMsg[1024];
+ char szDoneEvent[256];
+
+ if( !pszServerName )
+ return FALSE;
+
+ sprintf(szDoneEvent, "NS_%s", pszServerName);
+
+ hServDoneSemaphore = CreateSemaphore(
+ NULL, // security attributes
+ 0, // initial count for semaphore
+ 1, // maximum count for semaphore
+ szDoneEvent);
+
+ if ( hServDoneSemaphore == NULL) {
+
+ result = GetLastError();
+ if (result == ERROR_INVALID_HANDLE) {
+
+ sprintf(ErrMsg, "Netscape Server %s is already"
+ " running. Terminating this instance.", pszServerName);
+
+ MessageBox(GetDesktopWindow(), ErrMsg,
+ "SERVER ALREADY RUNNING", MB_ICONEXCLAMATION | MB_OK);
+ return TRUE;
+
+ } else {
+ /* We aren't too interested in why the creation failed
+ * if it is not because of another instance */
+
+ return FALSE;
+ }
+ } // hServDoneSemaphore == NULL
+
+ CloseHandle(hServDoneSemaphore);
+ return FALSE;
+}
+
+BOOL SlapdIsAService()
+{
+ // May change in V2.0
+ return FALSE;
+}
+
+BOOL SlapdGetServerNameFromCmdline(char *szServerName, char *szCmdLine, int dirname)
+{
+ BOOL bReturn = FALSE;
+ char *szChar = NULL;
+ char szCmdCopy[_MAX_PATH];
+
+ if( szCmdLine )
+ {
+ memset(szCmdCopy, 0, _MAX_PATH );
+ strcpy( szCmdCopy, szCmdLine );
+ }
+ else
+ return(bReturn);
+
+ // szCmdCopy should be something like
+ // c:\navgold\server\slapd-kennedy\config\slapd.conf
+ // unless dirname is TRUE in which case it should be
+ // c:\navgold\server\slapd-kennedy
+ if(szChar = strrchr(szCmdCopy, '\\'))
+ {
+ *szChar = 0;
+ if(dirname)
+ {
+ strcpy(szServerName, szChar+1);
+ bReturn = TRUE;
+ }
+ else if(szChar = strrchr(szCmdCopy, '\\'))
+ {
+ // szCmdCopy should be c:\navgold\server\slapd-kennedy\config
+ *szChar = 0;
+ // szCmdCopy should be c:\navgold\server\slapd-kennedy
+ if(szChar = strrchr(szCmdCopy, '\\'))
+ {
+ szChar++;
+ // szChar should point to slapd-kennedy
+ strcpy(szServerName, szChar);
+ bReturn = TRUE;
+ }
+ }
+ }
+ else
+ {
+ // szCmdCopy should be something like slapd-kennedy
+ strcpy(szServerName, szCmdCopy);
+ bReturn = TRUE;
+ }
+
+ if(strlen(szServerName) == 0)
+ bReturn = FALSE;
+
+ return(bReturn);
+}
+
+#endif _WIN32
diff --git a/ldap/libraries/libutil/ntreg.c b/ldap/libraries/libutil/ntreg.c
new file mode 100644
index 00000000..53313075
--- /dev/null
+++ b/ldap/libraries/libutil/ntreg.c
@@ -0,0 +1,105 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright 2001 Sun Microsystems, Inc.
+ * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+ * All rights reserved.
+ * END COPYRIGHT BLOCK **/
+
+#ifdef _WIN32
+
+#include <windows.h>
+#include <stdio.h>
+#include "ldap.h"
+
+int SlapdGetRegSZ( LPTSTR lpszRegKey, LPSTR lpszValueName, LPTSTR lpszValue )
+{
+ HKEY hKey;
+ DWORD dwType, dwNumBytes;
+ LONG lResult;
+
+ /* Open the registry, get the required key handle. */
+ lResult = RegOpenKeyEx( HKEY_LOCAL_MACHINE, lpszRegKey,
+ 0L, KEY_QUERY_VALUE, &hKey );
+ if (lResult == ERROR_SUCCESS)
+ {
+ dwNumBytes = sizeof( DWORD );
+ lResult = RegQueryValueEx( hKey, lpszValueName, 0,
+ &dwType, NULL, &dwNumBytes );
+ if( lResult == ERROR_SUCCESS )
+ {
+ RegQueryValueEx( hKey, lpszValueName, 0, &dwType,
+ (LPBYTE)lpszValue, &dwNumBytes );
+ *(lpszValue+dwNumBytes) = 0;
+
+ /* Close the Registry. */
+ RegCloseKey(hKey);
+ return 0;
+ }
+ else
+ {
+ /* No config file location stored in the Registry. */
+ RegCloseKey(hKey);
+ return 1;
+ }
+ }
+ else
+ {
+ return 1;
+ }
+} /* SlapdGetRegSZ */
+
+
+int SlapdSetRegSZ( LPTSTR lpszKey, LPSTR lpszValueName, LPTSTR lpszValue )
+{
+ HKEY hKey;
+ LONG lResult;
+
+ /* Open the registry, get a handle to the desired key. */
+ lResult = RegOpenKeyEx( HKEY_LOCAL_MACHINE, lpszKey, 0,
+ KEY_ALL_ACCESS, &hKey );
+ if (lResult == ERROR_SUCCESS)
+ {
+ /* Set the value to the value-name at the key location. */
+ RegSetValueEx( hKey, lpszValueName, 0, REG_SZ,
+ (CONST BYTE*)lpszValue, strlen(lpszValue) );
+
+ /* Close the registry */
+ RegCloseKey(hKey);
+ return 0;
+ }
+ else
+ {
+ return 1;
+ }
+} /* SlapdSetRegSZ */
+
+/* converts '/' chars to '\' */
+void
+unixtodospath(char *szText)
+{
+ if(szText)
+ {
+ while(*szText)
+ {
+ if( *szText == '/' )
+ *szText = '\\';
+ szText++;
+ }
+ }
+}
+
+/* converts '\' chars to '/' */
+void
+dostounixpath(char *szText)
+{
+ if(szText)
+ {
+ while(*szText)
+ {
+ if( *szText == '\\' )
+ *szText = '/';
+ szText++;
+ }
+ }
+}
+
+#endif /* _WIN32 */
diff --git a/ldap/libraries/libutil/ntresource.h b/ldap/libraries/libutil/ntresource.h
new file mode 100644
index 00000000..c2e375c5
--- /dev/null
+++ b/ldap/libraries/libutil/ntresource.h
@@ -0,0 +1,31 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright 2001 Sun Microsystems, Inc.
+ * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+ * All rights reserved.
+ * END COPYRIGHT BLOCK **/
+//{{NO_DEPENDENCIES}}
+// Microsoft Developer Studio generated include file.
+// Used by ntslapd.rc
+//
+#define IDD_DATABASE_PASSWORD 101
+#define IDD_FORTEZZA_PIN 102
+#define IDI_KEY 103
+#define IDI_LOGO 105
+#define IDR_MENU 205
+#define IDEDIT 1000
+#define ID_SERVER_RESTART 40001
+#define ID_FILE_EXIT 40003
+#define ID_SERVER_SHUTDOWN 40004
+#define ID_SERVER_SUSPEND 40005
+#define ID_SERVER_RESUME 40006
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE 106
+#define _APS_NEXT_COMMAND_VALUE 40001
+#define _APS_NEXT_CONTROL_VALUE 1001
+#define _APS_NEXT_SYMED_VALUE 101
+#endif
+#endif
diff --git a/ldap/libraries/libutil/ntstubs.c b/ldap/libraries/libutil/ntstubs.c
new file mode 100644
index 00000000..5d18ad38
--- /dev/null
+++ b/ldap/libraries/libutil/ntstubs.c
@@ -0,0 +1,40 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright 2001 Sun Microsystems, Inc.
+ * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+ * All rights reserved.
+ * END COPYRIGHT BLOCK **/
+/******************************************************
+ *
+ * ntstubs.c - Stubs needed on NT when linking in
+ * the SSL code. If these stubs were not here, the
+ * named functions below would not be located at link
+ * time, because there is no implementation of the
+ * functions for Win32 in cross-platform libraries.
+ *
+ ******************************************************/
+
+#if defined( _WIN32 ) && defined ( NET_SSL )
+
+#include <windows.h>
+#include <nspr.h>
+
+/*
+char* XP_FileName (const char* name, XP_FileType type)
+{
+ return NULL;
+}
+
+XP_File XP_FileOpen(const char* name, XP_FileType type,
+ const XP_FilePerm permissions)
+{
+ return NULL;
+}
+*/
+
+char *
+WH_FileName (const char *name, PRFileType type)
+{
+ return NULL;
+}
+#endif /* WIN32 && NET_SSL */
+