openldap/servers/slapd/back-shell/config.c

156 lines
3.8 KiB
C
Raw Normal View History

1998-08-09 08:43:13 +08:00
/* config.c - shell backend configuration file routine */
/* $OpenLDAP$ */
2000-05-16 00:35:48 +08:00
/*
2002-01-05 05:17:25 +08:00
* Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
2000-05-16 00:35:48 +08:00
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
1998-08-09 08:43:13 +08:00
1998-10-25 09:41:42 +08:00
#include "portable.h"
1998-08-09 08:43:13 +08:00
#include <stdio.h>
1998-10-25 09:41:42 +08:00
#include <ac/string.h>
#include <ac/socket.h>
1998-08-09 08:43:13 +08:00
#include "slap.h"
#include "shell.h"
#ifdef SHELL_SURROGATE_PARENT
static struct berval make_cmd_info(
char **args
)
{
struct berval ret = { 0, 0 };
int i;
ber_len_t offset;
for( i = 0; args[i] != NULL; i++ )
ret.bv_len += strlen( args[i] ) + 1;
ret.bv_val = ch_malloc( ret.bv_len );
offset = 0;
for( i = 0; args[i] != NULL; i++ ) {
strcpy( ret.bv_val + offset, args[i] );
offset += strlen( args[i] ) + 1;
}
return ret;
}
#endif /* SHELL_SURROGATE_PARENT */
int
shell_back_db_config(
BackendDB *be,
1999-08-21 03:29:43 +08:00
const char *fname,
1998-08-09 08:43:13 +08:00
int lineno,
int argc,
char **argv
)
{
struct shellinfo *si = (struct shellinfo *) be->be_private;
if ( si == NULL ) {
fprintf( stderr, "%s: line %d: shell backend info is null!\n",
fname, lineno );
return( 1 );
1998-08-09 08:43:13 +08:00
}
/* command + args to exec for binds */
if ( strcasecmp( argv[0], "bind" ) == 0 ) {
if ( argc < 2 ) {
fprintf( stderr,
"%s: line %d: missing executable in \"bind <executable>\" line\n",
fname, lineno );
return( 1 );
1998-08-09 08:43:13 +08:00
}
si->si_bind = MAKE_CMD_INFO( &argv[1] );
1998-08-09 08:43:13 +08:00
/* command + args to exec for unbinds */
} else if ( strcasecmp( argv[0], "unbind" ) == 0 ) {
if ( argc < 2 ) {
fprintf( stderr,
"%s: line %d: missing executable in \"unbind <executable>\" line\n",
fname, lineno );
return( 1 );
1998-08-09 08:43:13 +08:00
}
si->si_unbind = MAKE_CMD_INFO( &argv[1] );
1998-08-09 08:43:13 +08:00
/* command + args to exec for searches */
} else if ( strcasecmp( argv[0], "search" ) == 0 ) {
if ( argc < 2 ) {
fprintf( stderr,
"%s: line %d: missing executable in \"search <executable>\" line\n",
fname, lineno );
return( 1 );
1998-08-09 08:43:13 +08:00
}
si->si_search = MAKE_CMD_INFO( &argv[1] );
1998-08-09 08:43:13 +08:00
/* command + args to exec for compares */
} else if ( strcasecmp( argv[0], "compare" ) == 0 ) {
if ( argc < 2 ) {
fprintf( stderr,
"%s: line %d: missing executable in \"compare <executable>\" line\n",
fname, lineno );
return( 1 );
1998-08-09 08:43:13 +08:00
}
si->si_compare = MAKE_CMD_INFO( &argv[1] );
1998-08-09 08:43:13 +08:00
/* command + args to exec for modifies */
} else if ( strcasecmp( argv[0], "modify" ) == 0 ) {
if ( argc < 2 ) {
fprintf( stderr,
"%s: line %d: missing executable in \"modify <executable>\" line\n",
fname, lineno );
return( 1 );
1998-08-09 08:43:13 +08:00
}
si->si_modify = MAKE_CMD_INFO( &argv[1] );
1998-08-09 08:43:13 +08:00
/* command + args to exec for modrdn */
} else if ( strcasecmp( argv[0], "modrdn" ) == 0 ) {
if ( argc < 2 ) {
fprintf( stderr,
"%s: line %d: missing executable in \"modrdn <executable>\" line\n",
fname, lineno );
return( 1 );
1998-08-09 08:43:13 +08:00
}
si->si_modrdn = MAKE_CMD_INFO( &argv[1] );
1998-08-09 08:43:13 +08:00
/* command + args to exec for add */
} else if ( strcasecmp( argv[0], "add" ) == 0 ) {
if ( argc < 2 ) {
fprintf( stderr,
"%s: line %d: missing executable in \"add <executable>\" line\n",
fname, lineno );
return( 1 );
1998-08-09 08:43:13 +08:00
}
si->si_add = MAKE_CMD_INFO( &argv[1] );
1998-08-09 08:43:13 +08:00
/* command + args to exec for delete */
} else if ( strcasecmp( argv[0], "delete" ) == 0 ) {
if ( argc < 2 ) {
fprintf( stderr,
"%s: line %d: missing executable in \"delete <executable>\" line\n",
fname, lineno );
return( 1 );
1998-08-09 08:43:13 +08:00
}
si->si_delete = MAKE_CMD_INFO( &argv[1] );
1998-08-09 08:43:13 +08:00
/* command + args to exec for abandon */
} else if ( strcasecmp( argv[0], "abandon" ) == 0 ) {
if ( argc < 2 ) {
fprintf( stderr,
"%s: line %d: missing executable in \"abandon <executable>\" line\n",
fname, lineno );
return( 1 );
1998-08-09 08:43:13 +08:00
}
si->si_abandon = MAKE_CMD_INFO( &argv[1] );
1998-08-09 08:43:13 +08:00
/* anything else */
} else {
fprintf( stderr,
"%s: line %d: unknown directive \"%s\" in shell database definition (ignored)\n",
fname, lineno, argv[0] );
}
return 0;
1998-08-09 08:43:13 +08:00
}