mostly logging

This commit is contained in:
Kurt Zeilenga 2002-07-28 21:18:10 +00:00
parent 6d013d754a
commit fcefc5aea9
26 changed files with 4535 additions and 614 deletions

50
contrib/ldapsasl/README Normal file
View file

@ -0,0 +1,50 @@
LDAP auxprop plugin for SASL-enabled servers.
Copyright (C) 2002 by Howard Chu, hyc@symas.com
This software is an experimental proof-of-concept and is not intended for
general use. It is licensed under the terms ofthe OpenLDAP license.
The file ldapdb.c was written for Cyrus SASL 2.1.3 and OpenLDAP 2.1.3.
It can be compiled by copying into the Cyrus SASL source tree, in the
plugins subdirectory. No configuration or build script is provided.
To compile, type "make ldapdb.lo". To link, you'll have to copy the
link rule for one of the other plugins. Below is a sample on my Linux
system:
/bin/sh ./libtool --mode=link gcc -Wall -W -g -O2 -L/usr/local/lib -Wl,-rpath,/usr/local/lib -module -export-dynamic -rpath /usr/lib/sasl2 -o libldapdb.la -version-info 2:4:0 ldapdb.lo -lldap -llber -lssl -lcrypto
Once installed, you need to add some config items to the SASL server's
config file in /usr/lib/sasl2. For example:
ldapdb_uri: ldapi://
ldapdb_id: root
ldapdb_pw: secret
ldapdb_mech: PLAIN
This config assumes an LDAP server on the same machine as the server
that is using SASL. The LDAP server must be configured to map the SASL
authcId "root" into a DN that has proxy authorization privileges to
every account that is allowed to login to this server. (See the OpenLDAP
Admin Guide for details.)
Unlike other LDAP-enabled plugins for other services that are common
on the web, this plugin does not require you to configure DN search
patterns to map usernames to LDAP DNs. This plugin requires SASL name
mapping to be configured on the target slapd. This approach keeps the
LDAP-specific configuration details in one place, the slapd.conf, and
makes the configuration of remote services much simpler.
One additional keyword "ldapdb_rc" may be specified in the config file.
The filename specified here will be put into the server's LDAPRC
environment variable, and libldap-specific config options may be set
in that ldaprc file. The main purpose behind this option is to allow
a client TLS certificate to be configured, so that SASL/EXTERNAL may
be used between the SASL server and the LDAP server. This is the most
optimal way to use this plugin when the servers are on separate machines.
This plugin likely has very poor performance. You'll need something
better for a real production environment. Please send feedback via the
openldap-software mailing list for now.
-- Howard Chu, 2002-07-12

220
contrib/ldapsasl/ldapdb.c Normal file
View file

@ -0,0 +1,220 @@
/* SASL LDAP auxprop implementation
* Copyright (C) 2002 Howard Chu, hyc@symas.com
*/
#include <config.h>
#include <stdio.h>
#include "sasl.h"
#include "saslutil.h"
#include "saslplug.h"
#include "plugin_common.h"
#include <ldap.h>
static char ldapdb[] = "ldapdb";
SASL_AUXPROP_PLUG_INIT( ldapdb )
typedef struct ldapctx {
const char *uri; /* URI of LDAP server */
const char *id; /* SASL authcid to bind as */
const char *pw; /* password for bind */
const char *mech; /* SASL mech */
} ldapctx;
typedef struct gluectx {
ldapctx *lc;
sasl_server_params_t *lp;
const char *user;
} gluectx;
static int ldapdb_interact(LDAP *ld, unsigned flags __attribute__((unused)),
void *def, void *inter)
{
sasl_interact_t *in = inter;
gluectx *gc = def;
const char *p;
for (;in->id != SASL_CB_LIST_END;in++)
{
p = NULL;
switch(in->id)
{
case SASL_CB_GETREALM:
ldap_get_option(ld, LDAP_OPT_X_SASL_REALM, &p);
break;
case SASL_CB_AUTHNAME:
p = gc->lc->id;
break;
case SASL_CB_PASS:
p = gc->lc->pw;
break;
case SASL_CB_USER:
p = gc->user;
break;
}
if (p)
{
int l = strlen(p);
in->result = gc->lp->utils->malloc(l+1);
if (!in->result)
return LDAP_NO_MEMORY;
strcpy((char *)in->result, p);
in->len = l;
}
}
return LDAP_SUCCESS;
}
static void ldapdb_auxprop_lookup(void *glob_context,
sasl_server_params_t *sparams,
unsigned flags,
const char *user,
unsigned ulen)
{
ldapctx *ctx = glob_context;
int ret, i, n, *aindx;
const struct propval *pr;
LDAP *ld = NULL;
gluectx gc = { ctx, sparams, NULL };
struct berval *dn = NULL, **bvals;
LDAPMessage *msg, *res;
char **attrs = NULL, *authzid = NULL;
if(!ctx || !sparams || !user) return;
pr = sparams->utils->prop_get(sparams->propctx);
if(!pr) return;
/* count how many attrs to fetch */
for(i = 0, n = 0; pr[i].name; i++) {
if(pr[i].name[0] == '*' && (flags & SASL_AUXPROP_AUTHZID))
continue;
if(pr[i].values && !(flags & SASL_AUXPROP_OVERRIDE))
continue;
n++;
}
/* nothing to do, bail out */
if (!n) return;
/* alloc an array of attr names for search, and index to the props */
attrs = sparams->utils->malloc((n+1)*sizeof(char *)*2);
if (!attrs) return;
aindx = (int *)(attrs + n + 1);
/* copy attr list */
for (i=0, n=0; pr[i].name; i++) {
if(pr[i].name[0] == '*' && (flags & SASL_AUXPROP_AUTHZID))
continue;
if(pr[i].values && !(flags & SASL_AUXPROP_OVERRIDE))
continue;
attrs[n] = (char *)pr[i].name;
if (pr[i].name[0] == '*') attrs[n]++;
aindx[n] = i;
n++;
}
attrs[n] = NULL;
if(ldap_initialize(&ld, ctx->uri)) {
sparams->utils->free(attrs);
return;
}
authzid = sparams->utils->malloc(ulen + sizeof("u:"));
if (!authzid) goto done;
strcpy(authzid, "u:");
strcpy(authzid+2, user);
gc.user = authzid;
i = LDAP_VERSION3;
ret = ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &i);
ret = ldap_sasl_interactive_bind_s(ld, NULL, ctx->mech, NULL, NULL,
LDAP_SASL_QUIET, ldapdb_interact, &gc);
if (ret != LDAP_SUCCESS) goto done;
ret = ldap_extended_operation_s(ld, LDAP_EXOP_X_WHO_AM_I, NULL, NULL,
NULL, NULL, &dn);
if (ret != LDAP_SUCCESS || !dn) goto done;
if (dn->bv_val && !strncmp(dn->bv_val, "dn:", 3))
ret = ldap_search_s(ld, dn->bv_val+3, LDAP_SCOPE_BASE, "(objectclass=*)",
attrs, 0, &res);
ber_bvfree(dn);
if (ret != LDAP_SUCCESS) goto done;
for(msg=ldap_first_message(ld, res); msg; msg=ldap_next_message(ld, msg))
{
if (ldap_msgtype(msg) != LDAP_RES_SEARCH_ENTRY) continue;
for (i=0; i<n; i++)
{
bvals = ldap_get_values_len(ld, msg, attrs[i]);
if (!bvals) continue;
if (pr[aindx[i]].values)
sparams->utils->prop_erase(sparams->propctx, pr[aindx[i]].name);
sparams->utils->prop_set(sparams->propctx, pr[aindx[i]].name,
bvals[0]->bv_val, bvals[0]->bv_len);
ber_bvecfree(bvals);
}
}
ldap_msgfree(res);
done:
if(authzid) sparams->utils->free(authzid);
if(attrs) sparams->utils->free(attrs);
if(ld) ldap_unbind(ld);
}
static void ldapdb_auxprop_free(void *glob_ctx, const sasl_utils_t *utils)
{
utils->free(glob_ctx);
}
static sasl_auxprop_plug_t ldapdb_auxprop_plugin = {
0, /* Features */
0, /* spare */
NULL, /* glob_context */
ldapdb_auxprop_free, /* auxprop_free */
ldapdb_auxprop_lookup, /* auxprop_lookup */
ldapdb, /* name */
NULL /* spare */
};
int ldapdb_auxprop_plug_init(const sasl_utils_t *utils,
int max_version,
int *out_version,
sasl_auxprop_plug_t **plug,
const char *plugname __attribute__((unused)))
{
ldapctx tmp, *p;
const char *s;
if(!out_version || !plug) return SASL_BADPARAM;
if(max_version < SASL_AUXPROP_PLUG_VERSION) return SASL_BADVERS;
utils->getopt(utils->getopt_context, ldapdb, "ldapdb_uri", &tmp.uri, NULL);
if(!tmp.uri) return SASL_BADPARAM;
utils->getopt(utils->getopt_context, ldapdb, "ldapdb_id", &tmp.id, NULL);
utils->getopt(utils->getopt_context, ldapdb, "ldapdb_pw", &tmp.pw, NULL);
utils->getopt(utils->getopt_context, ldapdb, "ldapdb_mech", &tmp.mech, NULL);
utils->getopt(utils->getopt_context, ldapdb, "ldapdb_rc", &s, NULL);
if(s && setenv("LDAPRC", s, 1)) return SASL_BADPARAM;
p = utils->malloc(sizeof(ldapctx));
if (!p) return SASL_NOMEM;
*p = tmp;
ldapdb_auxprop_plugin.glob_context = p;
*out_version = SASL_AUXPROP_PLUG_VERSION;
*plug = &ldapdb_auxprop_plugin;
return SASL_OK;
}

10
libraries/Makefile.in Normal file
View file

@ -0,0 +1,10 @@
# $OpenLDAP$
## Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
## COPYING RESTRICTIONS APPLY, see COPYRIGHT file
##
## Libraries Makefile for OpenLDAP
SUBDIRS= liblutil liblunicode libldif \
liblber libldap libldap_r \
libavl libldbm librewrite

View file

@ -0,0 +1,20 @@
# $OpenLDAP$
## Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
## COPYING RESTRICTIONS APPLY, see COPYRIGHT file
##
## LIBAVL
##
SRCS = avl.c testavl.c
XSRCS = version.c
OBJS = avl.o
LDAP_INCDIR= ../../include
LDAP_LIBDIR= ../../libraries
LIBRARY = libavl.a
PROGRAMS = testavl
XLIBS = $(LIBRARY) $(LDAP_LIBLBER_LA) $(LDAP_LIBLUTIL_A)
testavl: $(XLIBS) testavl.o
$(LTLINK) -o $@ testavl.o $(LIBS)

View file

@ -0,0 +1,40 @@
# $OpenLDAP$
## Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
## COPYING RESTRICTIONS APPLY, see COPYRIGHT file
##
## LIBLBER
##
LIBRARY = liblber.la
NT_SRCS = nt_err.c
NT_OBJS = nt_err.lo
LIB_DEFS = -DLBER_LIBRARY
SRCS= assert.c decode.c encode.c io.c bprint.c debug.c \
memory.c options.c sockbuf.c $(@PLAT@_SRCS)
OBJS= assert.lo decode.lo encode.lo io.lo bprint.lo debug.lo\
memory.lo options.lo sockbuf.lo $(@PLAT@_OBJS)
XSRCS= version.c
PROGRAMS= dtest etest idtest
LDAP_INCDIR= ../../include
LDAP_LIBDIR= ../../libraries
XLIBS = $(LIBRARY) $(LDAP_LIBLUTIL_A)
XXLIBS =
NT_LINK_LIBS = $(AC_LIBS)
dtest: $(XLIBS) dtest.o
$(LTLINK) -o $@ dtest.o $(LIBS)
etest: $(XLIBS) etest.o
$(LTLINK) -o $@ etest.o $(LIBS)
idtest: $(XLIBS) idtest.o
$(LTLINK) -o $@ idtest.o $(LIBS)
install-local: FORCE
-$(MKDIR) $(DESTDIR)$(libdir)
$(LTINSTALL) $(INSTALLFLAGS) -m 644 $(LIBRARY) $(DESTDIR)$(libdir)

View file

@ -12,6 +12,7 @@
#include <ac/stdlib.h>
#include <ac/string.h>
#include <ac/time.h>
#include <ac/ctype.h>
#ifdef LDAP_SYSLOG
#include <ac/syslog.h>
@ -20,6 +21,7 @@
#include "ldap_log.h"
#include "ldap_defaults.h"
#include "lber.h"
#include "ldap_pvt.h"
struct DEBUGLEVEL
{
@ -27,7 +29,7 @@ struct DEBUGLEVEL
int level;
};
static struct DEBUGLEVEL **levelArray;
int ldap_loglevels[LDAP_SUBSYS_NUM];
static long numLevels = 0;
static FILE *log_file = NULL;
@ -56,6 +58,39 @@ static char *lutil_levels[] = {"emergency", "alert", "critical",
"results", "detail1", "detail2",
NULL};
static char *lutil_subsys[LDAP_SUBSYS_NUM] = {"global","operation", "transport",
"connection", "filter", "ber",
"config", "acl", "cache", "index",
"ldif", "tools", "slapd", "slurpd",
"backend", "back_bdb", "back_ldbm",
"back_ldap", "back_meta", "back_mon" };
int lutil_mnem2subsys( const char *subsys )
{
int i;
for( i = 0; i < LDAP_SUBSYS_NUM; i++ )
{
if ( !strcasecmp( subsys, lutil_subsys[i] ) )
{
return i;
}
}
return -1;
}
void lutil_set_all_backends( level )
{
int i;
for( i = 0; i < LDAP_SUBSYS_NUM; i++ )
{
if ( !strncasecmp( "back_", lutil_subsys[i], strlen("back_") ) )
{
ldap_loglevels[i] = level;
}
}
}
int lutil_mnem2level( const char *level )
{
int i;
@ -66,47 +101,38 @@ int lutil_mnem2level( const char *level )
return i;
}
}
return 0;
return -1;
}
static void addSubsys( const char *subsys, int level )
static int addSubsys( const char *subsys, int level )
{
int i, j;
int subsys_num;
if ( !strcasecmp( subsys, "global") ) global_level = level;
if ( !strcasecmp( subsys, "backend" ) )
{
lutil_set_all_backends( level );
return level;
}
else
{
subsys_num = lutil_mnem2subsys(subsys);
if(subsys_num < 0)
{
fprintf(stderr, "Unknown Subsystem name [ %s ] - Discarded\n",
subsys);
fflush(stderr);
return -1;
}
for( i = 0; i < numLevels; i++ )
{
if ( levelArray[i] == NULL )
{
levelArray[i] = (struct DEBUGLEVEL*)ber_memalloc( sizeof( struct DEBUGLEVEL ) );
levelArray[i]->subsystem = (char*)ber_memalloc( strlen( subsys ) + 1 );
strcpy ( levelArray[i]->subsystem, subsys );
levelArray[i]->level = level;
return;
}
if( !strcasecmp( subsys, levelArray[i]->subsystem ) )
{
levelArray[i]->level = level;
return;
}
ldap_loglevels[subsys_num] = level;
return level;
}
levelArray = (struct DEBUGLEVEL**)ber_memrealloc( levelArray, sizeof( struct DEBUGLEVEL* ) * (numLevels + 10) );
for( j = numLevels; j < (numLevels + 10); j++ )
{
levelArray[j] = NULL;
}
numLevels += 10;
levelArray[i] = (struct DEBUGLEVEL*)ber_memalloc( sizeof( struct DEBUGLEVEL ) );
levelArray[i]->subsystem = (char*)ber_memalloc( strlen( subsys ) + 1 );
strcpy( levelArray[i]->subsystem, subsys );
levelArray[i]->level = level;
return;
return -1;
}
void lutil_set_debug_level( const char* subsys, int level )
int lutil_set_debug_level( const char* subsys, int level )
{
addSubsys( subsys, level );
return( addSubsys( subsys, level ) );
}
int lutil_debug_file( FILE *file )
@ -126,33 +152,25 @@ void lutil_log_int(
time_t now;
struct tm *today;
#endif
int i;
size_t i;
char * t_subsys;
char * tmp;
if ( levelArray == NULL ) return; /* logging isn't set up */
/*
* Look for the subsystem in the level array. When we find it,
* break out of the loop.
*/
for( i = 0; i < numLevels; i++ ) {
if ( levelArray[i] == NULL ) break;
if ( ! strcasecmp( levelArray[i]->subsystem, subsys ) ) break;
}
/*
* If we didn't find the subsystem, or the set level is less than
* the requested output level, don't output it.
*/
if ( (level > global_level) &&
((i > numLevels ) || (levelArray[i] == NULL) || ( level > levelArray[i]->level )) )
{
return;
}
t_subsys = strdup(subsys);
for(tmp = t_subsys, i = 0; i < strlen(t_subsys); i++, tmp++)
*tmp = TOUPPER( (unsigned char) *tmp );
#ifdef LDAP_SYSLOG
/* we're configured to use syslog */
if( use_syslog ) {
#ifdef HAVE_VSYSLOG
vsyslog( debug2syslog(level), fmt, vl );
#else
char data[4096];
vsnprintf( data, sizeof(data), fmt, vl );
syslog( debug2syslog(level), data );
#endif
return;
}
#endif
@ -198,7 +216,10 @@ void lutil_log_int(
/*
* format the output data.
*/
fprintf(file, "\n%s:: ", t_subsys );
vfprintf( file, fmt, vl );
fflush( file );
}
/*
@ -206,13 +227,13 @@ void lutil_log_int(
* level of the log output and the format and data. Send this on to the
* internal routine with the print file, if any.
*/
void lutil_log( const char *subsys, int level, const char *fmt, ... )
void lutil_log( const int subsys, int level, const char *fmt, ... )
{
FILE* outfile = NULL;
va_list vl;
va_start( vl, fmt );
ber_get_option( NULL, LBER_OPT_LOG_PRINT_FILE, &outfile );
lutil_log_int( outfile, subsys, level, fmt, vl );
lutil_log_int( outfile, lutil_subsys[subsys], level, fmt, vl );
va_end( vl );
}
@ -232,32 +253,38 @@ void lutil_log_initialize(int argc, char **argv)
*/
for( i = 0; i < argc; i++ )
{
char *next = argv[i];
if ( i < argc-1 && next[0] == '-' && next[1] == 'd' )
{
char subsys[64];
int level;
char *optarg = argv[i+1];
char *index = strchr( optarg, '=' );
if ( index != NULL )
{
*index = 0;
strcpy ( subsys, optarg );
level = atoi( index+1 );
if ( level <= 0 ) level = lutil_mnem2level( index + 1 );
lutil_set_debug_level( subsys, level );
*index = '=';
}
else
{
global_level = atoi( optarg );
/*
* if a negative number was used, make the global level the
* maximum sane level.
*/
if ( global_level < 0 ) global_level = 65535;
}
}
char *next = argv[i];
if ( i < argc-1 && next[0] == '-' && next[1] == 'd' )
{
char subsys[64];
int level;
char *optarg = argv[i+1];
char *index = strchr( optarg, '=' );
if ( index != NULL )
{
*index = 0;
strcpy ( subsys, optarg );
level = atoi( index+1 );
if ( level <= 0 ) level = lutil_mnem2level( index + 1 );
lutil_set_debug_level( subsys, level );
*index = '=';
}
else
{
global_level = atoi( optarg );
ldap_loglevels[0] = global_level;
/*
* if a negative number was used, make the global level the
* maximum sane level.
*/
if ( global_level < 0 )
{
global_level = 65535;
ldap_loglevels[0] = 65535;
}
}
}
}
}
@ -296,6 +323,6 @@ void (lutil_debug)( int debug, int level, const char *fmt, ... )
fflush( log_file );
}
fputs( buffer, stderr );
fputs( buffer, stderr );
va_end( vl );
}

File diff suppressed because it is too large Load diff

View file

@ -812,8 +812,8 @@ ber_printf( BerElement *ber, LDAP_CONST char *fmt, ... )
default:
if( ber->ber_debug ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "liblber", LDAP_LEVEL_ERR,
"ber_printf: unknown fmt %c\n", *fmt ));
LDAP_LOG( BER, ERR,
"ber_printf: unknown fmt %c\n", *fmt, 0, 0 );
#else
ber_log_printf( LDAP_DEBUG_ANY, ber->ber_debug,
"ber_printf: unknown fmt %c\n", *fmt );

View file

@ -33,6 +33,7 @@
#endif
#include "lber-int.h"
#include "ldap_log.h"
ber_slen_t
ber_read(
@ -207,11 +208,14 @@ ber_flush( Sockbuf *sb, BerElement *ber, int freeit )
if ( sb->sb_debug ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "liblber", LDAP_LEVEL_DETAIL1,
LDAP_LOG( BER, DETAIL1,
"ber_flush: %ld bytes to sd %ld%s\n",
towrite, (long)sb->sb_fd,
ber->ber_rwptr != ber->ber_buf ? " (re-flush)" : "" ));
BER_DUMP(( "liblber", LDAP_LEVEL_DETAIL2, ber, 1 ));
ber->ber_rwptr != ber->ber_buf ? " (re-flush)" : "" );
if(LDAP_LOGS_TEST(BER, DETAIL2))
BER_DUMP(( "liblber", LDAP_LEVEL_DETAIL2, ber, 1 ));
#else
ber_log_printf( LDAP_DEBUG_ANY, sb->sb_debug,
"ber_flush: %ld bytes to sd %ld%s\n",
@ -441,7 +445,7 @@ ber_get_next(
assert( LBER_VALID( ber ) );
#ifdef NEW_LOGGING
LDAP_LOG(( "liblber", LDAP_LEVEL_ENTRY, "ber_get_next: enter\n" ));
LDAP_LOG( BER, ENTRY, "ber_get_next: enter\n", 0, 0, 0 );
#else
ber_log_printf( LDAP_DEBUG_TRACE, ber->ber_debug,
"ber_get_next\n" );
@ -509,6 +513,8 @@ ber_get_next(
ber->ber_ptr = (char *)p;
}
if (i == 1) continue;
/* Now look for the length */
if (*ber->ber_ptr & 0x80) { /* multi-byte */
int llen = *(unsigned char *)ber->ber_ptr++ & 0x7f;
@ -548,9 +554,9 @@ ber_get_next(
return LBER_DEFAULT;
} else if ( sb->sb_max_incoming && ber->ber_len > sb->sb_max_incoming ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "liblber", LDAP_LEVEL_ERR,
LDAP_LOG( BER, ERR,
"ber_get_next: sockbuf_max_incoming limit hit "
"(%d > %d)\n", ber->ber_len, sb->sb_max_incoming ));
"(%d > %d)\n", ber->ber_len, sb->sb_max_incoming, 0 );
#else
ber_log_printf( LDAP_DEBUG_CONNS, ber->ber_debug,
"ber_get_next: sockbuf_max_incoming limit hit "
@ -616,10 +622,11 @@ done:
*len = ber->ber_len;
if ( ber->ber_debug ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "liblber", LDAP_LEVEL_DETAIL1,
"ber_get_next: tag 0x%lx len %ld\n",
ber->ber_tag, ber->ber_len ));
BER_DUMP(( "liblber", LDAP_LEVEL_DETAIL2, ber, 1 ));
LDAP_LOG( BER, DETAIL1,
"ber_get_next: tag 0x%lx len %ld\n",
ber->ber_tag, ber->ber_len, 0 );
if(LDAP_LOGS_TEST(BER, DETAIL2))
BER_DUMP(( "liblber", LDAP_LEVEL_DETAIL2, ber, 1 ));
#else
ber_log_printf( LDAP_DEBUG_TRACE, ber->ber_debug,
"ber_get_next: tag 0x%lx len %ld contents:\n",

View file

@ -0,0 +1,207 @@
/* $OpenLDAP$ */
/*
* Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/* Portions
* Copyright (c) 1990 Regents of the University of Michigan.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that this notice is preserved and that due credit is given
* to the University of Michigan at Ann Arbor. The name of the University
* may not be used to endorse or promote products derived from this
* software without specific prior written permission. This software
* is provided ``as is'' without express or implied warranty.
*/
#ifndef _LBER_INT_H
#define _LBER_INT_H
#include "lber.h"
#include "ldap_log.h"
#include "lber_pvt.h"
#include "ldap_queue.h"
LDAP_BEGIN_DECL
typedef void (*BER_LOG_FN)(FILE *file,
const char *subsys, int level, const char *fmt, ... );
LBER_V (BER_ERRNO_FN) ber_int_errno_fn;
struct lber_options {
short lbo_valid;
unsigned short lbo_options;
int lbo_debug;
long lbo_meminuse;
};
#ifdef NEW_LOGGING
/*
# ifdef LDAP_DEBUG
# ifdef LDAP_LOG
# undef LDAP_LOG
# endif
# define LDAP_LOG(a) ber_pvt_log_output a
*/
# define BER_DUMP(a) ber_output_dump a
/*
# else
# define LDAP_LOG(a)
# define BER_DUMP(a)
# endif
*/
#endif
LBER_F( int ) ber_pvt_log_output(
const char *subsystem,
int level,
const char *fmt, ... );
#define LBER_UNINITIALIZED 0x0
#define LBER_INITIALIZED 0x1
#define LBER_VALID_BERELEMENT 0x2
#define LBER_VALID_SOCKBUF 0x3
LBER_V (struct lber_options) ber_int_options;
#define ber_int_debug ber_int_options.lbo_debug
struct berelement {
struct lber_options ber_opts;
#define ber_valid ber_opts.lbo_valid
#define ber_options ber_opts.lbo_options
#define ber_debug ber_opts.lbo_debug
/* Do not change the order of these 3 fields! see ber_get_next */
ber_tag_t ber_tag;
ber_len_t ber_len;
ber_tag_t ber_usertag;
char *ber_buf;
char *ber_ptr;
char *ber_end;
struct seqorset *ber_sos;
char *ber_rwptr;
};
#define LBER_VALID(ber) ((ber)->ber_valid==LBER_VALID_BERELEMENT)
#define ber_pvt_ber_remaining(ber) ((ber)->ber_end - (ber)->ber_ptr)
#define ber_pvt_ber_total(ber) ((ber)->ber_end - (ber)->ber_buf)
#define ber_pvt_ber_write(ber) ((ber)->ber_ptr - (ber)->ber_buf)
struct sockbuf {
struct lber_options sb_opts;
Sockbuf_IO_Desc *sb_iod; /* I/O functions */
#define sb_valid sb_opts.lbo_valid
#define sb_options sb_opts.lbo_options
#define sb_debug sb_opts.lbo_debug
ber_socket_t sb_fd;
unsigned int sb_trans_needs_read:1;
unsigned int sb_trans_needs_write:1;
ber_len_t sb_max_incoming;
};
#define SOCKBUF_VALID( sb ) ( (sb)->sb_valid == LBER_VALID_SOCKBUF )
struct seqorset {
BerElement *sos_ber;
ber_len_t sos_clen;
ber_tag_t sos_tag;
char *sos_first;
char *sos_ptr;
struct seqorset *sos_next;
};
/*
* io.c
*/
LBER_F( int )
ber_realloc LDAP_P((
BerElement *ber,
ber_len_t len ));
/*
* bprint.c
*/
#define ber_log_printf ber_pvt_log_printf
#ifdef NEW_LOGGING
LBER_F( int )
ber_output_dump LDAP_P((
const char *subsys,
int level,
BerElement *ber,
int inout ));
#endif
LBER_F( int )
ber_log_bprint LDAP_P((
int errlvl,
int loglvl,
const char *data,
ber_len_t len ));
LBER_F( int )
ber_log_dump LDAP_P((
int errlvl,
int loglvl,
BerElement *ber,
int inout ));
LBER_F( int )
ber_log_sos_dump LDAP_P((
int errlvl,
int loglvl,
Seqorset *sos ));
LBER_V (BER_LOG_FN) ber_int_log_proc;
LBER_V (FILE *) ber_pvt_err_file;
/* memory.c */
/* simple macros to realloc for now */
LBER_V (BerMemoryFunctions *) ber_int_memory_fns;
LBER_F (char *) ber_strndup( LDAP_CONST char *, ber_len_t );
LBER_F (char *) ber_strndup__( LDAP_CONST char *, size_t );
#ifdef CSRIMALLOC
#define LBER_MALLOC malloc
#define LBER_CALLOC calloc
#define LBER_REALLOC realloc
#define LBER_FREE free
#define LBER_VFREE ber_memvfree
#define LBER_STRDUP strdup
#define LBER_STRNDUP ber_strndup__
#else
#define LBER_MALLOC(s) ber_memalloc((s))
#define LBER_CALLOC(n,s) ber_memcalloc((n),(s))
#define LBER_REALLOC(p,s) ber_memrealloc((p),(s))
#define LBER_FREE(p) ber_memfree((p))
#define LBER_VFREE(v) ber_memvfree((void**)(v))
#define LBER_STRDUP(s) ber_strdup((s))
#define LBER_STRNDUP(s,l) ber_strndup((s),(l))
#endif
/* sockbuf.c */
LBER_F( int )
ber_int_sb_init LDAP_P(( Sockbuf *sb ));
LBER_F( int )
ber_int_sb_close LDAP_P(( Sockbuf *sb ));
LBER_F( int )
ber_int_sb_destroy LDAP_P(( Sockbuf *sb ));
LBER_F( ber_slen_t )
ber_int_sb_read LDAP_P(( Sockbuf *sb, void *buf, ber_len_t len ));
LBER_F( ber_slen_t )
ber_int_sb_write LDAP_P(( Sockbuf *sb, void *buf, ber_len_t len ));
LDAP_END_DECL
#endif /* _LBER_INT_H */

View file

@ -0,0 +1,229 @@
# Microsoft Developer Studio Project File - Name="liblber" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 5.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
CFG=liblber - Win32 DLL Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "liblber.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "liblber.mak" CFG="liblber - Win32 DLL Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "liblber - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "liblber - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE "liblber - Win32 Single Debug" (based on "Win32 (x86) Static Library")
!MESSAGE "liblber - Win32 Single Release" (based on\
"Win32 (x86) Static Library")
!MESSAGE "liblber - Win32 DLL Debug" (based on "Win32 (x86) Static Library")
!MESSAGE "liblber - Win32 DLL Release" (based on "Win32 (x86) Static Library")
!MESSAGE
# Begin Project
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
!IF "$(CFG)" == "liblber - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "..\..\Release"
# PROP Intermediate_Dir "..\..\Release\liblber"
# PROP Target_Dir ""
RSC=rc.exe
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "_WINDOWS" /YX /FD /c
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo /out:"..\..\Release\olber32.lib"
!ELSEIF "$(CFG)" == "liblber - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "..\..\Debug"
# PROP Intermediate_Dir "..\..\Debug\liblber"
# PROP Target_Dir ""
RSC=rc.exe
# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /MTd /W3 /GX /Z7 /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /YX /FD /c
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo /out:"..\..\Debug\olber32.lib"
!ELSEIF "$(CFG)" == "liblber - Win32 Single Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "liblber_"
# PROP BASE Intermediate_Dir "liblber_"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "..\..\Sdebug"
# PROP Intermediate_Dir "..\..\SDebug\liblber"
# PROP Target_Dir ""
RSC=rc.exe
# ADD BASE CPP /nologo /MTd /W3 /GX /Z7 /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /YX /FD /c
# ADD CPP /nologo /W3 /GX /Z7 /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /YX /FD /c
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo /out:"..\Debug\olber32.lib"
# ADD LIB32 /nologo /out:"..\..\SDebug\olber32.lib"
!ELSEIF "$(CFG)" == "liblber - Win32 Single Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "liblber0"
# PROP BASE Intermediate_Dir "liblber0"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "..\..\SRelease"
# PROP Intermediate_Dir "..\..\SRelease\liblber"
# PROP Target_Dir ""
RSC=rc.exe
# ADD BASE CPP /nologo /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "_WINDOWS" /YX /FD /c
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo /out:"..\Release\olber32.lib"
# ADD LIB32 /nologo /out:"..\..\SRelease\olber32.lib"
!ELSEIF "$(CFG)" == "liblber - Win32 DLL Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "liblber_"
# PROP BASE Intermediate_Dir "liblber_"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "..\..\DLLDebug"
# PROP Intermediate_Dir "..\..\DLLDebug\liblber"
# PROP Target_Dir ""
RSC=rc.exe
# ADD BASE CPP /nologo /MTd /W3 /GX /Z7 /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /YX /FD /c
# ADD CPP /nologo /MDd /W3 /GX /Z7 /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /YX /FD /c
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo /out:"..\..\Debug\olber32.lib"
# ADD LIB32 /nologo /out:"..\..\DLLDebug\olber32.lib"
!ELSEIF "$(CFG)" == "liblber - Win32 DLL Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "liblber0"
# PROP BASE Intermediate_Dir "liblber0"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "liblber0"
# PROP Intermediate_Dir "liblber0"
# PROP Target_Dir ""
RSC=rc.exe
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "_WINDOWS" /YX /FD /c
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo /out:"..\..\Release\olber32.lib"
# ADD LIB32 /nologo /out:"..\..\Release\olber32.lib"
!ENDIF
# Begin Target
# Name "liblber - Win32 Release"
# Name "liblber - Win32 Debug"
# Name "liblber - Win32 Single Debug"
# Name "liblber - Win32 Single Release"
# Name "liblber - Win32 DLL Debug"
# Name "liblber - Win32 DLL Release"
# Begin Source File
SOURCE=.\bprint.c
# End Source File
# Begin Source File
SOURCE=.\debug.c
# End Source File
# Begin Source File
SOURCE=.\decode.c
# End Source File
# Begin Source File
SOURCE=.\encode.c
# End Source File
# Begin Source File
SOURCE=.\io.c
# End Source File
# Begin Source File
SOURCE=".\lber-int.h"
# End Source File
# Begin Source File
SOURCE=..\..\include\lber.h
# End Source File
# Begin Source File
SOURCE=..\..\include\lber_pvt.h
# End Source File
# Begin Source File
SOURCE=..\..\include\lber_types.h
# End Source File
# Begin Source File
SOURCE=.\memory.c
# End Source File
# Begin Source File
SOURCE=.\nt_err.c
# End Source File
# Begin Source File
SOURCE=.\options.c
# End Source File
# Begin Source File
SOURCE=.\sockbuf.c
# End Source File
# End Target
# End Project

View file

@ -0,0 +1,317 @@
/* $OpenLDAP$ */
/*
* Copyright 1998-2002 The OpenLDAP Foundation, Redwood City, California, USA
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted only
* as authorized by the OpenLDAP Public License. A copy of this
* license is available at http://www.OpenLDAP.org/license.html or
* in file LICENSE in the top-level directory of the distribution.
*/
/* thr_posix.c - wrapper around posix and posixish thread implementations.
*/
#include "portable.h"
#if defined( HAVE_PTHREADS )
#include <ac/errno.h>
#include "ldap_pvt_thread.h"
#if HAVE_PTHREADS_D4
# define LDAP_INT_THREAD_ATTR_DEFAULT pthread_attr_default
# define LDAP_INT_THREAD_CONDATTR_DEFAULT pthread_condattr_default
# define LDAP_INT_THREAD_MUTEXATTR_DEFAULT pthread_mutexattr_default
#else
# define LDAP_INT_THREAD_ATTR_DEFAULT NULL
# define LDAP_INT_THREAD_CONDATTR_DEFAULT NULL
# define LDAP_INT_THREAD_MUTEXATTR_DEFAULT NULL
#endif
int
ldap_int_thread_initialize( void )
{
return 0;
}
int
ldap_int_thread_destroy( void )
{
#ifdef HAVE_PTHREAD_KILL_OTHER_THREADS_NP
/* LinuxThreads: kill clones */
pthread_kill_other_threads_np();
#endif
return 0;
}
#ifdef LDAP_THREAD_HAVE_SETCONCURRENCY
int
ldap_pvt_thread_set_concurrency(int n)
{
#ifdef HAVE_PTHREAD_SETCONCURRENCY
return pthread_setconcurrency( n );
#elif HAVE_THR_SETCONCURRENCY
return thr_setconcurrency( n );
#else
return 0;
#endif
}
#endif
#ifdef LDAP_THREAD_HAVE_GETCONCURRENCY
int
ldap_pvt_thread_get_concurrency(void)
{
#ifdef HAVE_PTHREAD_GETCONCURRENCY
return pthread_getconcurrency();
#elif HAVE_THR_GETCONCURRENCY
return thr_getconcurrency();
#else
return 0;
#endif
}
#endif
int
ldap_pvt_thread_create( ldap_pvt_thread_t * thread,
int detach,
void *(*start_routine)( void * ),
void *arg)
{
int rtn;
#if defined( HAVE_PTHREADS_FINAL )
pthread_attr_t attr;
pthread_attr_init(&attr);
#if defined( PTHREAD_CREATE_JOINABLE ) || defined( PTHREAD_UNDETACHED )
if (!detach) {
#if defined( PTHREAD_CREATE_JOINABLE )
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
#else
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_UNDETACHED);
#endif
#ifdef PTHREAD_CREATE_DETACHED
} else {
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
#elif HAVE_PTHREADS_OS390
} else {
int st = __DETACHED;
pthread_attr_setdetachstate(&attr, &st);
#endif
}
#endif
#if defined(LDAP_PVT_THREAD_STACK_SIZE) && LDAP_PVT_THREAD_STACK_SIZE > 0
/* this should be tunable */
pthread_attr_setstacksize( &attr, LDAP_PVT_THREAD_STACK_SIZE );
#endif
rtn = pthread_create( thread, &attr, start_routine, arg );
#ifdef HAVE_PTHREADS_OS390
if ( rtn == -1 ) rtn = errno;
#endif
#if !defined( PTHREAD_CREATE_JOINABLE ) && !defined( PTHREAD_UNDETACHED )
if( detach ) {
#ifdef HAVE_PTHREADS_OS390
(void) pthread_detach( thread );
#else
(void) pthread_detach( *thread );
#endif
}
#endif
pthread_attr_destroy(&attr);
#else
rtn = pthread_create( thread, LDAP_INT_THREAD_ATTR_DEFAULT,
start_routine, arg );
if( detach ) {
pthread_detach( thread );
}
#endif
return rtn;
}
void
ldap_pvt_thread_exit( void *retval )
{
pthread_exit( retval );
}
int
ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return )
{
#if !defined( HAVE_PTHREADS_FINAL )
void *dummy;
if (thread_return==NULL)
thread_return=&dummy;
#endif
#ifdef HAVE_PTHREADS_OS390
int st = pthread_join( thread, thread_return );
if ( st == -1 ) st = errno;
return st;
#else
return pthread_join( thread, thread_return );
#endif
}
int
ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo )
{
#ifdef HAVE_PTHREAD_KILL
#ifdef HAVE_PTHREADS_OS390
int st = pthread_kill( thread, signo );
if ( st == -1 ) st = errno;
return st;
#else
return pthread_kill( thread, signo );
#endif
#else
/* pthread package with DCE */
if (kill( getpid(), signo )<0)
return errno;
return 0;
#endif
}
int
ldap_pvt_thread_yield( void )
{
#ifdef _POSIX_THREAD_IS_GNU_PTH
sched_yield();
return 0;
#elif HAVE_SCHED_YIELD
return sched_yield();
#elif HAVE_PTHREAD_YIELD
#if HAVE_PTHREADS_OS390
pthread_yield(NULL);
#else
pthread_yield();
#endif
return 0;
#elif HAVE_THR_YIELD
return thr_yield();
#else
return 0;
#endif
}
int
ldap_pvt_thread_cond_init( ldap_pvt_thread_cond_t *cond )
{
return pthread_cond_init( cond, LDAP_INT_THREAD_CONDATTR_DEFAULT );
}
int
ldap_pvt_thread_cond_destroy( ldap_pvt_thread_cond_t *cond )
{
return pthread_cond_destroy( cond );
}
int
ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t *cond )
{
return pthread_cond_signal( cond );
}
int
ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t *cond )
{
return pthread_cond_broadcast( cond );
}
int
ldap_pvt_thread_cond_wait( ldap_pvt_thread_cond_t *cond,
ldap_pvt_thread_mutex_t *mutex )
{
return pthread_cond_wait( cond, mutex );
}
int
ldap_pvt_thread_mutex_init( ldap_pvt_thread_mutex_t *mutex )
{
return pthread_mutex_init( mutex, LDAP_INT_THREAD_MUTEXATTR_DEFAULT );
}
int
ldap_pvt_thread_mutex_destroy( ldap_pvt_thread_mutex_t *mutex )
{
return pthread_mutex_destroy( mutex );
}
int
ldap_pvt_thread_mutex_lock( ldap_pvt_thread_mutex_t *mutex )
{
return pthread_mutex_lock( mutex );
}
int
ldap_pvt_thread_mutex_trylock( ldap_pvt_thread_mutex_t *mutex )
{
return pthread_mutex_trylock( mutex );
}
int
ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t *mutex )
{
return pthread_mutex_unlock( mutex );
}
#ifdef LDAP_THREAD_HAVE_RDWR
#ifdef HAVE_PTHREAD_RWLOCK_DESTROY
int
ldap_pvt_thread_rdwr_init( ldap_pvt_thread_rdwr_t *rw )
{
return pthread_rwlock_init( rw, NULL );
}
int
ldap_pvt_thread_rdwr_destroy( ldap_pvt_thread_rdwr_t *rw )
{
return pthread_rwlock_destroy( rw );
}
int ldap_pvt_thread_rdwr_rlock( ldap_pvt_thread_rdwr_t *rw )
{
return pthread_rwlock_rdlock( rw );
}
int ldap_pvt_thread_rdwr_rtrylock( ldap_pvt_thread_rdwr_t *rw )
{
return pthread_rwlock_tryrdlock( rw );
}
int ldap_pvt_thread_rdwr_runlock( ldap_pvt_thread_rdwr_t *rw )
{
return pthread_rwlock_unlock( rw );
}
int ldap_pvt_thread_rdwr_wlock( ldap_pvt_thread_rdwr_t *rw )
{
return pthread_rwlock_wrlock( rw );
}
int ldap_pvt_thread_rdwr_wtrylock( ldap_pvt_thread_rdwr_t *rw )
{
return pthread_rwlock_trywrlock( rw );
}
int ldap_pvt_thread_rdwr_wunlock( ldap_pvt_thread_rdwr_t *rw )
{
return pthread_rwlock_unlock( rw );
}
#endif /* HAVE_PTHREAD_RDLOCK_DESTROY */
#endif /* LDAP_THREAD_HAVE_RDWR */
#endif /* HAVE_PTHREADS */

File diff suppressed because it is too large Load diff

View file

@ -14,6 +14,7 @@ SRCS = ucstr.c
OBJS = ucdata.o ure.o urestubs.o ucstr.o
XLIB = $(LIBRARY)
XLIBS = $(LDAP_LIBLUTIL_A)
PROGRAMS = ucgendat
LDAP_INCDIR= ../../include

View file

@ -30,6 +30,7 @@
#include "ldap_config.h"
#include <stdio.h>
#include <ac/bytes.h>
#include <ac/stdlib.h>
#include <ac/string.h>
#include <ac/unistd.h>
@ -44,11 +45,11 @@
**************************************************************************/
typedef struct {
unsigned short bom;
unsigned short cnt;
ac_uint2 bom;
ac_uint2 cnt;
union {
unsigned long bytes;
unsigned short len[2];
ac_uint4 bytes;
ac_uint2 len[2];
} size;
} _ucheader_t;

View file

@ -30,6 +30,7 @@
#include "ldap_config.h"
#include <stdio.h>
#include <ac/bytes.h>
#include <ac/stdlib.h>
#include <ac/string.h>
#include <ac/unistd.h>
@ -804,8 +805,8 @@ read_cdata(FILE *in)
char line[512], *s, *e;
lineno = skip = 0;
while (!feof(in)) {
if( fscanf(in, "%[^\n]\n", line) != 1) break;
while (fgets(line, sizeof(line), in)) {
if( (s=strchr(line, '\n')) ) *s = '\0';
lineno++;
/*
@ -1163,8 +1164,8 @@ read_compexdata(FILE *in)
(void) memset((char *) compexs, 0, sizeof(unsigned long) << 11);
while (!feof(in)) {
if( fscanf(in, "%[^\n]\n", line) != 1) break;
while (fgets(line, sizeof(line), in)) {
if( (s=strchr(line, '\n')) ) *s = '\0';
/*
* Skip blank lines and lines that start with a '#'.
*/
@ -1216,7 +1217,8 @@ static void
write_cdata(char *opath)
{
FILE *out;
unsigned long i, idx, bytes, nprops;
ac_uint4 bytes;
unsigned long i, idx, nprops;
unsigned short casecnt[2];
char path[BUFSIZ];
@ -1229,7 +1231,7 @@ write_cdata(char *opath)
/*
* Open the ctype.dat file.
*/
sprintf(path, "%s%sctype.dat", opath, LDAP_DIRSEP);
snprintf(path, sizeof path, "%s" LDAP_DIRSEP "ctype.dat", opath);
if ((out = fopen(path, "wb")) == 0)
return;
@ -1268,7 +1270,7 @@ write_cdata(char *opath)
/*
* Write the header.
*/
fwrite((char *) hdr, sizeof(unsigned short), 2, out);
fwrite((char *) hdr, sizeof(ac_uint2), 2, out);
/*
* Write the byte count.
@ -1300,7 +1302,7 @@ write_cdata(char *opath)
/*
* Open the case.dat file.
*/
sprintf(path, "%s%scase.dat", opath, LDAP_DIRSEP);
snprintf(path, sizeof path, "%s" LDAP_DIRSEP "case.dat", opath);
if ((out = fopen(path, "wb")) == 0)
return;
@ -1355,7 +1357,7 @@ write_cdata(char *opath)
/*
* Open the comp.dat file.
*/
sprintf(path, "%s%scomp.dat", opath, LDAP_DIRSEP);
snprintf(path, sizeof path, "%s" LDAP_DIRSEP "comp.dat", opath);
if ((out = fopen(path, "wb")) == 0)
return;
@ -1393,7 +1395,7 @@ write_cdata(char *opath)
/*
* Open the decomp.dat file.
*/
sprintf(path, "%s%sdecomp.dat", opath, LDAP_DIRSEP);
snprintf(path, sizeof path, "%s" LDAP_DIRSEP "decomp.dat", opath);
if ((out = fopen(path, "wb")) == 0)
return;
@ -1447,7 +1449,7 @@ write_cdata(char *opath)
/*
* Open the kdecomp.dat file.
*/
sprintf(path, "%s%skdecomp.dat", opath, LDAP_DIRSEP);
snprintf(path, sizeof path, "%s" LDAP_DIRSEP "kdecomp.dat", opath);
if ((out = fopen(path, "wb")) == 0)
return;
@ -1507,7 +1509,7 @@ write_cdata(char *opath)
/*
* Open the cmbcl.dat file.
*/
sprintf(path, "%s%scmbcl.dat", opath, LDAP_DIRSEP);
snprintf(path, sizeof path, "%s" LDAP_DIRSEP "cmbcl.dat", opath);
if ((out = fopen(path, "wb")) == 0)
return;
@ -1545,7 +1547,7 @@ write_cdata(char *opath)
/*
* Open the num.dat file.
*/
sprintf(path, "%s%snum.dat", opath, LDAP_DIRSEP);
snprintf(path, sizeof path, "%s" LDAP_DIRSEP "num.dat", opath);
if ((out = fopen(path, "wb")) == 0)
return;
@ -1598,10 +1600,7 @@ main(int argc, char *argv[])
FILE *in;
char *prog, *opath;
if ((prog = strrchr(argv[0], *LDAP_DIRSEP)) != 0)
prog++;
else
prog = argv[0];
prog = lutil_progname( "ucgendat", argc, argv );
opath = 0;
in = stdin;

View file

@ -0,0 +1,36 @@
# $OpenLDAP$
## Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
## COPYING RESTRICTIONS APPLY, see COPYRIGHT file
##
## Makefile for -llutil
##
LIBRARY = liblutil.a
NT_SRCS = ntservice.c
NT_OBJS = ntservice.o slapdmsg.res
UNIX_SRCS = detach.c
UNIX_OBJS = detach.o
SRCS = base64.c csn.c entropy.c sasl.c signal.c hash.c \
md5.c passwd.c sha1.c getpass.c lockf.c utils.c uuid.c sockpair.c \
@LIBSRCS@ $(@PLAT@_SRCS)
OBJS = base64.o csn.o entropy.o sasl.o signal.o hash.o \
md5.o passwd.o sha1.o getpass.o lockf.o utils.o uuid.o sockpair.o \
@LIBOBJS@ $(@PLAT@_OBJS)
LDAP_INCDIR= ../../include
LDAP_LIBDIR= ../../libraries
# These rules are for a Mingw32 build, specifically.
# It's ok for them to be here because the clean rule is harmless, and
# slapdmsg.res won't get built unless it's declared in OBJS.
slapdmsg.res: slapdmsg.rc slapdmsg.bin
windres $< -O coff -o $@
clean-local:
$(RM) *.res

126
libraries/liblutil/getopt.c Normal file
View file

@ -0,0 +1,126 @@
/* $OpenLDAP$ */
/*
* Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/*
getopt.c
modified public-domain AT&T getopt(3)
modified by Kurt Zeilenga for inclusion into OpenLDAP
*/
#include "portable.h"
#ifndef HAVE_GETOPT
#include <stdio.h>
#include <ac/string.h>
#include <ac/unistd.h>
#ifdef HAVE_IO_H
#include <io.h>
#endif
#include "lutil.h"
#ifndef STDERR_FILENO
#define STDERR_FILENO 2
#endif
int opterr = 1;
int optind = 1;
int optopt;
char * optarg;
#ifdef HAVE_EBCDIC
extern int _trans_argv;
#endif
static void ERR (char * const argv[], const char * s, char c)
{
#ifdef DF_TRACE_DEBUG
printf("DF_TRACE_DEBUG: static void ERR () in getopt.c\n");
#endif
if (opterr)
{
char *ptr, outbuf[4096];
ptr = lutil_strncopy(outbuf, argv[0], sizeof(outbuf) - 2);
ptr = lutil_strncopy(ptr, s, sizeof(outbuf)-2 -(ptr-outbuf));
*ptr++ = c;
*ptr++ = '\n';
#ifdef HAVE_EBCDIC
__atoe_l(outbuf, ptr - outbuf);
#endif
(void) write(STDERR_FILENO,outbuf,ptr - outbuf);
}
}
int getopt (int argc, char * const argv [], const char * opts)
{
static int sp = 1, error = (int) '?';
static char sw = '-', eos = '\0', arg = ':';
register char c, * cp;
#ifdef DF_TRACE_DEBUG
printf("DF_TRACE_DEBUG: int getopt () in getopt.c\n");
#endif
#ifdef HAVE_EBCDIC
if (_trans_argv) {
int i;
for (i=0; i<argc; i++) __etoa(argv[i]);
_trans_argv = 0;
}
#endif
if (sp == 1)
{
if (optind >= argc || argv[optind][0] != sw
|| argv[optind][1] == eos)
return EOF;
else if (strcmp(argv[optind],"--") == 0)
{
optind++;
return EOF;
}
}
c = argv[optind][sp];
optopt = (int) c;
if (c == arg || (cp = strchr(opts,c)) == NULL)
{
ERR(argv,": illegal option--",c);
if (argv[optind][++sp] == eos)
{
optind++;
sp = 1;
}
return error;
}
else if (*++cp == arg)
{
if (argv[optind][sp + 1] != eos)
optarg = &argv[optind++][sp + 1];
else if (++optind >= argc)
{
ERR(argv,": option requires an argument--",c);
sp = 1;
return error;
}
else
optarg = argv[optind++];
sp = 1;
}
else
{
if (argv[optind][++sp] == eos)
{
sp = 1;
optind++;
}
optarg = NULL;
}
return (int) c;
}
#endif /* HAVE_GETOPT */

View file

@ -0,0 +1,297 @@
# Microsoft Developer Studio Project File - Name="liblutil" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 5.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
CFG=liblutil - Win32 Single Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "liblutil.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "liblutil.mak" CFG="liblutil - Win32 Single Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "liblutil - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "liblutil - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE "liblutil - Win32 Single Debug" (based on\
"Win32 (x86) Static Library")
!MESSAGE "liblutil - Win32 Single Release" (based on\
"Win32 (x86) Static Library")
!MESSAGE
# Begin Project
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
!IF "$(CFG)" == "liblutil - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "..\..\Release"
# PROP Intermediate_Dir "..\..\Release\liblutil"
# PROP Target_Dir ""
RSC=rc.exe
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo /out:"..\..\Release\olutil32.lib"
!ELSEIF "$(CFG)" == "liblutil - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "..\..\Debug"
# PROP Intermediate_Dir "..\..\Debug\liblutil"
# PROP Target_Dir ""
RSC=rc.exe
# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /MTd /W3 /GX /Z7 /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /YX /FD /c
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo /out:"..\..\Debug\olutil32.lib"
!ELSEIF "$(CFG)" == "liblutil - Win32 Single Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "liblutil"
# PROP BASE Intermediate_Dir "liblutil"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "..\..\SDebug"
# PROP Intermediate_Dir "..\..\SDebug\liblutil"
# PROP Target_Dir ""
RSC=rc.exe
# ADD BASE CPP /nologo /MTd /W3 /GX /Z7 /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /Z7 /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /YX /FD /c
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo /out:"..\Debug\olutil32.lib"
# ADD LIB32 /nologo /out:"..\..\SDebug\olutil32.lib"
!ELSEIF "$(CFG)" == "liblutil - Win32 Single Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "libluti0"
# PROP BASE Intermediate_Dir "libluti0"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "..\..\SRelease"
# PROP Intermediate_Dir "..\..\SRelease\liblutil"
# PROP Target_Dir ""
RSC=rc.exe
# ADD BASE CPP /nologo /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo /out:"..\Release\olutil32.lib"
# ADD LIB32 /nologo /out:"..\..\SRelease\olutil32.lib"
!ENDIF
# Begin Target
# Name "liblutil - Win32 Release"
# Name "liblutil - Win32 Debug"
# Name "liblutil - Win32 Single Debug"
# Name "liblutil - Win32 Single Release"
# Begin Source File
SOURCE=.\authpasswd.c
# End Source File
# Begin Source File
SOURCE=.\base64.c
# End Source File
# Begin Source File
SOURCE=..\..\include\ac\bytes.h
# End Source File
# Begin Source File
SOURCE=.\csn.c
# End Source File
# Begin Source File
SOURCE=.\entropy.c
# End Source File
# Begin Source File
SOURCE="..\..\include\getopt-compat.h"
# End Source File
# Begin Source File
SOURCE=.\getopt.c
# End Source File
# Begin Source File
SOURCE=.\getpass.c
# End Source File
# Begin Source File
SOURCE=.\hash.c
# End Source File
# Begin Source File
SOURCE=..\..\include\ldap_cdefs.h
# End Source File
# Begin Source File
SOURCE=.\lockf.c
# End Source File
# Begin Source File
SOURCE=..\..\include\lutil.h
# End Source File
# Begin Source File
SOURCE=..\..\include\lutil_hash.h
# End Source File
# Begin Source File
SOURCE=..\..\include\lutil_ldap.h
# End Source File
# Begin Source File
SOURCE=..\..\include\lutil_lockf.h
# End Source File
# Begin Source File
SOURCE=..\..\include\lutil_md5.h
# End Source File
# Begin Source File
SOURCE=..\..\include\lutil_sha1.h
# End Source File
# Begin Source File
SOURCE=.\md5.c
# End Source File
# Begin Source File
SOURCE=.\ntservice.c
# End Source File
# Begin Source File
SOURCE=.\passwd.c
# End Source File
# Begin Source File
SOURCE=..\..\include\portable.h
# End Source File
# Begin Source File
SOURCE="..\..\include\queue-compat.h"
# End Source File
# Begin Source File
SOURCE=.\sasl.c
# End Source File
# Begin Source File
SOURCE=.\sha1.c
# End Source File
# Begin Source File
SOURCE=.\slapdmsg.mc
!IF "$(CFG)" == "liblutil - Win32 Release"
# Begin Custom Build - Building slapd message file
IntDir=.\..\..\Release\liblutil
InputPath=.\slapdmsg.mc
"slapdmsg.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
mkdir $(IntDir)
mc -v slapdmsg.mc -r $(IntDir)
rc /v /r $(IntDir)\slapdmsg.rc
# End Custom Build
!ELSEIF "$(CFG)" == "liblutil - Win32 Debug"
# Begin Custom Build - Building slapd message file
IntDir=.\..\..\Debug\liblutil
InputPath=.\slapdmsg.mc
"slapdmsg.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
mkdir $(IntDir)
mc -v slapdmsg.mc -r $(IntDir)
rc /v /r $(IntDir)\slapdmsg.rc
# End Custom Build
!ELSEIF "$(CFG)" == "liblutil - Win32 Single Debug"
# Begin Custom Build - Building slapd message file
IntDir=.\..\..\SDebug\liblutil
InputPath=.\slapdmsg.mc
"slapdmsg.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
mkdir $(IntDir)
mc -v slapdmsg.mc -r $(IntDir)
rc /v /r $(IntDir)\slapdmsg.rc
# End Custom Build
!ELSEIF "$(CFG)" == "liblutil - Win32 Single Release"
# Begin Custom Build - Building slapd message file
IntDir=.\..\..\SRelease\liblutil
InputPath=.\slapdmsg.mc
"slapdmsg.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
mkdir $(IntDir)
mc -v slapdmsg.mc -r $(IntDir)
rc /v /r $(IntDir)\slapdmsg.rc
# End Custom Build
!ENDIF
# End Source File
# Begin Source File
SOURCE=.\sockpair.c
# End Source File
# Begin Source File
SOURCE=.\utils.c
# End Source File
# Begin Source File
SOURCE=.\uuid.c
# End Source File
# End Target
# End Project

View file

@ -0,0 +1,513 @@
/* $OpenLDAP$ */
/*
* Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/*
* NT Service manager utilities for OpenLDAP services
* these should NOT be slapd specific, but are
*/
#include "portable.h"
#ifdef HAVE_NT_SERVICE_MANAGER
#include <ac/stdlib.h>
#include <ac/string.h>
#include <stdio.h>
#include <windows.h>
#include <winsvc.h>
#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"
#include "ldap_defaults.h"
#include "slapdmsg.h"
#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 */
SERVICE_STATUS SLAPDServiceStatus;
SERVICE_STATUS_HANDLE hSLAPDServiceStatus;
ldap_pvt_thread_cond_t started_event, stopped_event;
ldap_pvt_thread_t start_status_tid, stop_status_tid;
void (*stopfunc)(int);
static char *GetLastErrorString( void );
int srv_install(LPCTSTR lpszServiceName, LPCTSTR lpszDisplayName,
LPCTSTR lpszBinaryPathName, BOOL auto_start)
{
HKEY hKey;
DWORD dwValue, dwDisposition;
SC_HANDLE schSCManager, schService;
fprintf( stderr, "The install path is %s.\n", lpszBinaryPathName );
if ((schSCManager = OpenSCManager( NULL, NULL, SC_MANAGER_CONNECT|SC_MANAGER_CREATE_SERVICE ) ) != NULL )
{
if ((schService = CreateService(
schSCManager,
lpszServiceName,
lpszDisplayName,
SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS,
auto_start ? SERVICE_AUTO_START : SERVICE_DEMAND_START,
SERVICE_ERROR_NORMAL,
lpszBinaryPathName,
NULL, NULL, NULL, NULL, NULL)) != NULL)
{
char regpath[132];
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
snprintf( regpath, sizeof regpath,
"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s",
lpszServiceName );
/* Create the registry key for event logging to the Windows NT event log. */
if ( RegCreateKeyEx(HKEY_LOCAL_MACHINE,
regpath, 0,
"REG_SZ", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey,
&dwDisposition) != ERROR_SUCCESS)
{
fprintf( stderr, "RegCreateKeyEx() failed. GetLastError=%lu (%s)\n", GetLastError(), GetLastErrorString() );
RegCloseKey(hKey);
return(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() );
RegCloseKey(hKey);
return(0);
}
dwValue = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
if ( RegSetValueEx(hKey, "TypesSupported", 0, REG_DWORD, (LPBYTE) &dwValue, sizeof(DWORD)) != ERROR_SUCCESS)
{
fprintf( stderr, "RegCreateKeyEx(TypesSupported) failed. GetLastError=%lu (%s)\n", GetLastError(), GetLastErrorString() );
RegCloseKey(hKey);
return(0);
}
RegCloseKey(hKey);
return(1);
}
else
{
fprintf( stderr, "CreateService() failed. GetLastError=%lu (%s)\n", GetLastError(), GetLastErrorString() );
CloseServiceHandle(schSCManager);
return(0);
}
}
else
fprintf( stderr, "OpenSCManager() failed. GetLastError=%lu (%s)\n", GetLastError(), GetLastErrorString() );
return(0);
}
int srv_remove(LPCTSTR lpszServiceName, LPCTSTR lpszBinaryPathName)
{
SC_HANDLE schSCManager, schService;
fprintf( stderr, "The installed path is %s.\n", lpszBinaryPathName );
if ((schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT|SC_MANAGER_CREATE_SERVICE)) != NULL )
{
if ((schService = OpenService(schSCManager, lpszServiceName, DELETE)) != NULL)
{
if ( DeleteService(schService) == TRUE)
{
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
return(1);
} else {
fprintf( stderr, "DeleteService() failed. GetLastError=%lu (%s)\n", GetLastError(), GetLastErrorString() );
fprintf( stderr, "The %s service has not been removed.\n", lpszBinaryPathName);
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
return(0);
}
} else {
fprintf( stderr, "OpenService() failed. GetLastError=%lu (%s)\n", GetLastError(), GetLastErrorString() );
CloseServiceHandle(schSCManager);
return(0);
}
}
else
fprintf( stderr, "OpenSCManager() failed. GetLastError=%lu (%s)\n", GetLastError(), GetLastErrorString() );
return(0);
}
DWORD
svc_installed (LPTSTR lpszServiceName, LPTSTR lpszBinaryPathName)
{
char buf[256];
HKEY key;
DWORD rc;
DWORD type;
long len;
strcpy(buf, TEXT("SYSTEM\\CurrentControlSet\\Services\\"));
strcat(buf, lpszServiceName);
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, buf, 0, KEY_QUERY_VALUE, &key) != ERROR_SUCCESS)
return(-1);
rc = 0;
if (lpszBinaryPathName) {
len = sizeof(buf);
if (RegQueryValueEx(key, "ImagePath", NULL, &type, buf, &len) == ERROR_SUCCESS) {
if (strcmp(lpszBinaryPathName, buf))
rc = -1;
}
}
RegCloseKey(key);
return(rc);
}
DWORD
svc_running (LPTSTR lpszServiceName)
{
SC_HANDLE service;
SC_HANDLE scm;
DWORD rc;
SERVICE_STATUS ss;
if (!(scm = OpenSCManager(NULL, NULL, GENERIC_READ)))
return(GetLastError());
rc = 1;
service = OpenService(scm, lpszServiceName, SERVICE_QUERY_STATUS);
if (service) {
if (!QueryServiceStatus(service, &ss))
rc = GetLastError();
else if (ss.dwCurrentState != SERVICE_STOPPED)
rc = 0;
CloseServiceHandle(service);
}
CloseServiceHandle(scm);
return(rc);
}
static void *start_status_routine( void *ptr )
{
DWORD wait_result;
int done = 0;
while ( !done )
{
wait_result = WaitForSingleObject( started_event, SCM_NOTIFICATION_INTERVAL );
switch ( wait_result )
{
case WAIT_ABANDONED:
case WAIT_OBJECT_0:
/* 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);
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);
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);
done = 1;
break;
}
}
ldap_pvt_thread_exit(NULL);
return NULL;
}
static void *stop_status_routine( void *ptr )
{
DWORD wait_result;
int done = 0;
while ( !done )
{
wait_result = WaitForSingleObject( stopped_event, SCM_NOTIFICATION_INTERVAL );
switch ( wait_result )
{
case WAIT_ABANDONED:
case WAIT_OBJECT_0:
/* the object that we were waiting for has been destroyed (ABANDONED) or
* signalled (TIMEOUT_0). The shutting down process is therefore complete
* and the final SERVICE_STOPPED message will be sent to the service control
* manager prior to the process terminating. */
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);
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);
done = 1;
break;
}
}
ldap_pvt_thread_exit(NULL);
return NULL;
}
void WINAPI SLAPDServiceCtrlHandler( 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);
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);
}
else
{
/* start a thread to report the progress to the service control manager
* until the stopped_event is fired. */
if ( ldap_pvt_thread_create( &stop_status_tid, 0, stop_status_routine, NULL ) == 0 )
{
}
else {
/* failed to create the thread that tells the Service Control Manager that the
* 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);
}
}
stopfunc( -1 );
break;
case SERVICE_CONTROL_INTERROGATE:
SetServiceStatus(hSLAPDServiceStatus, &SLAPDServiceStatus);
break;
}
return;
}
void *getRegParam( char *svc, char *value )
{
HKEY hkey;
char path[255];
DWORD vType;
static char vValue[1024];
DWORD valLen = sizeof( vValue );
if ( svc != NULL )
snprintf ( path, sizeof path, "SOFTWARE\\%s", svc );
else
snprintf ( path, sizeof path, "SOFTWARE\\OpenLDAP\\Parameters" );
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;
}
RegCloseKey( hkey );
switch ( vType )
{
case REG_BINARY:
case REG_DWORD:
return (void*)&vValue;
case REG_SZ:
return (void*)&vValue;
}
return (void*)NULL;
}
void LogSlapdStartedEvent( char *svc, int slap_debug, char *configfile, char *urls )
{
char *Inserts[5];
WORD i = 0, j;
HANDLE hEventLog;
hEventLog = RegisterEventSource( NULL, svc );
Inserts[i] = (char *)malloc( 20 );
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 );
for ( j = 0; j < i; j++ )
ldap_memfree( Inserts[j] );
DeregisterEventSource( hEventLog );
}
void LogSlapdStoppedEvent( char *svc )
{
HANDLE hEventLog;
hEventLog = RegisterEventSource( NULL, svc );
ReportEvent( hEventLog, EVENTLOG_INFORMATION_TYPE, 0,
MSG_SLAPD_STOPPED, NULL, 0, 0, NULL, NULL );
DeregisterEventSource( hEventLog );
}
void CommenceStartupProcessing( LPCTSTR lpszServiceName,
void (*stopper)(int) )
{
hSLAPDServiceStatus = RegisterServiceCtrlHandler( lpszServiceName, (LPHANDLER_FUNCTION)SLAPDServiceCtrlHandler);
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;
SetServiceStatus(hSLAPDServiceStatus, &SLAPDServiceStatus);
/* 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
* SERVICE_RUNNING to the Service Control Manager. */
ldap_pvt_thread_cond_init( &started_event );
if ( started_event == NULL)
{
/* 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);
}
else
{
/* start a thread to report the progress to the service control manager
* until the started_event is fired. */
if ( ldap_pvt_thread_create( &start_status_tid, 0, start_status_routine, NULL ) == 0 )
{
}
else {
/* failed to create the thread that tells the Service Control Manager that the
* 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);
}
}
}
void ReportSlapdShutdownComplete( )
{
if ( is_NT_Service )
{
/* stop sending SERVICE_STOP_PENDING messages to the Service Control Manager */
ldap_pvt_thread_cond_signal( &stopped_event );
ldap_pvt_thread_cond_destroy( &stopped_event );
/* wait for the thread sending the SERVICE_STOP_PENDING messages to the Service Control Manager to die.
* if the wait fails then put ourselves to sleep for half the Service Control Manager update interval */
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);
}
}
static char *GetErrorString( int err )
{
static char msgBuf[1024];
FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
msgBuf, 1024, NULL );
return msgBuf;
}
static char *GetLastErrorString( void )
{
return GetErrorString( GetLastError() );
}
#endif

206
libraries/liblutil/sasl.c Normal file
View file

@ -0,0 +1,206 @@
/* $OpenLDAP$ */
/*
* Copyright 2000-2002 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "portable.h"
#ifdef HAVE_CYRUS_SASL
#include <stdio.h>
#include <ac/stdlib.h>
#include <ac/string.h>
#include <ac/unistd.h>
#ifdef HAVE_SASL_SASL_H
#include <sasl/sasl.h>
#else
#include <sasl.h>
#endif
#include <ldap.h>
#include "lutil_ldap.h"
typedef struct lutil_sasl_defaults_s {
char *mech;
char *realm;
char *authcid;
char *passwd;
char *authzid;
} lutilSASLdefaults;
void *
lutil_sasl_defaults(
LDAP *ld,
char *mech,
char *realm,
char *authcid,
char *passwd,
char *authzid )
{
lutilSASLdefaults *defaults;
defaults = ber_memalloc( sizeof( lutilSASLdefaults ) );
if( defaults == NULL ) return NULL;
defaults->mech = mech;
defaults->realm = realm;
defaults->authcid = authcid;
defaults->passwd = passwd;
defaults->authzid = authzid;
if( defaults->mech == NULL ) {
ldap_get_option( ld, LDAP_OPT_X_SASL_MECH, &defaults->mech );
}
if( defaults->realm == NULL ) {
ldap_get_option( ld, LDAP_OPT_X_SASL_REALM, &defaults->realm );
}
if( defaults->authcid == NULL ) {
ldap_get_option( ld, LDAP_OPT_X_SASL_AUTHCID, &defaults->authcid );
}
if( defaults->authzid == NULL ) {
ldap_get_option( ld, LDAP_OPT_X_SASL_AUTHZID, &defaults->authzid );
}
return defaults;
}
static int interaction(
unsigned flags,
sasl_interact_t *interact,
lutilSASLdefaults *defaults )
{
const char *dflt = interact->defresult;
char input[1024];
int noecho=0;
int challenge=0;
switch( interact->id ) {
case SASL_CB_GETREALM:
if( defaults ) dflt = defaults->realm;
break;
case SASL_CB_AUTHNAME:
if( defaults ) dflt = defaults->authcid;
break;
case SASL_CB_PASS:
if( defaults ) dflt = defaults->passwd;
noecho = 1;
break;
case SASL_CB_USER:
if( defaults ) dflt = defaults->authzid;
break;
case SASL_CB_NOECHOPROMPT:
noecho = 1;
challenge = 1;
break;
case SASL_CB_ECHOPROMPT:
challenge = 1;
break;
}
if( dflt && !*dflt ) dflt = NULL;
if( flags != LDAP_SASL_INTERACTIVE &&
( dflt || interact->id == SASL_CB_USER ) )
{
goto use_default;
}
if( flags == LDAP_SASL_QUIET ) {
/* don't prompt */
return LDAP_OTHER;
}
if( challenge ) {
if( interact->challenge ) {
fprintf( stderr, "Challenge: %s\n", interact->challenge );
}
}
if( dflt ) {
fprintf( stderr, "Default: %s\n", dflt );
}
snprintf( input, sizeof input, "%s: ",
interact->prompt ? interact->prompt : "Interact" );
if( noecho ) {
interact->result = (char *) getpassphrase( input );
interact->len = interact->result
? strlen( interact->result ) : 0;
} else {
/* prompt user */
fputs( input, stderr );
/* get input */
interact->result = fgets( input, sizeof(input), stdin );
if( interact->result == NULL ) {
interact->len = 0;
return LDAP_UNAVAILABLE;
}
/* len of input */
interact->len = strlen(input);
if( interact->len > 0 && input[interact->len - 1] == '\n' ) {
/* input includes '\n', trim it */
interact->len--;
input[interact->len] = '\0';
}
}
if( interact->len > 0 ) {
/* duplicate */
char *p = (char *)interact->result;
interact->result = strdup( p );
/* zap */
memset( p, '\0', interact->len );
} else {
use_default:
/* input must be empty */
interact->result = strdup( (dflt && *dflt) ? dflt : "" );
interact->len = interact->result
? strlen( interact->result ) : 0;
}
if( defaults && defaults->passwd && interact->id == SASL_CB_PASS ) {
/* zap password after first use */
memset( defaults->passwd, '\0', strlen(defaults->passwd) );
defaults->passwd = NULL;
}
return LDAP_SUCCESS;
}
int lutil_sasl_interact(
LDAP *ld,
unsigned flags,
void *defaults,
void *in )
{
sasl_interact_t *interact = in;
if( flags == LDAP_SASL_INTERACTIVE ) {
fputs( "SASL Interaction\n", stderr );
}
while( interact->id != SASL_CB_LIST_END ) {
int rc = interaction( flags, interact, defaults );
if( rc ) return rc;
interact++;
}
return LDAP_SUCCESS;
}
#endif

228
libraries/liblutil/stdio.c Normal file
View file

@ -0,0 +1,228 @@
/* $OpenLDAP$ */
/*
* Copyright 2002 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "portable.h"
#include <stdio.h>
#include <ac/stdarg.h>
#include <ac/string.h>
#include <lutil.h>
#ifndef HAVE_VSNPRINTF
/* Write at most n characters to the buffer in str, return the
* number of chars written or -1 if the buffer would have been
* overflowed.
*
* This is portable to any POSIX-compliant system. We use pipe()
* to create a valid file descriptor, and then fdopen() it to get
* a valid FILE pointer. The user's buffer and size are assigned
* to the FILE pointer using setvbuf. Then we close the read side
* of the pipe to invalidate the descriptor.
*
* If the write arguments all fit into size n, the write will
* return successfully. If the write is too large, the stdio
* buffer will need to be flushed to the underlying file descriptor.
* The flush will fail because it is attempting to write to a
* broken pipe, and the write will be terminated.
* -- hyc, 2002-07-19
*/
#ifndef HAVE_EBCDIC
/* This emulation uses vfprintf; on OS/390 we're also emulating
* that function so it's more efficient just to have a separate
* version of vsnprintf there.
*/
#include <ac/signal.h>
int vsnprintf( char *str, size_t n, const char *fmt, va_list ap )
{
int fds[2], res;
FILE *f;
RETSIGTYPE (*sig)();
if (pipe( fds )) return -1;
f = fdopen( fds[1], "w" );
if ( !f ) {
close( fds[1] );
close( fds[0] );
return -1;
}
setvbuf( f, str, _IOFBF, n );
sig = signal( SIGPIPE, SIG_IGN );
close( fds[0] );
res = vfprintf( f, fmt, ap );
fclose( f );
signal( SIGPIPE, sig );
return res;
}
#endif
int snprintf( char *str, size_t n, const char *fmt, ... )
{
va_list ap;
int res;
va_start( ap, fmt );
res = vsnprintf( str, n, fmt, ap );
va_end( ap );
return res;
}
#endif /* !HAVE_VSNPRINTF */
#ifdef HAVE_EBCDIC
/* stdio replacements with ASCII/EBCDIC translation for OS/390.
* The OS/390 port depends on the CONVLIT compiler option being
* used to force character and string literals to be compiled in
* ISO8859-1, and the __LIBASCII cpp symbol to be defined to use the
* OS/390 ASCII-compatibility library. This library only supplies
* an ASCII version of sprintf, so other needed functions are
* provided here.
*
* All of the internal character manipulation is done in ASCII,
* but file I/O is EBCDIC, so we catch any stdio reading/writing
* of files here and do the translations.
*/
#undef fputs
#undef fgets
char *lutil_fgets( char *s, int n, FILE *fp )
{
s = (char *)fgets( s, n, fp );
if ( s ) __etoa( s );
return s;
}
int lutil_fputs( const char *str, FILE *fp )
{
char buf[8192];
strncpy( buf, str, sizeof(buf) );
__atoe( buf );
return fputs( buf, fp );
}
/* The __LIBASCII doesn't include a working vsprintf, so we make do
* using just sprintf. This is a very simplistic parser that looks for
* format strings and uses sprintf to process them one at a time.
* Literal text is just copied straight to the destination.
* The result is appended to the destination string. The parser
* recognizes field-width specifiers and the 'l' qualifier; it
* may need to be extended to recognize other qualifiers but so
* far this seems to be enough.
*/
int vsnprintf( char *str, size_t n, const char *fmt, va_list ap )
{
char *ptr, *pct, *s2, *f2, *end;
char fm2[64];
int len, rem;
ptr = (char *)fmt;
s2 = str;
fm2[0] = '%';
if (n)
end = str + n;
else
end = NULL;
for (pct = strchr(ptr, '%'); pct; pct = strchr(ptr, '%')) {
len = pct-ptr;
if (end) {
rem = end-s2;
if (rem < 1) return -1;
if (rem < len) len = rem;
}
s2 = lutil_strncopy( s2, ptr, len );
/* Did we cheat the length above? If so, bail out */
if (len < pct-ptr) return -1;
for (pct++, f2 = fm2+1; isdigit(*pct);) *f2++ = *pct++;
if (*pct == 'l') *f2++ = *pct++;
if (*pct == '%') *s2++ = '%';
else {
*f2++ = *pct;
*f2 = '\0';
if (*pct == 's') {
char *ss = va_arg(ap, char *);
/* Attempt to limit sprintf output. This
* may be thrown off if field widths were
* specified for this string.
*
* If it looks like the string is too
* long for the remaining buffer, bypass
* sprintf and just copy what fits, then
* quit.
*/
if (end && strlen(ss) > (rem=end-s2)) {
strncpy(s2, ss, rem);
return -1;
} else {
s2 += sprintf(s2, fm2, ss);
}
} else
s2 += sprintf(s2, fm2, va_arg(ap, int));
}
ptr = pct + 1;
}
if (end) {
rem = end-s2;
if (rem > 0) {
len = strlen(ptr);
s2 = lutil_strncopy( s2, ptr, rem );
rem -= len;
}
if (rem < 0) return -1;
} else {
s2 = lutil_strcopy( s2, ptr );
}
return s2 - str;
}
int lutil_vsprintf( char *str, const char *fmt, va_list ap )
{
return vsnprintf( str, 0, fmt, ap );
}
/* The fixed buffer size here is a problem, we don't know how
* to flush the buffer and keep printing if the msg is too big.
* Hopefully we never try to write something bigger than this
* in a log msg...
*/
int lutil_vfprintf( FILE *fp, const char *fmt, va_list ap )
{
char buf[8192];
int res;
vsnprintf( buf, sizeof(buf), fmt, ap );
__atoe( buf );
res = fputs( buf, fp );
if (res == EOF) res = -1;
return res;
}
int lutil_printf( const char *fmt, ... )
{
va_list ap;
int res;
va_start( ap, fmt );
res = lutil_vfprintf( stdout, fmt, ap );
va_end( ap );
return res;
}
int lutil_fprintf( FILE *fp, const char *fmt, ... )
{
va_list ap;
int res;
va_start( ap, fmt );
res = lutil_vfprintf( fp, fmt, ap );
va_end( ap );
return res;
}
#endif

109
libraries/liblutil/utils.c Normal file
View file

@ -0,0 +1,109 @@
/* $OpenLDAP$ */
/*
* Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "portable.h"
#include <ac/stdlib.h>
#include <ac/string.h>
#include <ac/unistd.h>
#include <ac/time.h>
#ifdef HAVE_IO_H
#include <io.h>
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#include <lutil.h>
#include <ldap_defaults.h>
#ifdef HAVE_EBCDIC
int _trans_argv = 1;
#endif
char* lutil_progname( const char* name, int argc, char *argv[] )
{
char *progname;
if(argc == 0) {
return (char *)name;
}
#ifdef HAVE_EBCDIC
if (_trans_argv) {
int i;
for (i=0; i<argc; i++) __etoa(argv[i]);
_trans_argv = 0;
}
#endif
progname = strrchr ( argv[0], *LDAP_DIRSEP );
progname = progname ? &progname[1] : argv[0];
return progname;
}
size_t lutil_gentime( char *s, size_t max, const struct tm *tm )
{
size_t ret;
#ifdef HAVE_EBCDIC
/* We've been compiling in ASCII so far, but we want EBCDIC now since
* strftime only understands EBCDIC input.
*/
#pragma convlit(suspend)
#endif
ret = strftime( s, max, "%Y%m%d%H%M%SZ", tm );
#ifdef HAVE_EBCDIC
#pragma convlit(resume)
__etoa( s );
#endif
return ret;
}
/* strcopy is like strcpy except it returns a pointer to the trailing NUL of
* the result string. This allows fast construction of catenated strings
* without the overhead of strlen/strcat.
*/
char *
lutil_strcopy(
char *a,
const char *b
)
{
if (!a || !b)
return a;
while ((*a++ = *b++)) ;
return a-1;
}
/* strncopy is like strcpy except it returns a pointer to the trailing NUL of
* the result string. This allows fast construction of catenated strings
* without the overhead of strlen/strcat.
*/
char *
lutil_strncopy(
char *a,
const char *b,
size_t n
)
{
if (!a || !b || n == 0)
return a;
while ((*a++ = *b++) && n-- > 0) ;
return a-1;
}
#ifndef HAVE_MKSTEMP
int mkstemp( char * template )
{
#ifdef HAVE_MKTEMP
return open ( mktemp ( template ), O_RDWR|O_CREAT|O_EXCL, 0600 );
#else
return -1;
#endif
}
#endif

View file

@ -24,6 +24,8 @@
#include <portable.h>
#include <stdio.h>
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
@ -541,6 +543,7 @@ rewrite_xmap_apply(
break;
}
#ifdef HAVE_PW_GECOS
if ( pwd->pw_gecos != NULL && pwd->pw_gecos[0] != '\0' ) {
int l = strlen( pwd->pw_gecos );
@ -555,7 +558,9 @@ rewrite_xmap_apply(
break;
}
val->bv_len = l;
} else {
} else
#endif /* HAVE_PW_GECOS */
{
val->bv_val = strdup( key->bv_val );
val->bv_len = key->bv_len;
}

View file

@ -24,6 +24,8 @@
#include <portable.h>
#include <stdio.h>
#include "rewrite-int.h"
static int

View file

@ -0,0 +1,144 @@
/******************************************************************************
*
* Copyright (C) 2000 Pierangelo Masarati, <ando@sys-net.it>
* All rights reserved.
*
* Permission is granted to anyone to use this software for any purpose
* on any computer system, and to alter it and redistribute it, subject
* to the following restrictions:
*
* 1. The author is not responsible for the consequences of use of this
* software, no matter how awful, even if they arise from flaws in it.
*
* 2. The origin of this software must not be misrepresented, either by
* explicit claim or by omission. Since few users ever read sources,
* credits should appear in the documentation.
*
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software. Since few users
* ever read sources, credits should appear in the documentation.
*
* 4. This notice may not be removed or altered.
*
******************************************************************************/
#include <portable.h>
#include <ac/stdlib.h>
#include <ac/string.h>
#include <ac/syslog.h>
#include <ac/regex.h>
#include <ac/socket.h>
#include <ac/unistd.h>
#include <ac/ctype.h>
#include <ac/string.h>
#include <stdio.h>
#include <rewrite.h>
int ldap_debug;
int ldap_syslog;
int ldap_syslog_level;
char *
apply(
FILE *fin,
const char *rewriteContext,
const char *arg
)
{
struct rewrite_info *info;
char *string, *sep, *result = NULL;
int rc;
void *cookie = &info;
info = rewrite_info_init(REWRITE_MODE_ERR);
if ( rewrite_read( fin, info ) != 0 ) {
exit( EXIT_FAILURE );
}
rewrite_param_set( info, "prog", "rewrite" );
rewrite_session_init( info, cookie );
string = strdup( arg );
for ( sep = strchr( rewriteContext, ',' );
rewriteContext != NULL;
rewriteContext = sep,
sep ? sep = strchr( rewriteContext, ',' ) : NULL ) {
if ( sep != NULL ) {
sep[ 0 ] = '\0';
sep++;
}
/* rc = rewrite( info, rewriteContext, string, &result ); */
rc = rewrite_session( info, rewriteContext, string,
cookie, &result );
fprintf( stdout, "%s -> %s\n", string,
( result ? result : "unwilling to perform" ) );
if ( result == NULL ) {
break;
}
free( string );
string = result;
}
rewrite_session_delete( info, cookie );
return result;
}
int
main( int argc, char *argv[] )
{
FILE *fin = NULL;
char *rewriteContext = REWRITE_DEFAULT_CONTEXT;
while ( 1 ) {
int opt = getopt( argc, argv, "f:hr:" );
if ( opt == EOF ) {
break;
}
switch ( opt ) {
case 'f':
fin = fopen( optarg, "r" );
if ( fin == NULL ) {
fprintf( stderr, "unable to open file '%s'\n",
optarg );
exit( EXIT_FAILURE );
}
break;
case 'h':
fprintf( stderr,
"usage: rewrite [options] string\n"
"\n"
"\t\t-f file\t\tconfiguration file\n"
"\t\t-r rule[s]\tlist of comma-separated rules\n"
"\n"
"\tsyntax:\n"
"\t\trewriteEngine\t{on|off}\n"
"\t\trewriteContext\tcontextName [alias aliasedContextName]\n"
"\t\trewriteRule\tpattern subst [flags]\n"
"\n"
);
exit( EXIT_SUCCESS );
case 'r':
rewriteContext = strdup( optarg );
break;
}
}
if ( optind >= argc ) {
return -1;
}
apply( ( fin ? fin : stdin ), rewriteContext, argv[ optind ] );
return 0;
}