mirror of
https://git.openldap.org/openldap/openldap.git
synced 2026-02-20 00:10:59 -05:00
Changes:
Fixed liblutil getpeereid replacement function
Fixed liblber 64bit len/tag bug
Updated liblber ber_get_stringbv handling
Build Environment
Updated NT build environment w/ slurpd support
Updated test suite
This commit is contained in:
parent
cf2ae725cd
commit
0dfb50953b
27 changed files with 1395 additions and 896 deletions
6
CHANGES
6
CHANGES
|
|
@ -2,6 +2,12 @@ OpenLDAP 2.1 Change Log
|
|||
|
||||
OpenLDAP 2.1.15 Engineering
|
||||
Fixed slapd saslauthz null backend crash
|
||||
Fixed liblutil getpeereid replacement function
|
||||
Fixed liblber 64bit len/tag bug
|
||||
Updated liblber ber_get_stringbv handling
|
||||
Build Environment
|
||||
Updated NT build environment w/ slurpd support
|
||||
Updated test suite
|
||||
|
||||
OpenLDAP 2.1.14 Release
|
||||
Fixed slapd schema_check name check crash (ITS#2330)
|
||||
|
|
|
|||
|
|
@ -1216,3 +1216,16 @@ AC_DEFUN([OL_SASL_COMPAT],
|
|||
#endif
|
||||
], [ol_cv_sasl_compat=yes], [ol_cv_sasl_compat=no])])
|
||||
])
|
||||
dnl ====================================================================
|
||||
dnl check for msg_accrights in msghdr
|
||||
AC_DEFUN(OL_MSGHDR_MSG_ACCRIGHTS,
|
||||
[AC_CACHE_CHECK(for msg_accrights in msghdr, ol_cv_msghdr_msg_accrights,
|
||||
[AC_TRY_COMPILE([#include <sys/socket.h>],
|
||||
[struct msghdr m; m.msg_accrightslen=0],
|
||||
ol_cv_msghdr_msg_accrights=yes, ol_cv_msghdr_msg_accrights=no)
|
||||
])
|
||||
if test $ol_cv_msghdr_msg_accrights = "yes" ; then
|
||||
AC_DEFINE(HAVE_MSGHDR_MSG_ACCRIGHTS,1,
|
||||
[define if struct msghdr has msg_accrights])
|
||||
fi
|
||||
])dnl
|
||||
|
|
|
|||
|
|
@ -808,10 +808,12 @@ AC_CHECK_HEADERS( \
|
|||
sys/resource.h \
|
||||
sys/select.h \
|
||||
sys/socket.h \
|
||||
sys/stat.h \
|
||||
sys/syslog.h \
|
||||
sys/time.h \
|
||||
sys/types.h \
|
||||
sys/ucred.h \
|
||||
sys/uio.h \
|
||||
syslog.h \
|
||||
termios.h \
|
||||
unistd.h \
|
||||
|
|
@ -2438,6 +2440,7 @@ if test "$ac_cv_func_getopt" != yes; then
|
|||
LIBSRCS="$LIBSRCS getopt.c"
|
||||
fi
|
||||
if test "$ac_cv_func_getpeereid" != yes; then
|
||||
OL_MSGHDR_MSG_ACCRIGHTS
|
||||
LIBSRCS="$LIBSRCS getpeereid.c"
|
||||
fi
|
||||
if test "$ac_cv_func_snprintf" != yes -o "$ac_cv_func_vsnprintf" != yes; then
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# $OpenLDAP$
|
||||
## Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
|
||||
## Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
|
||||
## COPYING RESTRICTIONS APPLY, See COPYRIGHT file
|
||||
##
|
||||
## include Makefile.in for OpenLDAP
|
||||
|
|
@ -43,10 +43,6 @@ ldap_config.h: $(LDAP_CONFIG) Makefile
|
|||
$(SED) -e 's/\\\\/\\\\\\\\\\\\\\\\/g'`; \
|
||||
localstatedir=`cygpath -w $(localstatedir) | \
|
||||
$(SED) -e 's/\\\\/\\\\\\\\\\\\\\\\/g'`; \
|
||||
editor=`cygpath -w $(EDITOR) | \
|
||||
$(SED) -e 's/\\\\/\\\\\\\\\\\\\\\\/g'`; \
|
||||
sendmail=`cygpath -w $(SENDMAIL) | \
|
||||
$(SED) -e 's/\\\\/\\\\\\\\\\\\\\\\/g'`; \
|
||||
else \
|
||||
sysconfdir=$(sysconfdir); \
|
||||
datadir=$(datadir); \
|
||||
|
|
@ -54,8 +50,6 @@ ldap_config.h: $(LDAP_CONFIG) Makefile
|
|||
sbindir=$(sbindir); \
|
||||
libexecdir=$(libexecdir); \
|
||||
localstatedir=$(localstatedir); \
|
||||
editor=$(EDITOR); \
|
||||
sendmail=$(SENDMAIL); \
|
||||
fi; \
|
||||
$(SED) \
|
||||
-e "s;%SYSCONFDIR%;$$sysconfdir;" \
|
||||
|
|
@ -64,8 +58,6 @@ ldap_config.h: $(LDAP_CONFIG) Makefile
|
|||
-e "s;%SBINDIR%;$$sbindir;" \
|
||||
-e "s;%LIBEXECDIR%;$$libexecdir;" \
|
||||
-e "s;%RUNDIR%;$$localstatedir;" \
|
||||
-e "s;%EDITOR%;$$editor;" \
|
||||
-e "s;%SENDMAIL%;$$sendmail;" \
|
||||
$(LDAP_CONFIG) >> $@; \
|
||||
$(CHMOD) 444 $@
|
||||
|
||||
|
|
|
|||
|
|
@ -162,12 +162,35 @@ LDAP_LUTIL_V (ldap_pvt_thread_cond_t) started_event;
|
|||
|
||||
/* macros are different between Windows and Mingw */
|
||||
#if defined(_WINSVC_H) || defined(_WINSVC_)
|
||||
LDAP_LUTIL_V (SERVICE_STATUS) SLAPDServiceStatus;
|
||||
LDAP_LUTIL_V (SERVICE_STATUS_HANDLE) hSLAPDServiceStatus;
|
||||
LDAP_LUTIL_V (SERVICE_STATUS) lutil_ServiceStatus;
|
||||
LDAP_LUTIL_V (SERVICE_STATUS_HANDLE) hlutil_ServiceStatus;
|
||||
#endif /* _WINSVC_H */
|
||||
|
||||
LDAP_LUTIL_F (void)
|
||||
lutil_CommenceStartupProcessing( char *serverName, void (*stopper)(int)) ;
|
||||
|
||||
LDAP_LUTIL_F (void)
|
||||
lutil_ReportShutdownComplete( void );
|
||||
|
||||
LDAP_LUTIL_F (void *)
|
||||
lutil_getRegParam( char *svc, char *value );
|
||||
|
||||
LDAP_LUTIL_F (int)
|
||||
lutil_srv_install( char* service, char * displayName, char* filename,
|
||||
int auto_start );
|
||||
LDAP_LUTIL_F (int)
|
||||
lutil_srv_remove ( char* service, char* filename );
|
||||
|
||||
#endif /* HAVE_NT_SERVICE_MANAGER */
|
||||
|
||||
#ifdef HAVE_NT_EVENT_LOG
|
||||
LDAP_LUTIL_F (void)
|
||||
lutil_LogStartedEvent( char *svc, int slap_debug, char *configfile, char *urls );
|
||||
|
||||
LDAP_LUTIL_F (void)
|
||||
lutil_LogStoppedEvent( char *svc );
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_EBCDIC
|
||||
/* Generally this has only been used to put '\n' to stdout. We need to
|
||||
* make sure it is output in EBCDIC.
|
||||
|
|
|
|||
|
|
@ -539,6 +539,9 @@
|
|||
/* Define if you have the <sys/socket.h> header file. */
|
||||
#undef HAVE_SYS_SOCKET_H
|
||||
|
||||
/* Define if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
/* Define if you have the <sys/syslog.h> header file. */
|
||||
#undef HAVE_SYS_SYSLOG_H
|
||||
|
||||
|
|
@ -551,6 +554,9 @@
|
|||
/* Define if you have the <sys/ucred.h> header file. */
|
||||
#undef HAVE_SYS_UCRED_H
|
||||
|
||||
/* Define if you have the <sys/uio.h> header file. */
|
||||
#undef HAVE_SYS_UIO_H
|
||||
|
||||
/* Define if you have the <sys/un.h> header file. */
|
||||
#undef HAVE_SYS_UN_H
|
||||
|
||||
|
|
@ -878,6 +884,9 @@
|
|||
/* define to vsnprintf routine */
|
||||
#undef vsnprintf
|
||||
|
||||
/* define if struct msghdr has msg_accrights */
|
||||
#undef HAVE_MSGHDR_MSG_ACCRIGHTS
|
||||
|
||||
/* define to snprintf routine */
|
||||
#undef snprintf
|
||||
|
||||
|
|
|
|||
|
|
@ -282,7 +282,7 @@ ber_get_stringb(
|
|||
return tag;
|
||||
}
|
||||
|
||||
/* Definitions for recursive get_string
|
||||
/* Definitions for get_string vector
|
||||
*
|
||||
* ChArray, BvArray, and BvVec are self-explanatory.
|
||||
* BvOff is a struct berval embedded in an array of larger structures
|
||||
|
|
@ -296,9 +296,6 @@ enum bgbvc { ChArray, BvArray, BvVec, BvOff };
|
|||
typedef struct bgbvr {
|
||||
enum bgbvc choice;
|
||||
BerElement *ber;
|
||||
ber_tag_t tag;
|
||||
ber_len_t len;
|
||||
char *last;
|
||||
int alloc;
|
||||
ber_len_t siz;
|
||||
ber_len_t off;
|
||||
|
|
@ -309,74 +306,74 @@ typedef struct bgbvr {
|
|||
} res;
|
||||
} bgbvr;
|
||||
|
||||
/* Recursive get_string, for decoding a vector of strings. The number
|
||||
* of elements in the vector is limited only by available stack space.
|
||||
* Each invocation consumes 24 bytes of stack on a 32-bit machine.
|
||||
*/
|
||||
static ber_tag_t
|
||||
ber_get_stringbvr( bgbvr *b, int n )
|
||||
ber_get_stringbvl( bgbvr *b, ber_len_t *rlen )
|
||||
{
|
||||
int i = 0, n;
|
||||
ber_tag_t tag;
|
||||
ber_len_t len;
|
||||
char *last, *orig;
|
||||
struct berval bv, *bvp = NULL;
|
||||
|
||||
if ( n )
|
||||
b->tag = ber_next_element( b->ber, &b->len, b->last );
|
||||
else
|
||||
b->tag = ber_first_element( b->ber, &b->len, &b->last );
|
||||
orig = b->ber->ber_ptr;
|
||||
|
||||
if ( b->tag == LBER_DEFAULT )
|
||||
tag = ber_first_element( b->ber, &len, &last );
|
||||
if ( tag != LBER_DEFAULT ) {
|
||||
for ( ; b->ber->ber_ptr < last; i++ )
|
||||
{
|
||||
tag = ber_skip_tag( b->ber, &len );
|
||||
if (tag == LBER_DEFAULT) break;
|
||||
b->ber->ber_ptr += len;
|
||||
}
|
||||
}
|
||||
|
||||
if ( rlen ) *rlen = i;
|
||||
|
||||
if ( i == 0 )
|
||||
{
|
||||
b->len = n;
|
||||
|
||||
if ( n == 0 ) {
|
||||
*b->res.c = NULL;
|
||||
return 0;
|
||||
}
|
||||
/* Allocate the result vector */
|
||||
switch (b->choice) {
|
||||
case ChArray:
|
||||
*b->res.c = LBER_MALLOC( (n+1) * sizeof( char * ));
|
||||
if ( *b->res.c == NULL )
|
||||
return LBER_DEFAULT;
|
||||
(*b->res.c)[n] = NULL;
|
||||
break;
|
||||
case BvArray:
|
||||
*b->res.ba = LBER_MALLOC( (n+1) * sizeof( struct berval ));
|
||||
if ( *b->res.ba == NULL )
|
||||
return LBER_DEFAULT;
|
||||
(*b->res.ba)[n].bv_val = NULL;
|
||||
break;
|
||||
case BvVec:
|
||||
*b->res.bv = LBER_MALLOC( (n+1) * sizeof( struct berval *));
|
||||
if ( *b->res.bv == NULL )
|
||||
return LBER_DEFAULT;
|
||||
(*b->res.bv)[n] = NULL;
|
||||
break;
|
||||
case BvOff:
|
||||
*b->res.ba = LBER_MALLOC( (n+1) * b->siz );
|
||||
if ( *b->res.ba == NULL )
|
||||
return LBER_DEFAULT;
|
||||
((struct berval *)((long)(*b->res.ba) + n*b->siz +
|
||||
b->off))->bv_val = NULL;
|
||||
break;
|
||||
}
|
||||
*b->res.c = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Do all local allocs before the recursion. Then there
|
||||
* cannot possibly be any failures on the return trip.
|
||||
*/
|
||||
if ( b->choice == BvVec )
|
||||
bvp = LBER_MALLOC( sizeof( struct berval ));
|
||||
n = i;
|
||||
|
||||
if ( ber_get_stringbv( b->ber, &bv, b->alloc ) == LBER_DEFAULT ) {
|
||||
if ( bvp ) LBER_FREE( bvp );
|
||||
return LBER_DEFAULT;
|
||||
/* Allocate the result vector */
|
||||
switch (b->choice) {
|
||||
case ChArray:
|
||||
*b->res.c = LBER_MALLOC( (n+1) * sizeof( char * ));
|
||||
if ( *b->res.c == NULL )
|
||||
return LBER_DEFAULT;
|
||||
(*b->res.c)[n] = NULL;
|
||||
break;
|
||||
case BvArray:
|
||||
*b->res.ba = LBER_MALLOC( (n+1) * sizeof( struct berval ));
|
||||
if ( *b->res.ba == NULL )
|
||||
return LBER_DEFAULT;
|
||||
(*b->res.ba)[n].bv_val = NULL;
|
||||
break;
|
||||
case BvVec:
|
||||
*b->res.bv = LBER_MALLOC( (n+1) * sizeof( struct berval *));
|
||||
if ( *b->res.bv == NULL )
|
||||
return LBER_DEFAULT;
|
||||
(*b->res.bv)[n] = NULL;
|
||||
break;
|
||||
case BvOff:
|
||||
*b->res.ba = LBER_MALLOC( (n+1) * b->siz );
|
||||
if ( *b->res.ba == NULL )
|
||||
return LBER_DEFAULT;
|
||||
((struct berval *)((long)(*b->res.ba) + n*b->siz +
|
||||
b->off))->bv_val = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
b->tag = ber_get_stringbvr( b, n+1 );
|
||||
b->ber->ber_ptr = orig;
|
||||
ber_skip_tag( b->ber, &len );
|
||||
|
||||
if ( b->tag == 0 )
|
||||
for (n=0; n<i; n++)
|
||||
{
|
||||
tag = ber_next_element( b->ber, &len, last );
|
||||
if ( ber_get_stringbv( b->ber, &bv, b->alloc ) == LBER_DEFAULT )
|
||||
goto nomem;
|
||||
|
||||
/* store my result */
|
||||
switch (b->choice) {
|
||||
case ChArray:
|
||||
|
|
@ -386,20 +383,36 @@ ber_get_stringbvr( bgbvr *b, int n )
|
|||
(*b->res.ba)[n] = bv;
|
||||
break;
|
||||
case BvVec:
|
||||
bvp = LBER_MALLOC( sizeof( struct berval ));
|
||||
if ( !bvp ) {
|
||||
LBER_FREE(bv.bv_val);
|
||||
goto nomem;
|
||||
}
|
||||
(*b->res.bv)[n] = bvp;
|
||||
*bvp = bv;
|
||||
break;
|
||||
case BvOff:
|
||||
*(BerVarray)((long)(*b->res.ba)+n*b->siz+b->off) = bv;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* Failure will propagate up and free in reverse
|
||||
* order, which is actually ideal.
|
||||
*/
|
||||
if ( b->alloc ) LBER_FREE( bv.bv_val );
|
||||
if ( bvp ) LBER_FREE( bvp );
|
||||
}
|
||||
return b->tag;
|
||||
return tag;
|
||||
nomem:
|
||||
if (b->alloc || b->choice == BvVec)
|
||||
{
|
||||
for (--n; n>=0; n--)
|
||||
{
|
||||
switch(b->choice) {
|
||||
case ChArray: LBER_FREE((*b->res.c)[n]); break;
|
||||
case BvArray: LBER_FREE((*b->res.ba)[n].bv_val); break;
|
||||
case BvVec: LBER_FREE((*b->res.bv)[n]->bv_val);
|
||||
LBER_FREE((*b->res.bv)[n]); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
LBER_FREE(*b->res.c);
|
||||
*b->res.c = NULL;
|
||||
return LBER_DEFAULT;
|
||||
}
|
||||
|
||||
ber_tag_t
|
||||
|
|
@ -723,7 +736,7 @@ ber_scanf ( BerElement *ber,
|
|||
cookie.ber = ber;
|
||||
cookie.res.c = va_arg( ap, char *** );
|
||||
cookie.alloc = 1;
|
||||
rc = ber_get_stringbvr( &cookie, 0 );
|
||||
rc = ber_get_stringbvl( &cookie, NULL );
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -733,7 +746,7 @@ ber_scanf ( BerElement *ber,
|
|||
cookie.ber = ber;
|
||||
cookie.res.bv = va_arg( ap, struct berval *** );
|
||||
cookie.alloc = 1;
|
||||
rc = ber_get_stringbvr( &cookie, 0 );
|
||||
rc = ber_get_stringbvl( &cookie, NULL );
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -743,7 +756,7 @@ ber_scanf ( BerElement *ber,
|
|||
cookie.ber = ber;
|
||||
cookie.res.ba = va_arg( ap, struct berval ** );
|
||||
cookie.alloc = 1;
|
||||
rc = ber_get_stringbvr( &cookie, 0 );
|
||||
rc = ber_get_stringbvl( &cookie, NULL );
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -760,8 +773,7 @@ ber_scanf ( BerElement *ber,
|
|||
l = va_arg( ap, ber_len_t * );
|
||||
cookie.siz = *l;
|
||||
cookie.off = va_arg( ap, ber_len_t );
|
||||
rc = ber_get_stringbvr( &cookie, 0 );
|
||||
*l = cookie.len;
|
||||
rc = ber_get_stringbvl( &cookie, l );
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -456,6 +456,8 @@ ber_reset( BerElement *ber, int was_writing )
|
|||
* a full packet is read.
|
||||
*/
|
||||
|
||||
#define LENSIZE 4
|
||||
|
||||
ber_tag_t
|
||||
ber_get_next(
|
||||
Sockbuf *sb,
|
||||
|
|
@ -486,6 +488,15 @@ ber_get_next(
|
|||
* 1) small tags (less than 128)
|
||||
* 2) definite lengths
|
||||
* 3) primitive encodings used whenever possible
|
||||
*
|
||||
* The code also handles multi-byte tags. The first few bytes
|
||||
* of the message are read to check for multi-byte tags and
|
||||
* lengths. These bytes are temporarily stored in the ber_tag,
|
||||
* ber_len, and ber_usertag fields of the berelement until
|
||||
* tag/len parsing is complete. After this parsing, any leftover
|
||||
* bytes and the rest of the message are copied into the ber_buf.
|
||||
*
|
||||
* We expect tag and len to be at most 32 bits wide.
|
||||
*/
|
||||
|
||||
if (ber->ber_rwptr == NULL) {
|
||||
|
|
@ -499,13 +510,13 @@ ber_get_next(
|
|||
}
|
||||
|
||||
while (ber->ber_rwptr > (char *)&ber->ber_tag && ber->ber_rwptr <
|
||||
(char *)(&ber->ber_usertag + 1)) {
|
||||
(char *)&ber->ber_len + LENSIZE*2) {
|
||||
ber_slen_t sblen;
|
||||
char buf[sizeof(ber->ber_len)-1];
|
||||
char buf[LENSIZE-1];
|
||||
ber_len_t tlen = 0;
|
||||
|
||||
sblen=ber_int_sb_read( sb, ber->ber_rwptr,
|
||||
(char *)(&ber->ber_usertag+1)-ber->ber_rwptr);
|
||||
((char *)&ber->ber_len + LENSIZE*2)-ber->ber_rwptr);
|
||||
if (sblen<=0) return LBER_DEFAULT;
|
||||
ber->ber_rwptr += sblen;
|
||||
|
||||
|
|
@ -563,11 +574,11 @@ ber_get_next(
|
|||
}
|
||||
|
||||
/* Are there leftover data bytes inside ber->ber_len? */
|
||||
if (ber->ber_ptr < (char *)&ber->ber_usertag) {
|
||||
if (ber->ber_rwptr < (char *)&ber->ber_usertag)
|
||||
if (ber->ber_ptr < (char *)&ber->ber_len+LENSIZE) {
|
||||
if (ber->ber_rwptr < (char *)&ber->ber_len+LENSIZE)
|
||||
sblen = ber->ber_rwptr - ber->ber_ptr;
|
||||
else
|
||||
sblen = (char *)&ber->ber_usertag - ber->ber_ptr;
|
||||
sblen = ((char *)&ber->ber_len+LENSIZE) - ber->ber_ptr;
|
||||
AC_MEMCPY(buf, ber->ber_ptr, sblen);
|
||||
ber->ber_ptr += sblen;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -25,8 +25,12 @@
|
|||
#include <ac/time.h>
|
||||
#include <ac/unistd.h>
|
||||
|
||||
/* XXX non-portable */
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_UIO_H
|
||||
#include <sys/uio.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_IO_H
|
||||
#include <io.h>
|
||||
|
|
@ -131,7 +135,9 @@ ldap_pvt_is_socket_ready(LDAP *ld, int s)
|
|||
}
|
||||
#undef TRACE
|
||||
|
||||
#if !defined(HAVE_GETPEEREID) && !defined(SO_PEERCRED) && !defined(LOCAL_PEERCRED) && defined(HAVE_SENDMSG)
|
||||
#if !defined(HAVE_GETPEEREID) && \
|
||||
!defined(SO_PEERCRED) && !defined(LOCAL_PEERCRED) && \
|
||||
defined(HAVE_SENDMSG) && defined(HAVE_MSGHDR_MSG_ACCRIGHTS)
|
||||
#define DO_SENDMSG
|
||||
#endif
|
||||
|
||||
|
|
@ -163,9 +169,13 @@ ldap_pvt_connect(LDAP *ld, ber_socket_t s, struct sockaddr_un *sa, int async)
|
|||
/* Send a dummy message with access rights. Remote side will
|
||||
* obtain our uid/gid by fstat'ing this descriptor.
|
||||
*/
|
||||
sendcred: {
|
||||
sendcred:
|
||||
{
|
||||
int fds[2];
|
||||
struct iovec iov = {(char *)fds, sizeof(int)};
|
||||
/* Abandon, noop, has no reply */
|
||||
char txt[] = {LDAP_TAG_MESSAGE, 6,
|
||||
LDAP_TAG_MSGID, 1, 0, LDAP_REQ_ABANDON, 1, 0};
|
||||
struct iovec iov = {txt, sizeof(txt)};
|
||||
struct msghdr msg = {0};
|
||||
if (pipe(fds) == 0) {
|
||||
msg.msg_iov = &iov;
|
||||
|
|
@ -173,7 +183,7 @@ sendcred: {
|
|||
msg.msg_accrights = (char *)fds;
|
||||
msg.msg_accrightslen = sizeof(int);
|
||||
sendmsg( s, &msg, 0 );
|
||||
close(fds[0]);
|
||||
close(fds[0]);
|
||||
close(fds[1]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,13 +13,18 @@
|
|||
#include <ac/unistd.h>
|
||||
|
||||
#include <ac/socket.h>
|
||||
#include <ac/errno.h>
|
||||
|
||||
#if HAVE_SYS_UCRED_H
|
||||
#include <sys/ucred.h>
|
||||
#endif
|
||||
|
||||
#if !defined(SO_PEERCRED) && !defined(LOCAL_PEERCRED) && defined(HAVE_SENDMSG)
|
||||
#if !defined(SO_PEERCRED) && !defined(LOCAL_PEERCRED) && \
|
||||
defined(HAVE_SENDMSG) && defined(HAVE_MSGHDR_MSG_ACCRIGHTS)
|
||||
#define DO_SENDMSG
|
||||
#ifdef HAVE_SYS_UIO_H
|
||||
#include <sys/uio.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
|
|
@ -53,14 +58,14 @@ int getpeereid( int s, uid_t *euid, gid_t *egid )
|
|||
}
|
||||
#elif defined( DO_SENDMSG )
|
||||
int dummy, fd[2];
|
||||
struct iovec iov = {(char *)&dummy, sizeof(dummy)};
|
||||
struct iovec iov = {(char *)&dummy, 1};
|
||||
struct msghdr msg = {0};
|
||||
struct stat st;
|
||||
msg.msg_iov = &iov;
|
||||
msg.msg_iovlen = 1;
|
||||
msg.msg_accrights = (char *)fd;
|
||||
msg.msg_accrightslen = sizeof(fd);
|
||||
if( recvmsg( s, &msg, 0) >= 0 && msg.msg_accrightslen == sizeof(int) )
|
||||
if( recvmsg( s, &msg, MSG_PEEK) >= 0 && msg.msg_accrightslen == sizeof(int) )
|
||||
{
|
||||
/* We must receive a valid descriptor, it must be a pipe,
|
||||
* and it must only be accessible by its owner.
|
||||
|
|
@ -76,9 +81,9 @@ int getpeereid( int s, uid_t *euid, gid_t *egid )
|
|||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif /* LDAP_PF_LOCAL */
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* HAVE_GETPEEREID */
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
/*
|
||||
* NT Service manager utilities for OpenLDAP services
|
||||
* these should NOT be slapd specific, but are
|
||||
*/
|
||||
|
||||
#include "portable.h"
|
||||
|
|
@ -23,17 +22,6 @@
|
|||
|
||||
#include <ldap.h>
|
||||
|
||||
/*
|
||||
* The whole debug implementation is a bit of a hack.
|
||||
* We have to define this LDAP_SLAPD_V macro here since the slap.h
|
||||
* header file isn't included (and really shouldn't be).
|
||||
* TODO: re-implement debug functions so that the debug level can
|
||||
* be passed around instead of having to count on the existence of
|
||||
* ldap_debug, slap_debug, etc.
|
||||
*/
|
||||
#define ldap_debug slap_debug
|
||||
LDAP_SLAPD_V (int) slap_debug;
|
||||
|
||||
#include "ldap_log.h"
|
||||
#include "ldap_pvt_thread.h"
|
||||
|
||||
|
|
@ -45,11 +33,10 @@ LDAP_SLAPD_V (int) slap_debug;
|
|||
#define SCM_NOTIFICATION_INTERVAL 5000
|
||||
#define THIRTY_SECONDS (30 * 1000)
|
||||
|
||||
int is_NT_Service = 1; /* assume this is an NT service until determined that */
|
||||
/* startup was from the command line */
|
||||
int is_NT_Service; /* is this is an NT service? */
|
||||
|
||||
SERVICE_STATUS SLAPDServiceStatus;
|
||||
SERVICE_STATUS_HANDLE hSLAPDServiceStatus;
|
||||
SERVICE_STATUS lutil_ServiceStatus;
|
||||
SERVICE_STATUS_HANDLE hlutil_ServiceStatus;
|
||||
|
||||
ldap_pvt_thread_cond_t started_event, stopped_event;
|
||||
ldap_pvt_thread_t start_status_tid, stop_status_tid;
|
||||
|
|
@ -58,14 +45,17 @@ void (*stopfunc)(int);
|
|||
|
||||
static char *GetLastErrorString( void );
|
||||
|
||||
int srv_install(LPCTSTR lpszServiceName, LPCTSTR lpszDisplayName,
|
||||
LPCTSTR lpszBinaryPathName, BOOL auto_start)
|
||||
int lutil_srv_install(LPCTSTR lpszServiceName, LPCTSTR lpszDisplayName,
|
||||
LPCTSTR lpszBinaryPathName, int auto_start)
|
||||
{
|
||||
HKEY hKey;
|
||||
DWORD dwValue, dwDisposition;
|
||||
SC_HANDLE schSCManager, schService;
|
||||
char *sp = strchr( lpszBinaryPathName, ' ');
|
||||
|
||||
if ( sp ) *sp = '\0';
|
||||
fprintf( stderr, "The install path is %s.\n", lpszBinaryPathName );
|
||||
if ( sp ) *sp = ' ';
|
||||
if ((schSCManager = OpenSCManager( NULL, NULL, SC_MANAGER_CONNECT|SC_MANAGER_CREATE_SERVICE ) ) != NULL )
|
||||
{
|
||||
if ((schService = CreateService(
|
||||
|
|
@ -96,6 +86,7 @@ int srv_install(LPCTSTR lpszServiceName, LPCTSTR lpszDisplayName,
|
|||
RegCloseKey(hKey);
|
||||
return(0);
|
||||
}
|
||||
if ( sp ) *sp = '\0';
|
||||
if ( RegSetValueEx(hKey, "EventMessageFile", 0, REG_EXPAND_SZ, lpszBinaryPathName, strlen(lpszBinaryPathName) + 1) != ERROR_SUCCESS)
|
||||
{
|
||||
fprintf( stderr, "RegSetValueEx(EventMessageFile) failed. GetLastError=%lu (%s)\n", GetLastError(), GetLastErrorString() );
|
||||
|
|
@ -126,7 +117,7 @@ int srv_install(LPCTSTR lpszServiceName, LPCTSTR lpszDisplayName,
|
|||
}
|
||||
|
||||
|
||||
int srv_remove(LPCTSTR lpszServiceName, LPCTSTR lpszBinaryPathName)
|
||||
int lutil_srv_remove(LPCTSTR lpszServiceName, LPCTSTR lpszBinaryPathName)
|
||||
{
|
||||
SC_HANDLE schSCManager, schService;
|
||||
|
||||
|
|
@ -159,6 +150,7 @@ int srv_remove(LPCTSTR lpszServiceName, LPCTSTR lpszBinaryPathName)
|
|||
}
|
||||
|
||||
|
||||
#if 0 /* unused */
|
||||
DWORD
|
||||
svc_installed (LPTSTR lpszServiceName, LPTSTR lpszBinaryPathName)
|
||||
{
|
||||
|
|
@ -209,7 +201,7 @@ svc_running (LPTSTR lpszServiceName)
|
|||
CloseServiceHandle(scm);
|
||||
return(rc);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static void *start_status_routine( void *ptr )
|
||||
{
|
||||
|
|
@ -226,27 +218,27 @@ static void *start_status_routine( void *ptr )
|
|||
/* the object that we were waiting for has been destroyed (ABANDONED) or
|
||||
* signalled (TIMEOUT_0). We can assume that the startup process is
|
||||
* complete and tell the Service Control Manager that we are now runnng */
|
||||
SLAPDServiceStatus.dwCurrentState = SERVICE_RUNNING;
|
||||
SLAPDServiceStatus.dwWin32ExitCode = NO_ERROR;
|
||||
SLAPDServiceStatus.dwCheckPoint++;
|
||||
SLAPDServiceStatus.dwWaitHint = 1000;
|
||||
SetServiceStatus(hSLAPDServiceStatus, &SLAPDServiceStatus);
|
||||
lutil_ServiceStatus.dwCurrentState = SERVICE_RUNNING;
|
||||
lutil_ServiceStatus.dwWin32ExitCode = NO_ERROR;
|
||||
lutil_ServiceStatus.dwCheckPoint++;
|
||||
lutil_ServiceStatus.dwWaitHint = 1000;
|
||||
SetServiceStatus(hlutil_ServiceStatus, &lutil_ServiceStatus);
|
||||
done = 1;
|
||||
break;
|
||||
case WAIT_TIMEOUT:
|
||||
/* We've waited for the required time, so send an update to the Service Control
|
||||
* Manager saying to wait again. */
|
||||
SLAPDServiceStatus.dwCheckPoint++;
|
||||
SLAPDServiceStatus.dwWaitHint = SCM_NOTIFICATION_INTERVAL * 2;
|
||||
SetServiceStatus(hSLAPDServiceStatus, &SLAPDServiceStatus);
|
||||
lutil_ServiceStatus.dwCheckPoint++;
|
||||
lutil_ServiceStatus.dwWaitHint = SCM_NOTIFICATION_INTERVAL * 2;
|
||||
SetServiceStatus(hlutil_ServiceStatus, &lutil_ServiceStatus);
|
||||
break;
|
||||
case WAIT_FAILED:
|
||||
/* theres been some problem with WaitForSingleObject so tell the Service
|
||||
* Control Manager to wait 30 seconds before deploying its assasin and
|
||||
* then leave the thread. */
|
||||
SLAPDServiceStatus.dwCheckPoint++;
|
||||
SLAPDServiceStatus.dwWaitHint = THIRTY_SECONDS;
|
||||
SetServiceStatus(hSLAPDServiceStatus, &SLAPDServiceStatus);
|
||||
lutil_ServiceStatus.dwCheckPoint++;
|
||||
lutil_ServiceStatus.dwWaitHint = THIRTY_SECONDS;
|
||||
SetServiceStatus(hlutil_ServiceStatus, &lutil_ServiceStatus);
|
||||
done = 1;
|
||||
break;
|
||||
}
|
||||
|
|
@ -278,17 +270,17 @@ static void *stop_status_routine( void *ptr )
|
|||
case WAIT_TIMEOUT:
|
||||
/* We've waited for the required time, so send an update to the Service Control
|
||||
* Manager saying to wait again. */
|
||||
SLAPDServiceStatus.dwCheckPoint++;
|
||||
SLAPDServiceStatus.dwWaitHint = SCM_NOTIFICATION_INTERVAL * 2;
|
||||
SetServiceStatus(hSLAPDServiceStatus, &SLAPDServiceStatus);
|
||||
lutil_ServiceStatus.dwCheckPoint++;
|
||||
lutil_ServiceStatus.dwWaitHint = SCM_NOTIFICATION_INTERVAL * 2;
|
||||
SetServiceStatus(hlutil_ServiceStatus, &lutil_ServiceStatus);
|
||||
break;
|
||||
case WAIT_FAILED:
|
||||
/* theres been some problem with WaitForSingleObject so tell the Service
|
||||
* Control Manager to wait 30 seconds before deploying its assasin and
|
||||
* then leave the thread. */
|
||||
SLAPDServiceStatus.dwCheckPoint++;
|
||||
SLAPDServiceStatus.dwWaitHint = THIRTY_SECONDS;
|
||||
SetServiceStatus(hSLAPDServiceStatus, &SLAPDServiceStatus);
|
||||
lutil_ServiceStatus.dwCheckPoint++;
|
||||
lutil_ServiceStatus.dwWaitHint = THIRTY_SECONDS;
|
||||
SetServiceStatus(hlutil_ServiceStatus, &lutil_ServiceStatus);
|
||||
done = 1;
|
||||
break;
|
||||
}
|
||||
|
|
@ -299,27 +291,26 @@ static void *stop_status_routine( void *ptr )
|
|||
|
||||
|
||||
|
||||
void WINAPI SLAPDServiceCtrlHandler( IN DWORD Opcode)
|
||||
void WINAPI lutil_ServiceCtrlHandler( IN DWORD Opcode)
|
||||
{
|
||||
switch (Opcode)
|
||||
{
|
||||
case SERVICE_CONTROL_STOP:
|
||||
case SERVICE_CONTROL_SHUTDOWN:
|
||||
|
||||
Debug( LDAP_DEBUG_TRACE, "Service Shutdown ordered\n", 0, 0, 0 );
|
||||
SLAPDServiceStatus.dwCurrentState = SERVICE_STOP_PENDING;
|
||||
SLAPDServiceStatus.dwCheckPoint++;
|
||||
SLAPDServiceStatus.dwWaitHint = SCM_NOTIFICATION_INTERVAL * 2;
|
||||
SetServiceStatus(hSLAPDServiceStatus, &SLAPDServiceStatus);
|
||||
lutil_ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING;
|
||||
lutil_ServiceStatus.dwCheckPoint++;
|
||||
lutil_ServiceStatus.dwWaitHint = SCM_NOTIFICATION_INTERVAL * 2;
|
||||
SetServiceStatus(hlutil_ServiceStatus, &lutil_ServiceStatus);
|
||||
|
||||
ldap_pvt_thread_cond_init( &stopped_event );
|
||||
if ( stopped_event == NULL )
|
||||
{
|
||||
/* the event was not created. We will ask the service control manager for 30
|
||||
* seconds to shutdown */
|
||||
SLAPDServiceStatus.dwCheckPoint++;
|
||||
SLAPDServiceStatus.dwWaitHint = THIRTY_SECONDS;
|
||||
SetServiceStatus(hSLAPDServiceStatus, &SLAPDServiceStatus);
|
||||
lutil_ServiceStatus.dwCheckPoint++;
|
||||
lutil_ServiceStatus.dwWaitHint = THIRTY_SECONDS;
|
||||
SetServiceStatus(hlutil_ServiceStatus, &lutil_ServiceStatus);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -334,22 +325,22 @@ void WINAPI SLAPDServiceCtrlHandler( IN DWORD Opcode)
|
|||
* service stopping is proceeding.
|
||||
* tell the Service Control Manager to wait another 30 seconds before deploying its
|
||||
* assasin. */
|
||||
SLAPDServiceStatus.dwCheckPoint++;
|
||||
SLAPDServiceStatus.dwWaitHint = THIRTY_SECONDS;
|
||||
SetServiceStatus(hSLAPDServiceStatus, &SLAPDServiceStatus);
|
||||
lutil_ServiceStatus.dwCheckPoint++;
|
||||
lutil_ServiceStatus.dwWaitHint = THIRTY_SECONDS;
|
||||
SetServiceStatus(hlutil_ServiceStatus, &lutil_ServiceStatus);
|
||||
}
|
||||
}
|
||||
stopfunc( -1 );
|
||||
break;
|
||||
|
||||
case SERVICE_CONTROL_INTERROGATE:
|
||||
SetServiceStatus(hSLAPDServiceStatus, &SLAPDServiceStatus);
|
||||
SetServiceStatus(hlutil_ServiceStatus, &lutil_ServiceStatus);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void *getRegParam( char *svc, char *value )
|
||||
void *lutil_getRegParam( char *svc, char *value )
|
||||
{
|
||||
HKEY hkey;
|
||||
char path[255];
|
||||
|
|
@ -364,13 +355,11 @@ void *getRegParam( char *svc, char *value )
|
|||
|
||||
if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, path, 0, KEY_READ, &hkey ) != ERROR_SUCCESS )
|
||||
{
|
||||
/*Debug( LDAP_DEBUG_ANY, "RegOpenKeyEx() %s\n", GetLastErrorString(), 0, 0); */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ( RegQueryValueEx( hkey, value, NULL, &vType, vValue, &valLen ) != ERROR_SUCCESS )
|
||||
{
|
||||
/*Debug( LDAP_DEBUG_ANY, "RegQueryValueEx() %s\n", GetLastErrorString(), 0, 0 );*/
|
||||
RegCloseKey( hkey );
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -387,7 +376,7 @@ void *getRegParam( char *svc, char *value )
|
|||
return (void*)NULL;
|
||||
}
|
||||
|
||||
void LogSlapdStartedEvent( char *svc, int slap_debug, char *configfile, char *urls )
|
||||
void lutil_LogStartedEvent( char *svc, int slap_debug, char *configfile, char *urls )
|
||||
{
|
||||
char *Inserts[5];
|
||||
WORD i = 0, j;
|
||||
|
|
@ -399,10 +388,9 @@ void LogSlapdStartedEvent( char *svc, int slap_debug, char *configfile, char *ur
|
|||
itoa( slap_debug, Inserts[i++], 10 );
|
||||
Inserts[i++] = strdup( configfile );
|
||||
Inserts[i++] = strdup( urls ? urls : "ldap:///" );
|
||||
Inserts[i++] = strdup( is_NT_Service ? "svc" : "cmd" );
|
||||
|
||||
ReportEvent( hEventLog, EVENTLOG_INFORMATION_TYPE, 0,
|
||||
MSG_SLAPD_STARTED, NULL, i, 0, (LPCSTR *) Inserts, NULL );
|
||||
MSG_SVC_STARTED, NULL, i, 0, (LPCSTR *) Inserts, NULL );
|
||||
|
||||
for ( j = 0; j < i; j++ )
|
||||
ldap_memfree( Inserts[j] );
|
||||
|
|
@ -411,34 +399,34 @@ void LogSlapdStartedEvent( char *svc, int slap_debug, char *configfile, char *ur
|
|||
|
||||
|
||||
|
||||
void LogSlapdStoppedEvent( char *svc )
|
||||
void lutil_LogStoppedEvent( char *svc )
|
||||
{
|
||||
HANDLE hEventLog;
|
||||
|
||||
hEventLog = RegisterEventSource( NULL, svc );
|
||||
ReportEvent( hEventLog, EVENTLOG_INFORMATION_TYPE, 0,
|
||||
MSG_SLAPD_STOPPED, NULL, 0, 0, NULL, NULL );
|
||||
MSG_SVC_STOPPED, NULL, 0, 0, NULL, NULL );
|
||||
DeregisterEventSource( hEventLog );
|
||||
}
|
||||
|
||||
|
||||
void CommenceStartupProcessing( LPCTSTR lpszServiceName,
|
||||
void lutil_CommenceStartupProcessing( char *lpszServiceName,
|
||||
void (*stopper)(int) )
|
||||
{
|
||||
hSLAPDServiceStatus = RegisterServiceCtrlHandler( lpszServiceName, (LPHANDLER_FUNCTION)SLAPDServiceCtrlHandler);
|
||||
hlutil_ServiceStatus = RegisterServiceCtrlHandler( lpszServiceName, (LPHANDLER_FUNCTION)lutil_ServiceCtrlHandler);
|
||||
|
||||
stopfunc = stopper;
|
||||
|
||||
/* initialize the Service Status structure */
|
||||
SLAPDServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
|
||||
SLAPDServiceStatus.dwCurrentState = SERVICE_START_PENDING;
|
||||
SLAPDServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
|
||||
SLAPDServiceStatus.dwWin32ExitCode = NO_ERROR;
|
||||
SLAPDServiceStatus.dwServiceSpecificExitCode = 0;
|
||||
SLAPDServiceStatus.dwCheckPoint = 1;
|
||||
SLAPDServiceStatus.dwWaitHint = SCM_NOTIFICATION_INTERVAL * 2;
|
||||
lutil_ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
|
||||
lutil_ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
|
||||
lutil_ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
|
||||
lutil_ServiceStatus.dwWin32ExitCode = NO_ERROR;
|
||||
lutil_ServiceStatus.dwServiceSpecificExitCode = 0;
|
||||
lutil_ServiceStatus.dwCheckPoint = 1;
|
||||
lutil_ServiceStatus.dwWaitHint = SCM_NOTIFICATION_INTERVAL * 2;
|
||||
|
||||
SetServiceStatus(hSLAPDServiceStatus, &SLAPDServiceStatus);
|
||||
SetServiceStatus(hlutil_ServiceStatus, &lutil_ServiceStatus);
|
||||
|
||||
/* start up a thread to keep sending SERVICE_START_PENDING to the Service Control Manager
|
||||
* until the slapd listener is completed and listening. Only then should we send
|
||||
|
|
@ -449,9 +437,9 @@ void CommenceStartupProcessing( LPCTSTR lpszServiceName,
|
|||
/* failed to create the event to determine when the startup process is complete so
|
||||
* tell the Service Control Manager to wait another 30 seconds before deploying its
|
||||
* assasin */
|
||||
SLAPDServiceStatus.dwCheckPoint++;
|
||||
SLAPDServiceStatus.dwWaitHint = THIRTY_SECONDS;
|
||||
SetServiceStatus(hSLAPDServiceStatus, &SLAPDServiceStatus);
|
||||
lutil_ServiceStatus.dwCheckPoint++;
|
||||
lutil_ServiceStatus.dwWaitHint = THIRTY_SECONDS;
|
||||
SetServiceStatus(hlutil_ServiceStatus, &lutil_ServiceStatus);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -466,14 +454,14 @@ void CommenceStartupProcessing( LPCTSTR lpszServiceName,
|
|||
* service startup is proceeding.
|
||||
* tell the Service Control Manager to wait another 30 seconds before deploying its
|
||||
* assasin. */
|
||||
SLAPDServiceStatus.dwCheckPoint++;
|
||||
SLAPDServiceStatus.dwWaitHint = THIRTY_SECONDS;
|
||||
SetServiceStatus(hSLAPDServiceStatus, &SLAPDServiceStatus);
|
||||
lutil_ServiceStatus.dwCheckPoint++;
|
||||
lutil_ServiceStatus.dwWaitHint = THIRTY_SECONDS;
|
||||
SetServiceStatus(hlutil_ServiceStatus, &lutil_ServiceStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ReportSlapdShutdownComplete( )
|
||||
void lutil_ReportShutdownComplete( )
|
||||
{
|
||||
if ( is_NT_Service )
|
||||
{
|
||||
|
|
@ -486,10 +474,10 @@ void ReportSlapdShutdownComplete( )
|
|||
if (ldap_pvt_thread_join( stop_status_tid, (void *) NULL ) == -1)
|
||||
ldap_pvt_thread_sleep( SCM_NOTIFICATION_INTERVAL / 2 );
|
||||
|
||||
SLAPDServiceStatus.dwCurrentState = SERVICE_STOPPED;
|
||||
SLAPDServiceStatus.dwCheckPoint++;
|
||||
SLAPDServiceStatus.dwWaitHint = SCM_NOTIFICATION_INTERVAL;
|
||||
SetServiceStatus(hSLAPDServiceStatus, &SLAPDServiceStatus);
|
||||
lutil_ServiceStatus.dwCurrentState = SERVICE_STOPPED;
|
||||
lutil_ServiceStatus.dwCheckPoint++;
|
||||
lutil_ServiceStatus.dwWaitHint = SCM_NOTIFICATION_INTERVAL;
|
||||
SetServiceStatus(hlutil_ServiceStatus, &lutil_ServiceStatus);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
BIN
libraries/liblutil/slapdmsg.bin
Normal file
BIN
libraries/liblutil/slapdmsg.bin
Normal file
Binary file not shown.
65
libraries/liblutil/slapdmsg.h
Normal file
65
libraries/liblutil/slapdmsg.h
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
//
|
||||
// This file contains message strings for the OpenLDAP slapd service.
|
||||
//
|
||||
// This file should be compiled as follows
|
||||
// mc -v slapdmsg.mc -r $(IntDir)
|
||||
// rc /v /r $(IntDir)\slapdmsg.rc
|
||||
// The mc (message compiler) command generates the .rc and .h files from this file. The
|
||||
// rc (resource compiler) takes the .rc file and produces a .res file that can be linked
|
||||
// with the final executable application. The application is then registered as a message
|
||||
// source with by creating the appropriate entries in the system registry.
|
||||
//
|
||||
//
|
||||
// Values are 32 bit values layed out as follows:
|
||||
//
|
||||
// 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
|
||||
// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
|
||||
// +---+-+-+-----------------------+-------------------------------+
|
||||
// |Sev|C|R| Facility | Code |
|
||||
// +---+-+-+-----------------------+-------------------------------+
|
||||
//
|
||||
// where
|
||||
//
|
||||
// Sev - is the severity code
|
||||
//
|
||||
// 00 - Success
|
||||
// 01 - Informational
|
||||
// 10 - Warning
|
||||
// 11 - Error
|
||||
//
|
||||
// C - is the Customer code flag
|
||||
//
|
||||
// R - is a reserved bit
|
||||
//
|
||||
// Facility - is the facility code
|
||||
//
|
||||
// Code - is the facility's status code
|
||||
//
|
||||
//
|
||||
// Define the facility codes
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// Define the severity codes
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// MessageId: MSG_SVC_STARTED
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// OpenLDAP service started. debuglevel=%1, conffile=%2, urls=%3
|
||||
//
|
||||
#define MSG_SVC_STARTED 0x40000500L
|
||||
|
||||
//
|
||||
// MessageId: MSG_SVC_STOPPED
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// OpenLDAP service stopped.
|
||||
//
|
||||
#define MSG_SVC_STOPPED 0x40000501L
|
||||
|
||||
28
libraries/liblutil/slapdmsg.mc
Normal file
28
libraries/liblutil/slapdmsg.mc
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
;//
|
||||
;// This file contains message strings for the OpenLDAP slapd service.
|
||||
;//
|
||||
;// This file should be compiled as follows
|
||||
;// mc -v slapdmsg.mc -r $(IntDir)
|
||||
;// rc /v /r $(IntDir)\slapdmsg.rc
|
||||
;// The mc (message compiler) command generates the .rc and .h files from this file. The
|
||||
;// rc (resource compiler) takes the .rc file and produces a .res file that can be linked
|
||||
;// with the final executable application. The application is then registered as a message
|
||||
;// source with by creating the appropriate entries in the system registry.
|
||||
;//
|
||||
|
||||
MessageID=0x500
|
||||
Severity=Informational
|
||||
SymbolicName=MSG_SVC_STARTED
|
||||
Facility=Application
|
||||
Language=English
|
||||
OpenLDAP service started. debuglevel=%1, conffile=%2, urls=%3
|
||||
.
|
||||
|
||||
|
||||
MessageID=0x501
|
||||
Severity=Informational
|
||||
SymbolicName=MSG_SVC_STOPPED
|
||||
Facility=Application
|
||||
Language=English
|
||||
OpenLDAP service stopped.
|
||||
.
|
||||
2
libraries/liblutil/slapdmsg.rc
Normal file
2
libraries/liblutil/slapdmsg.rc
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
LANGUAGE 0x9,0x1
|
||||
1 11 slapdmsg.bin
|
||||
|
|
@ -32,15 +32,10 @@ static RETSIGTYPE wait4child( int sig );
|
|||
#define MAIN_RETURN(x) return
|
||||
static struct sockaddr_in bind_addr;
|
||||
|
||||
void CommenceStartupProcessing( LPCTSTR serverName,
|
||||
void(*stopper)(int));
|
||||
void ReportSlapdShutdownComplete( void );
|
||||
void *getRegParam( char *svc, char *value );
|
||||
|
||||
#define SERVICE_EXIT( e, n ) do { \
|
||||
if ( is_NT_Service ) { \
|
||||
SLAPDServiceStatus.dwWin32ExitCode = (e); \
|
||||
SLAPDServiceStatus.dwServiceSpecificExitCode = (n); \
|
||||
lutil_ServiceStatus.dwWin32ExitCode = (e); \
|
||||
lutil_ServiceStatus.dwServiceSpecificExitCode = (n); \
|
||||
} \
|
||||
} while ( 0 )
|
||||
|
||||
|
|
@ -49,11 +44,6 @@ void *getRegParam( char *svc, char *value );
|
|||
#define MAIN_RETURN(x) return(x)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NT_EVENT_LOG
|
||||
void LogSlapdStartedEvent( char *svc, int slap_debug, char *configfile, char *urls );
|
||||
void LogSlapdStoppedEvent( char *svc );
|
||||
#endif
|
||||
|
||||
/*
|
||||
* when more than one slapd is running on one machine, each one might have
|
||||
* it's own LOCAL for syslogging and must have its own pid/args files
|
||||
|
|
@ -170,12 +160,12 @@ int main( int argc, char **argv )
|
|||
|
||||
if ( is_NT_Service ) {
|
||||
serverName = argv[0];
|
||||
CommenceStartupProcessing( serverName, slap_sig_shutdown );
|
||||
lutil_CommenceStartupProcessing( serverName, slap_sig_shutdown );
|
||||
if ( strcmp(serverName, SERVICE_NAME) )
|
||||
regService = serverName;
|
||||
}
|
||||
|
||||
i = (int*)getRegParam( regService, "DebugLevel" );
|
||||
i = (int*)lutil_getRegParam( regService, "DebugLevel" );
|
||||
if ( i != NULL )
|
||||
{
|
||||
slap_debug = *i;
|
||||
|
|
@ -189,7 +179,7 @@ int main( int argc, char **argv )
|
|||
#endif
|
||||
}
|
||||
|
||||
newUrls = (char *) getRegParam(regService, "Urls");
|
||||
newUrls = (char *) lutil_getRegParam(regService, "Urls");
|
||||
if (newUrls)
|
||||
{
|
||||
if (urls)
|
||||
|
|
@ -206,7 +196,7 @@ int main( int argc, char **argv )
|
|||
|
||||
}
|
||||
|
||||
newConfigFile = (char*)getRegParam( regService, "ConfigFile" );
|
||||
newConfigFile = (char*)lutil_getRegParam( regService, "ConfigFile" );
|
||||
if ( newConfigFile != NULL )
|
||||
{
|
||||
configfile = newConfigFile;
|
||||
|
|
@ -561,7 +551,7 @@ int main( int argc, char **argv )
|
|||
|
||||
#ifdef HAVE_NT_EVENT_LOG
|
||||
if (is_NT_Service)
|
||||
LogSlapdStartedEvent( serverName, slap_debug, configfile, urls );
|
||||
lutil_LogStartedEvent( serverName, slap_debug, configfile, urls );
|
||||
#endif
|
||||
|
||||
rc = slapd_daemon();
|
||||
|
|
@ -589,7 +579,7 @@ destroy:
|
|||
stop:
|
||||
#ifdef HAVE_NT_EVENT_LOG
|
||||
if (is_NT_Service)
|
||||
LogSlapdStoppedEvent( serverName );
|
||||
lutil_LogStoppedEvent( serverName );
|
||||
#endif
|
||||
|
||||
#ifdef NEW_LOGGING
|
||||
|
|
@ -600,7 +590,7 @@ stop:
|
|||
|
||||
|
||||
#ifdef HAVE_NT_SERVICE_MANAGER
|
||||
ReportSlapdShutdownComplete();
|
||||
lutil_ReportShutdownComplete();
|
||||
#endif
|
||||
|
||||
#ifdef LOG_DEBUG
|
||||
|
|
|
|||
101
servers/slapd/nt_svc.c
Normal file
101
servers/slapd/nt_svc.c
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
/* $OpenLDAP$ */
|
||||
/*
|
||||
* Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
|
||||
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
||||
*/
|
||||
|
||||
#include "portable.h"
|
||||
#include <stdio.h>
|
||||
#include <ac/string.h>
|
||||
#include "slap.h"
|
||||
#include "lutil.h"
|
||||
|
||||
#ifdef HAVE_NT_SERVICE_MANAGER
|
||||
|
||||
/* in main.c */
|
||||
void WINAPI ServiceMain( DWORD argc, LPTSTR *argv );
|
||||
|
||||
/* in ntservice.c */
|
||||
int main( int argc, LPTSTR *argv )
|
||||
{
|
||||
int length;
|
||||
char filename[MAX_PATH], *fname_start;
|
||||
|
||||
/*
|
||||
* Because the service was registered as SERVICE_WIN32_OWN_PROCESS,
|
||||
* the lpServiceName element of the SERVICE_TABLE_ENTRY will be
|
||||
* ignored.
|
||||
*/
|
||||
|
||||
SERVICE_TABLE_ENTRY DispatchTable[] = {
|
||||
{ "", (LPSERVICE_MAIN_FUNCTION) ServiceMain },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
/*
|
||||
* set the service's current directory to the installation directory
|
||||
* for the service. this way we don't have to write absolute paths
|
||||
* in the configuration files
|
||||
*/
|
||||
GetModuleFileName( NULL, filename, sizeof( filename ) );
|
||||
fname_start = strrchr( filename, *LDAP_DIRSEP );
|
||||
|
||||
if ( argc > 1 ) {
|
||||
if ( _stricmp( "install", argv[1] ) == 0 )
|
||||
{
|
||||
char *svcName = SERVICE_NAME;
|
||||
char *displayName = "OpenLDAP Directory Service";
|
||||
BOOL auto_start = FALSE;
|
||||
|
||||
if ( (argc > 2) && (argv[2] != NULL) )
|
||||
svcName = argv[2];
|
||||
|
||||
if ( argc > 3 && argv[3])
|
||||
displayName = argv[3];
|
||||
|
||||
if ( argc > 4 && stricmp(argv[4], "auto") == 0)
|
||||
auto_start = TRUE;
|
||||
|
||||
strcat(filename, " service");
|
||||
if ( !lutil_srv_install(svcName, displayName, filename, auto_start) )
|
||||
{
|
||||
fputs( "service failed installation ...\n", stderr );
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
fputs( "service has been installed ...\n", stderr );
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
if ( _stricmp( "remove", argv[1] ) == 0 )
|
||||
{
|
||||
char *svcName = SERVICE_NAME;
|
||||
if ( (argc > 2) && (argv[2] != NULL) )
|
||||
svcName = argv[2];
|
||||
if ( !lutil_srv_remove(svcName, filename) )
|
||||
{
|
||||
fputs( "failed to remove the service ...\n", stderr );
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
fputs( "service has been removed ...\n", stderr );
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if ( _stricmp( "service", argv[1] ) == 0 )
|
||||
{
|
||||
is_NT_Service = 1;
|
||||
*fname_start = '\0';
|
||||
SetCurrentDirectory( filename );
|
||||
}
|
||||
}
|
||||
|
||||
if (is_NT_Service)
|
||||
{
|
||||
StartServiceCtrlDispatcher(DispatchTable);
|
||||
} else
|
||||
{
|
||||
ServiceMain( argc, argv );
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
# $OpenLDAP$
|
||||
## Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
|
||||
## Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
|
||||
## COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
||||
##
|
||||
## Makefile.in for slurpd
|
||||
|
|
@ -10,12 +10,17 @@ XPROGRAMS = sslurpd
|
|||
|
||||
XSRCS = version.c
|
||||
|
||||
NT_SRCS = nt_svc.c
|
||||
NT_OBJS = nt_svc.o ../../libraries/liblutil/slapdmsg.res
|
||||
|
||||
SRCS = admin.c args.c ch_malloc.c config.c \
|
||||
fm.c globals.c ldap_op.c lock.c main.c re.c \
|
||||
reject.c replica.c replog.c ri.c rq.c sanity.c st.c
|
||||
reject.c replica.c replog.c ri.c rq.c sanity.c st.c \
|
||||
$(@PLAT@_SRCS)
|
||||
OBJS = admin.o args.o ch_malloc.o config.o \
|
||||
fm.o globals.o ldap_op.o lock.o main.o re.o \
|
||||
reject.o replica.o replog.o ri.o rq.o sanity.o st.o
|
||||
reject.o replica.o replog.o ri.o rq.o sanity.o st.o \
|
||||
$(@PLAT@_OBJS)
|
||||
|
||||
LDAP_INCDIR= ../../include
|
||||
LDAP_LIBDIR= ../../libraries
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ usage( char *name )
|
|||
#else /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
|
||||
fprintf( stderr, "\t\t[-t tmp-dir] [-o]\n" );
|
||||
#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
|
||||
fprintf( stderr, "\t\t[-n service-name]\n" );
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -67,7 +68,7 @@ doargs(
|
|||
g->myname = strdup( g->myname + 1 );
|
||||
}
|
||||
|
||||
while ( (i = getopt( argc, argv, "d:f:or:t:" )) != EOF ) {
|
||||
while ( (i = getopt( argc, argv, "d:f:n:or:t:" )) != EOF ) {
|
||||
switch ( i ) {
|
||||
case 'd': /* set debug level and 'do not detach' flag */
|
||||
g->no_detach = 1;
|
||||
|
|
@ -109,6 +110,10 @@ doargs(
|
|||
case 'f': /* slapd config file */
|
||||
g->slapd_configfile = strdup( optarg );
|
||||
break;
|
||||
case 'n': /* NT service name *.
|
||||
if ( g->serverName ) free( g->serverName );
|
||||
g->serverName = strdup( optarg );
|
||||
break;
|
||||
case 'o':
|
||||
g->one_shot_mode = 1;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@
|
|||
*/
|
||||
static char *get_record LDAP_P(( FILE * ));
|
||||
static void populate_queue LDAP_P(( char *f ));
|
||||
static RETSIGTYPE set_shutdown LDAP_P((int));
|
||||
|
||||
|
||||
/*
|
||||
|
|
@ -60,11 +59,14 @@ fm(
|
|||
* LDAP_SIGUSR2 - causes a shutdown
|
||||
*/
|
||||
(void) SIGNAL( LDAP_SIGUSR1, do_nothing );
|
||||
(void) SIGNAL( LDAP_SIGUSR2, set_shutdown );
|
||||
(void) SIGNAL( SIGTERM, set_shutdown );
|
||||
(void) SIGNAL( SIGINT, set_shutdown );
|
||||
(void) SIGNAL( LDAP_SIGUSR2, slurp_set_shutdown );
|
||||
(void) SIGNAL( SIGTERM, slurp_set_shutdown );
|
||||
(void) SIGNAL( SIGINT, slurp_set_shutdown );
|
||||
#ifdef SIGHUP
|
||||
(void) SIGNAL( SIGHUP, set_shutdown );
|
||||
(void) SIGNAL( SIGHUP, slurp_set_shutdown );
|
||||
#endif
|
||||
#ifdef SIGBREAK
|
||||
(void) SIGNAL( SIGBREAK, slurp_set_shutdown );
|
||||
#endif
|
||||
|
||||
if ( sglob->one_shot_mode ) {
|
||||
|
|
@ -155,11 +157,15 @@ fm(
|
|||
/*
|
||||
* Set a global flag which signals that we're shutting down.
|
||||
*/
|
||||
static RETSIGTYPE
|
||||
set_shutdown(int sig)
|
||||
RETSIGTYPE
|
||||
slurp_set_shutdown(int sig)
|
||||
{
|
||||
int i;
|
||||
|
||||
#if HAVE_NT_SERVICE_MANAGER && SIGBREAK
|
||||
if (sig == SIGBREAK) return do_nothing( sig );
|
||||
#endif
|
||||
|
||||
sglob->slurpd_shutdown = 1; /* set flag */
|
||||
ldap_pvt_thread_kill( sglob->fm_tid, LDAP_SIGUSR1 ); /* wake up file mgr */
|
||||
sglob->rq->rq_lock( sglob->rq ); /* lock queue */
|
||||
|
|
@ -168,7 +174,7 @@ set_shutdown(int sig)
|
|||
(sglob->replicas[ i ])->ri_wake( sglob->replicas[ i ]);
|
||||
}
|
||||
sglob->rq->rq_unlock( sglob->rq ); /* unlock queue */
|
||||
(void) SIGNAL_REINSTALL( sig, set_shutdown ); /* reinstall handlers */
|
||||
(void) SIGNAL_REINSTALL( sig, slurp_set_shutdown ); /* reinstall handlers */
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ int ldap_syslog_level = 0;
|
|||
#endif
|
||||
int ldap_debug = 0;
|
||||
|
||||
|
||||
/*
|
||||
* Initialize the globals
|
||||
*/
|
||||
|
|
@ -53,12 +52,17 @@ init_globals( void )
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef HAVE_NT_SERVICE_MANAGER
|
||||
g->slapd_configfile = ".\\slapd.conf";
|
||||
g->slurpd_rdir = ".\\replica";
|
||||
#else
|
||||
g->slapd_configfile = SLAPD_DEFAULT_CONFIGFILE;
|
||||
g->slurpd_rdir = DEFAULT_SLURPD_REPLICA_DIR "/replica";
|
||||
#endif
|
||||
g->no_work_interval = DEFAULT_NO_WORK_INTERVAL;
|
||||
g->slurpd_shutdown = 0;
|
||||
g->num_replicas = 0;
|
||||
g->replicas = NULL;
|
||||
g->slurpd_rdir = DEFAULT_SLURPD_REPLICA_DIR "/replica";
|
||||
strcpy( g->slurpd_status_file, DEFAULT_SLURPD_STATUS_FILE );
|
||||
g->slapd_replogfile[ 0 ] = '\0';
|
||||
g->slurpd_replogfile[ 0 ] = '\0';
|
||||
|
|
@ -66,6 +70,7 @@ init_globals( void )
|
|||
g->one_shot_mode = 0;
|
||||
g->no_detach = 0;
|
||||
g->myname = NULL;
|
||||
g->serverName = NULL;
|
||||
g->srpos = 0L;
|
||||
if ( St_init( &(g->st)) < 0 ) {
|
||||
fprintf( stderr, "Cannot initialize status data\n" );
|
||||
|
|
|
|||
|
|
@ -1,3 +1,8 @@
|
|||
/* $OpenLDAP$ */
|
||||
/*
|
||||
* Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
|
||||
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 1996 Regents of the University of Michigan.
|
||||
* All rights reserved.
|
||||
|
|
@ -10,6 +15,8 @@
|
|||
* is provided ``as is'' without express or implied warranty.
|
||||
*/
|
||||
|
||||
#ifndef SLURPD_GLOBALS_H
|
||||
#define SLURPD_GLOBALS_H 1
|
||||
|
||||
/*
|
||||
* globals.h - definition of structure holding global data.
|
||||
|
|
@ -17,15 +24,17 @@
|
|||
|
||||
#include "slurp.h"
|
||||
|
||||
LDAP_BEGIN_DECL
|
||||
|
||||
typedef struct globals {
|
||||
/* Thread ID for file manager thread */
|
||||
pthread_t fm_tid;
|
||||
ldap_pvt_thread_t fm_tid;
|
||||
/* The name of the slapd config file (which is also our config file) */
|
||||
char *slapd_configfile;
|
||||
/* How long the master slurpd sleeps when there's no work to do */
|
||||
int no_work_interval;
|
||||
/* We keep running until slurpd_shutdown is nonzero. HUP signal set this */
|
||||
int slurpd_shutdown;
|
||||
sig_atomic_t slurpd_shutdown;
|
||||
/* Number of replicas we're servicing */
|
||||
int num_replicas;
|
||||
/* Array of pointers to replica info */
|
||||
|
|
@ -40,25 +49,29 @@ typedef struct globals {
|
|||
char slurpd_replogfile[ MAXPATHLEN ];
|
||||
/* Non-zero if we were given a replog file to process on command-line */
|
||||
int one_shot_mode;
|
||||
/* Non-zero if we should not detach the process */
|
||||
int no_detach;
|
||||
/* Name of program */
|
||||
char *myname;
|
||||
/* NT service name */
|
||||
char *serverName;
|
||||
/* Current offset into slurpd replica logfile */
|
||||
off_t srpos;
|
||||
/* mutex to serialize access to reject file */
|
||||
pthread_mutex_t rej_mutex;
|
||||
ldap_pvt_thread_mutex_t rej_mutex;
|
||||
/* pointer to status struct */
|
||||
St *st;
|
||||
/* Pointer to replication queue */
|
||||
Rq *rq;
|
||||
#ifdef KERBEROS
|
||||
#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
|
||||
/* Default name of kerberos srvtab file */
|
||||
char *default_srvtab;
|
||||
#endif /* KERBEROS */
|
||||
#if defined( THREAD_SUNOS4_LWP )
|
||||
tl_t *tsl_list;
|
||||
mon_t tsl_mon;
|
||||
#endif /* THREAD_SUNOS4_LWP */
|
||||
#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND */
|
||||
} Globals;
|
||||
|
||||
|
||||
extern Globals *sglob;
|
||||
|
||||
LDAP_END_DECL
|
||||
|
||||
#endif /* SLURPD_GLOBALS_H */
|
||||
|
|
|
|||
|
|
@ -32,11 +32,24 @@
|
|||
|
||||
#include <ldap_pvt.h>
|
||||
|
||||
int
|
||||
main(
|
||||
int argc,
|
||||
char **argv
|
||||
)
|
||||
#ifdef HAVE_NT_SERVICE_MANAGER
|
||||
#define MAIN_RETURN(x) return
|
||||
#define SERVICE_EXIT( e, n ) do { \
|
||||
if ( is_NT_Service ) { \
|
||||
lutil_ServiceStatus.dwWin32ExitCode = (e); \
|
||||
lutil_ServiceStatus.dwServiceSpecificExitCode = (n); \
|
||||
} \
|
||||
} while ( 0 )
|
||||
#else
|
||||
#define SERVICE_EXIT( e, n )
|
||||
#define MAIN_RETURN(x) return(x)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NT_SERVICE_MANAGER
|
||||
void WINAPI ServiceMain( DWORD argc, LPTSTR *argv )
|
||||
#else
|
||||
int main( int argc, char **argv )
|
||||
#endif
|
||||
{
|
||||
#ifdef NO_THREADS
|
||||
/* Haven't yet written the non-threaded version */
|
||||
|
|
@ -44,7 +57,7 @@ main(
|
|||
return( 1 );
|
||||
#else
|
||||
|
||||
int i;
|
||||
int i, rc = 0;
|
||||
|
||||
/* initialize thread package */
|
||||
ldap_pvt_thread_initialize();
|
||||
|
|
@ -55,14 +68,60 @@ main(
|
|||
*/
|
||||
if (( sglob = init_globals()) == NULL ) {
|
||||
fprintf( stderr, "Out of memory initializing globals\n" );
|
||||
exit( EXIT_FAILURE );
|
||||
SERVICE_EXIT( ERROR_NOT_ENOUGH_MEMORY, 0 );
|
||||
rc = 1;
|
||||
goto stop;
|
||||
}
|
||||
|
||||
#ifdef HAVE_NT_SERVICE_MANAGER
|
||||
{
|
||||
int *i;
|
||||
char *newConfigFile;
|
||||
char *regService = NULL;
|
||||
|
||||
if ( is_NT_Service ) {
|
||||
sglob->serverName = argv[0];
|
||||
lutil_CommenceStartupProcessing( sglob->serverName, slurp_set_shutdown );
|
||||
if ( strcmp(sglob->serverName, SERVICE_NAME) )
|
||||
regService = sglob->serverName;
|
||||
}
|
||||
|
||||
i = (int*)lutil_getRegParam( regService, "DebugLevel" );
|
||||
if ( i != NULL )
|
||||
{
|
||||
ldap_debug = *i;
|
||||
#ifdef NEW_LOGGING
|
||||
lutil_log_initialize( argc, argv );
|
||||
LDAP_LOG( SLURPD, INFO,
|
||||
"main: new debug level from registry is: %d\n",
|
||||
ldap_debug, 0, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY, "new debug level from registry is: %d\n", ldap_debug, 0, 0 );
|
||||
#endif
|
||||
}
|
||||
|
||||
newConfigFile = (char*)lutil_getRegParam( regService, "ConfigFile" );
|
||||
if ( newConfigFile != NULL )
|
||||
{
|
||||
sglob->slapd_configfile = newConfigFile;
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( SLURPD, INFO,
|
||||
"main: new config file from registry is: %s\n", sglob->slapd_configfile, 0, 0 );
|
||||
#else
|
||||
Debug ( LDAP_DEBUG_ANY, "new config file from registry is: %s\n", sglob->slapd_configfile, 0, 0 );
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Process command-line args and fill in globals.
|
||||
*/
|
||||
if ( doargs( argc, argv, sglob ) < 0 ) {
|
||||
exit( EXIT_FAILURE );
|
||||
SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 15 );
|
||||
rc = 1;
|
||||
goto stop;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -72,13 +131,17 @@ main(
|
|||
fprintf( stderr,
|
||||
"Errors encountered while processing config file \"%s\"\n",
|
||||
sglob->slapd_configfile );
|
||||
exit( EXIT_FAILURE );
|
||||
SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 19 );
|
||||
rc = 1;
|
||||
goto stop;
|
||||
}
|
||||
|
||||
#ifdef HAVE_TLS
|
||||
if( ldap_pvt_tls_init() || ldap_pvt_tls_init_def_ctx() ) {
|
||||
fprintf( stderr, "TLS Initialization failed.\n" );
|
||||
exit( EXIT_FAILURE);
|
||||
SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
|
||||
rc = 1;
|
||||
goto stop;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -87,7 +150,9 @@ main(
|
|||
*/
|
||||
if ( mkdir(sglob->slurpd_rdir, 0755) == -1 && errno != EEXIST) {
|
||||
perror(sglob->slurpd_rdir);
|
||||
exit( 1 );
|
||||
SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 16 );
|
||||
rc = 1;
|
||||
goto stop;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -96,7 +161,9 @@ main(
|
|||
if ( sglob->st->st_read( sglob->st )) {
|
||||
fprintf( stderr, "Malformed slurpd status file \"%s\"\n",
|
||||
sglob->slurpd_status_file, 0, 0 );
|
||||
exit( EXIT_FAILURE );
|
||||
SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 17 );
|
||||
rc = 1;
|
||||
goto stop;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -104,7 +171,9 @@ main(
|
|||
* Check for any fatal error conditions before we get started
|
||||
*/
|
||||
if ( sanity() < 0 ) {
|
||||
exit( EXIT_FAILURE );
|
||||
SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 18 );
|
||||
rc = 1;
|
||||
goto stop;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -116,6 +185,10 @@ main(
|
|||
lutil_detach( 0, 0 );
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NT_EVENT_LOG
|
||||
if (is_NT_Service) lutil_LogStartedEvent( sglob->serverName, ldap_debug, sglob->slapd_configfile, "n/a" );
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Start the main file manager thread (in fm.c).
|
||||
*/
|
||||
|
|
@ -129,7 +202,9 @@ main(
|
|||
Debug( LDAP_DEBUG_ANY, "file manager ldap_pvt_thread_create failed\n",
|
||||
0, 0, 0 );
|
||||
#endif
|
||||
exit( EXIT_FAILURE );
|
||||
SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 21 );
|
||||
rc = 1;
|
||||
goto stop;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -147,6 +222,10 @@ main(
|
|||
start_replica_thread( sglob->replicas[ i ]);
|
||||
}
|
||||
|
||||
#ifdef HAVE_NT_SERVICE_MANAGER
|
||||
if ( started_event ) ldap_pvt_thread_cond_signal( &started_event );
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Wait for the fm thread to finish.
|
||||
*/
|
||||
|
|
@ -161,6 +240,14 @@ main(
|
|||
ldap_pvt_thread_join( sglob->replicas[ i ]->ri_tid, (void *) NULL );
|
||||
}
|
||||
|
||||
stop:
|
||||
#ifdef HAVE_NT_SERVICE_MANAGER
|
||||
if (is_NT_Service) {
|
||||
ldap_pvt_thread_cond_destroy( &started_event );
|
||||
lutil_LogStoppedEvent( sglob->serverName );
|
||||
lutil_ReportShutdownComplete();
|
||||
}
|
||||
#endif
|
||||
/* destroy the thread package */
|
||||
ldap_pvt_thread_destroy();
|
||||
|
||||
|
|
@ -169,6 +256,6 @@ main(
|
|||
#else
|
||||
Debug( LDAP_DEBUG_ANY, "slurpd: terminated.\n", 0, 0, 0 );
|
||||
#endif
|
||||
return 0;
|
||||
MAIN_RETURN(rc);
|
||||
#endif /* !NO_THREADS */
|
||||
}
|
||||
|
|
|
|||
81
servers/slurpd/proto-slurp.h
Normal file
81
servers/slurpd/proto-slurp.h
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/* $OpenLDAP$ */
|
||||
/*
|
||||
* Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
|
||||
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
||||
*/
|
||||
#ifndef _PROTO_SLURP
|
||||
#define _PROTO_SLURP
|
||||
|
||||
#include <ldap_cdefs.h>
|
||||
|
||||
struct globals;
|
||||
|
||||
/* admin.c */
|
||||
RETSIGTYPE do_admin LDAP_P((int sig));
|
||||
|
||||
/* args.c */
|
||||
int doargs LDAP_P((int argc, char **argv, struct globals *g));
|
||||
|
||||
/* ch_malloc.c */
|
||||
#ifdef CSRIMALLOC
|
||||
#define ch_malloc malloc
|
||||
#define ch_realloc realloc
|
||||
#define ch_calloc calloc
|
||||
#define ch_free free
|
||||
#else
|
||||
void *ch_malloc LDAP_P((ber_len_t size));
|
||||
void *ch_realloc LDAP_P((void *block, ber_len_t size));
|
||||
void *ch_calloc LDAP_P((ber_len_t nelem, ber_len_t size));
|
||||
void ch_free LDAP_P((void *p));
|
||||
#endif
|
||||
|
||||
/* config.c */
|
||||
int slurpd_read_config LDAP_P((char *fname));
|
||||
|
||||
/* ch_malloc.c */
|
||||
void ch_free LDAP_P(( void *p ));
|
||||
|
||||
/* fm.c */
|
||||
void *fm LDAP_P((void *arg));
|
||||
RETSIGTYPE do_nothing LDAP_P((int i));
|
||||
RETSIGTYPE slurp_set_shutdown LDAP_P((int));
|
||||
|
||||
/* globals.c */
|
||||
extern struct globals *sglob;
|
||||
extern int ldap_syslog;
|
||||
extern int ldap_syslog_level;
|
||||
extern int ldap_debug;
|
||||
extern struct globals *init_globals LDAP_P((void));
|
||||
|
||||
/* ldap_op.c */
|
||||
int do_ldap LDAP_P((Ri *ri, Re *re, char **errmsg));
|
||||
|
||||
/* lock.c */
|
||||
FILE *lock_fopen LDAP_P((const char *fname, const char *type, FILE **lfp));
|
||||
int lock_fclose LDAP_P((FILE *fp, FILE *lfp));
|
||||
int acquire_lock LDAP_P((const char *file, FILE **rfp, FILE **lfp));
|
||||
int relinquish_lock LDAP_P((const char *file, FILE *rfp, FILE *lfp));
|
||||
|
||||
/* reject.c */
|
||||
void write_reject LDAP_P((Ri *ri, Re *re, int lderr, char *errmsg));
|
||||
|
||||
/* replica.c */
|
||||
int start_replica_thread LDAP_P((Ri *ri));
|
||||
|
||||
/* replog.c */
|
||||
int copy_replog LDAP_P((char *src, char *dst));
|
||||
int file_nonempty LDAP_P((char *filename));
|
||||
|
||||
/* sanity.c */
|
||||
int sanity LDAP_P((void));
|
||||
|
||||
/* st.c */
|
||||
int St_init LDAP_P((St **st));
|
||||
|
||||
/* tsleep.c */
|
||||
int tsleep LDAP_P((time_t interval));
|
||||
#if defined( HAVE_LWP )
|
||||
void start_lwp_scheduler LDAP_P(( void ));
|
||||
#endif
|
||||
|
||||
#endif /* _PROTO_SLURP */
|
||||
|
|
@ -33,11 +33,11 @@
|
|||
#include <ac/string.h>
|
||||
#include <ac/ctype.h>
|
||||
|
||||
#include "../slapd/slap.h"
|
||||
|
||||
#include "slurp.h"
|
||||
#include "globals.h"
|
||||
|
||||
#include "../slapd/slap.h"
|
||||
|
||||
/* Forward references */
|
||||
static Rh *get_repl_hosts LDAP_P(( char *, int *, char ** ));
|
||||
static int gettype LDAP_P(( char * ));
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@
|
|||
#define S_IWGRP 0
|
||||
#endif
|
||||
|
||||
#undef SERVICE_NAME
|
||||
#define SERVICE_NAME OPENLDAP_PACKAGE "-slurpd"
|
||||
|
||||
/* Default directory for slurpd's private copy of replication logs */
|
||||
#define DEFAULT_SLURPD_REPLICA_DIR LDAP_RUNDIR LDAP_DIRSEP "openldap-slurp"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue