main.c 11.5 KB
Newer Older
1
/* $OpenLDAP$ */
2
/*
Kurt Zeilenga's avatar
Kurt Zeilenga committed
3
 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4
5
 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
 */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
6
#include "portable.h"
Kurt Zeilenga's avatar
Kurt Zeilenga committed
7
8
9

#include <stdio.h>

10
#include <ac/signal.h>
Kurt Zeilenga's avatar
Kurt Zeilenga committed
11
12
13
#include <ac/socket.h>
#include <ac/string.h>
#include <ac/time.h>
14
#include <ac/unistd.h>
Hallvard Furuseth's avatar
Hallvard Furuseth committed
15
16
17
#include <ac/wait.h>
#include <ac/signal.h>
#include <ac/errno.h>
Kurt Zeilenga's avatar
Kurt Zeilenga committed
18

19
#include "slap.h"
20
#include "lutil.h"
Kurt Zeilenga's avatar
Kurt Zeilenga committed
21

22
#ifdef LDAP_SIGCHLD
Hallvard Furuseth's avatar
Hallvard Furuseth committed
23
24
25
static RETSIGTYPE wait4child( int sig );
#endif

26
#ifdef HAVE_NT_SERVICE_MANAGER
27
#define MAIN_RETURN(x) return
28
29
struct sockaddr_in	bind_addr;

30
/* in nt_main.c */
Howard Chu's avatar
Howard Chu committed
31
32
LIBLUTIL_F (SERVICE_STATUS)		SLAPDServiceStatus;
LIBLUTIL_F (SERVICE_STATUS_HANDLE)	hSLAPDServiceStatus;
33
34
35
extern ldap_pvt_thread_cond_t	started_event,		stopped_event;
extern int	  is_NT_Service;

36
void CommenceStartupProcessing( LPCTSTR serverName,
37
38
39
40
							   void(*stopper)(int));
void ReportSlapdShutdownComplete( void );
void *getRegParam( char *svc, char *value );

41
42
43
44
45
46
47
#define SERVICE_EXIT( e, n )	do { \
	if ( is_NT_Service ) { \
		SLAPDServiceStatus.dwWin32ExitCode				= (e); \
		SLAPDServiceStatus.dwServiceSpecificExitCode	= (n); \
	} \
} while ( 0 )

48
49
#else
#define SERVICE_EXIT( e, n )
50
#define MAIN_RETURN(x) return(x)
51
52
#endif

53
#ifdef HAVE_NT_EVENT_LOG
54
55
56
57
void LogSlapdStartedEvent( char *svc, int slap_debug, char *configfile, char *urls );
void LogSlapdStoppedEvent( char *svc );
#endif

58
59
60
61
62
/*
 * 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
 */

Kurt Zeilenga's avatar
Kurt Zeilenga committed
63
#ifndef HAVE_MKVERSION
Kurt Zeilenga's avatar
Kurt Zeilenga committed
64
65
const char Versionstr[] =
	OPENLDAP_PACKAGE " " OPENLDAP_VERSION " Standalone LDAP Server (slapd)";
Kurt Zeilenga's avatar
Kurt Zeilenga committed
66
67
#endif

68
69
70
71
72
#ifdef LOG_LOCAL4

#define DEFAULT_SYSLOG_USER  LOG_LOCAL4

typedef struct _str2intDispatch {
73
74
75
	char    *stringVal;
	int      abbr;
	int      intVal;
76
77
78
79
80
} STRDISP, *STRDISP_P;


/* table to compute syslog-options to integer */
static STRDISP  syslog_types[] = {
81
82
83
84
85
86
87
88
89
	{ "LOCAL0", sizeof("LOCAL0"), LOG_LOCAL0 },
	{ "LOCAL1", sizeof("LOCAL1"), LOG_LOCAL1 },
	{ "LOCAL2", sizeof("LOCAL2"), LOG_LOCAL2 },
	{ "LOCAL3", sizeof("LOCAL3"), LOG_LOCAL3 },
	{ "LOCAL4", sizeof("LOCAL4"), LOG_LOCAL4 },
	{ "LOCAL5", sizeof("LOCAL5"), LOG_LOCAL5 },
	{ "LOCAL6", sizeof("LOCAL6"), LOG_LOCAL6 },
	{ "LOCAL7", sizeof("LOCAL7"), LOG_LOCAL7 },
	{ NULL }
90
91
};

Hallvard Furuseth's avatar
Hallvard Furuseth committed
92
static int   cnvt_str2int( char *, STRDISP_P, int );
93
94
95
96

#endif  /* LOG_LOCAL4 */


Hallvard Furuseth's avatar
Hallvard Furuseth committed
97
static void
98
usage( char *name )
Kurt Zeilenga's avatar
Kurt Zeilenga committed
99
{
Kurt Zeilenga's avatar
Kurt Zeilenga committed
100
101
102
	fprintf( stderr,
		"usage: %s options\n", name );
	fprintf( stderr,
103
#if LDAP_CONNECTIONLESS
Kurt Zeilenga's avatar
Kurt Zeilenga committed
104
		"\t-c\t\tEnable (experimental) Connectionless LDAP\n"
105
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
106
107
108
109
		"\t-d level\tDebug Level" "\n"
		"\t-f filename\tConfiguration File\n"
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
		"\t-g group\tGroup (id or name) to ran as\n"
110
#endif
111
		"\t-h URLs\tList of URLs to serve\n"
112
#ifdef LOG_LOCAL4
Kurt Zeilenga's avatar
Kurt Zeilenga committed
113
		"\t-l sysloguser\tSyslog User (default: LOCAL4)\n"
114
#endif
115
		"\t-n serverName\tservice name\n"
Kurt Zeilenga's avatar
Kurt Zeilenga committed
116
117
118
		"\t-s level\tSyslog Level\n"
#ifdef SLAPD_BDB2
		"\t-t\t\tEnable BDB2 timing\n"
Julio Sánchez Fernández's avatar
   
Julio Sánchez Fernández committed
119
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
120
121
122
123
124
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
		"\t-u user\tUser (id or name) to ran as\n"
#endif
    );
}
125

126
#ifdef HAVE_NT_SERVICE_MANAGER
127
128
129
130
void WINAPI ServiceMain( DWORD argc, LPTSTR *argv )
#else
int main( int argc, char **argv )
#endif
131
{
132
	int		i, no_detach = 0;
Gary Williams's avatar
NT port    
Gary Williams committed
133
	int		rc;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
134
	char *urls = NULL;
135
136
137
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
	char *username = NULL;
	char *groupname = NULL;
138
#endif
139
140
141
#if defined(HAVE_CHROOT)
	char *sandbox = NULL;
#endif
142
143
#ifdef LOG_LOCAL4
    int     syslogUser = DEFAULT_SYSLOG_USER;
144
#endif
145
146

#ifdef HAVE_NT_SERVICE_MANAGER
147
148
149
	char		*configfile = ".\\slapd.conf";
#else
	char		*configfile = SLAPD_DEFAULT_CONFIGFILE;
150
#endif
151
	char        *serverName = NULL;
152
	int         serverMode = SLAP_SERVER_MODE;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
153

154
155
156
157
158
159
160
#ifdef CSRIMALLOC
	FILE *leakfile;
	if( ( leakfile = fopen( "slapd.leak", "w" )) == NULL ) {
		leakfile = stderr;
	}
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
161
162
163
	g_argc = argc;
	g_argv = argv;

164
#ifdef HAVE_NT_SERVICE_MANAGER
165
	{
Kurt Zeilenga's avatar
Kurt Zeilenga committed
166
		int *i;
167
		char *newConfigFile;
Howard Chu's avatar
Howard Chu committed
168
		char *newUrls;
169
		char *regService = NULL;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
170
171

		if ( is_NT_Service ) {
172
173
174
175
			serverName = argv[0];
			CommenceStartupProcessing( serverName, slap_sig_shutdown );
			if ( strcmp(serverName, SERVICE_NAME) )
			    regService = serverName;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
176
177
		}

178
		i = (int*)getRegParam( regService, "DebugLevel" );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
179
		if ( i != NULL ) 
180
		{
Kurt Zeilenga's avatar
Kurt Zeilenga committed
181
			slap_debug = *i;
182
183
			Debug( LDAP_DEBUG_ANY, "new debug level from registry is: %d\n", slap_debug, 0, 0 );
		}
Howard Chu's avatar
Howard Chu committed
184

185
		newUrls = (char *) getRegParam(regService, "Urls");
Howard Chu's avatar
Howard Chu committed
186
187
188
189
190
191
192
193
194
195
		if (newUrls)
		{
		    if (urls)
			ch_free(urls);

		    urls = ch_strdup(newUrls);
		    Debug(LDAP_DEBUG_ANY, "new urls from registry: %s\n",
			  urls, 0, 0);
		}

196
		newConfigFile = (char*)getRegParam( regService, "ConfigFile" );
197
198
199
200
201
202
203
204
		if ( newConfigFile != NULL ) 
		{
			configfile = newConfigFile;
			Debug ( LDAP_DEBUG_ANY, "new config file from registry is: %s\n", configfile, 0, 0 );
		}
	}
#endif

205
	while ( (i = getopt( argc, argv,
206
			     "d:f:h:s:n:"
207
208
209
#ifdef HAVE_CHROOT
				"r:"
#endif
210
211
212
#ifdef LOG_LOCAL4
			     "l:"
#endif
213
#ifdef SLAPD_BDB2
214
			     "t"
215
#endif
216
217
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
			     "u:g:"
Kurt Zeilenga's avatar
Kurt Zeilenga committed
218
219
220
#endif
#ifdef LDAP_CONNECTIONLESS
				 "c"
221
#endif
222
			     )) != EOF ) {
Kurt Zeilenga's avatar
Kurt Zeilenga committed
223
		switch ( i ) {
Kurt Zeilenga's avatar
Kurt Zeilenga committed
224
		case 'h':	/* listen URLs */
Hallvard Furuseth's avatar
Hallvard Furuseth committed
225
			if ( urls != NULL ) free( urls );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
226
			urls = ch_strdup( optarg );
227
228
            break;

229
230
		case 'd':	/* set debug level and 'do not detach' flag */
			no_detach = 1;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
231
#ifdef LDAP_DEBUG
Kurt Zeilenga's avatar
Kurt Zeilenga committed
232
			slap_debug |= atoi( optarg );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
233
#else
234
235
236
			if ( atoi( optarg ) != 0 )
				fputs( "must compile with LDAP_DEBUG for debugging\n",
				       stderr );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
237
#endif
238
			break;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
239
240

		case 'f':	/* read config file */
241
			configfile = ch_strdup( optarg );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
242
243
244
245
246
247
			break;

		case 's':	/* set syslog level */
			ldap_syslog = atoi( optarg );
			break;

248
249
#ifdef LOG_LOCAL4
		case 'l':	/* set syslog local user */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
250
251
			syslogUser = cnvt_str2int( optarg,
				syslog_types, DEFAULT_SYSLOG_USER );
252
253
254
			break;
#endif

255
256
#ifdef LDAP_CONNECTIONLESS
		case 'c':	/* do connectionless (udp) */
257
258
			/* udp = 1; */
			fprintf( stderr, "connectionless support not supported");
Kurt Zeilenga's avatar
Kurt Zeilenga committed
259
			exit( EXIT_FAILURE );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
260
			break;
261
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
262

263
264
#ifdef SLAPD_BDB2
		case 't':  /* timed server */
265
			serverMode |= SLAP_TIMED_MODE;
266
267
268
			break;
#endif

269
270
271
272
273
274
275
#ifdef HAVE_CHROOT
		case 'r':
			if( sandbox ) free(sandbox);
			sandbox = ch_strdup( optarg );
			break;
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
276
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
277
278
		case 'u':	/* user name */
			if( username ) free(username);
279
280
281
			username = ch_strdup( optarg );
			break;

282
283
		case 'g':	/* group name */
			if( groupname ) free(groupname);
284
285
			groupname = ch_strdup( optarg );
			break;
286
#endif /* SETUID && GETUID */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
287

288
		case 'n':  /* NT service name */
289
290
			if( serverName != NULL ) free( serverName );
			serverName = ch_strdup( optarg );
291
			break;
292

Kurt Zeilenga's avatar
Kurt Zeilenga committed
293
294
		default:
			usage( argv[0] );
295
296
297
			rc = 1;
			SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 15 );
			goto stop;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
298
299
300
		}
	}

Kurt Zeilenga's avatar
Kurt Zeilenga committed
301
	ber_set_option(NULL, LBER_OPT_DEBUG_LEVEL, &slap_debug);
302
303
304
	ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &slap_debug);
	ldif_debug = slap_debug;

Kurt Zeilenga's avatar
Kurt Zeilenga committed
305
306
	Debug( LDAP_DEBUG_TRACE, "%s", Versionstr, 0, 0 );

307
308
309
310
311
312
	if( serverName == NULL ) {
		if ( (serverName = strrchr( argv[0], *LDAP_DIRSEP )) == NULL ) {
			serverName = ch_strdup( argv[0] );
		} else {
			serverName = ch_strdup( serverName + 1 );
		}
Kurt Zeilenga's avatar
Kurt Zeilenga committed
313
314
315
	}

#ifdef LOG_LOCAL4
316
	openlog( serverName, OPENLOG_OPTIONS, syslogUser );
317
#elif LOG_DEBUG
318
	openlog( serverName, OPENLOG_OPTIONS );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
319
320
#endif

321
	if( slapd_daemon_init( urls ) != 0 ) {
Kurt Zeilenga's avatar
Kurt Zeilenga committed
322
323
324
325
		rc = 1;
		SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 16 );
		goto stop;
	}
Kurt Zeilenga's avatar
Kurt Zeilenga committed
326

327
328
329
330
331
332
333
334
#if defined(HAVE_CHROOT)
	if ( sandbox && chroot( sandbox ) ) {
		perror("chroot");
		rc = 1;
		goto stop;
	}
#endif

335
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
Kurt Zeilenga's avatar
Kurt Zeilenga committed
336
	if ( username != NULL || groupname != NULL ) {
337
		slap_init_user( username, groupname );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
338
	}
339
340
#endif

341
342
	extops_init();

343
344
345
346
347
348
349
350
#ifdef SLAPD_MODULES
	if ( module_init() != 0 ) {
		rc = 1;
		SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 17 );
		goto destroy;
	}
#endif

351
	if ( slap_init( serverMode, serverName ) != 0 ) {
352
		rc = 1;
353
		SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 18 );
354
355
356
		goto destroy;
	}

357
358
359
360
361
362
363
	if ( schema_init( ) != 0 ) {
		Debug( LDAP_DEBUG_ANY,
		    "schema initialization error\n",
		    0, 0, 0 );
		goto destroy;
	}

364
365
	if ( read_config( configfile ) != 0 ) {
		rc = 1;
366
		SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 19 );
367
368
369
		goto destroy;
	}

370
371
372
373
374
375
376
	if ( schema_prep( ) != 0 ) {
		Debug( LDAP_DEBUG_ANY,
		    "schema prep error\n",
		    0, 0, 0 );
		goto destroy;
	}

377
378
#ifdef HAVE_TLS
	ldap_pvt_tls_init();
Howard Chu's avatar
Howard Chu committed
379
380
381
382
383
384
385

	if (ldap_pvt_tls_init_def_ctx() != 0)
	{
		rc = 1;
		SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
		goto destroy;
	}
386
387
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
388
389
390
	(void) SIGNAL( LDAP_SIGUSR1, slap_sig_wake );
	(void) SIGNAL( LDAP_SIGUSR2, slap_sig_shutdown );

391
#ifdef SIGPIPE
392
	(void) SIGNAL( SIGPIPE, SIG_IGN );
393
394
#endif
#ifdef SIGHUP
Kurt Zeilenga's avatar
Kurt Zeilenga committed
395
	(void) SIGNAL( SIGHUP, slap_sig_shutdown );
396
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
397
398
	(void) SIGNAL( SIGINT, slap_sig_shutdown );
	(void) SIGNAL( SIGTERM, slap_sig_shutdown );
399
400
#ifdef LDAP_SIGCHLD
	(void) SIGNAL( LDAP_SIGCHLD, wait4child );
Hallvard Furuseth's avatar
Hallvard Furuseth committed
401
#endif
402
#ifdef SIGBREAK
403
	/* SIGBREAK is generated when Ctrl-Break is pressed. */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
404
	(void) SIGNAL( SIGBREAK, slap_sig_shutdown );
405
#endif
406

407
#ifndef HAVE_WINSOCK
408
	lutil_detach( no_detach, 0 );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
409
#endif /* HAVE_WINSOCK */
410

411
412
413
414
#ifdef CSRIMALLOC
	mal_leaktrace(1);
#endif

415
	if ( slap_startup( NULL )  != 0 ) {
416
		rc = 1;
Howard Chu's avatar
Howard Chu committed
417
		SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 21 );
418
419
		goto shutdown;
	}
Kurt Zeilenga's avatar
Kurt Zeilenga committed
420

Kurt Zeilenga's avatar
Kurt Zeilenga committed
421
	{
422
		FILE *fp;
423

424
		Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 );
425

426
427
428
429
430
		if (( slapd_pid_file != NULL ) &&
			(( fp = fopen( slapd_pid_file, "w" )) != NULL ))
		{
			fprintf( fp, "%d\n", (int) getpid() );
			fclose( fp );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
431
432
		}

433
434
435
436
437
		if (( slapd_args_file != NULL ) &&
			(( fp = fopen( slapd_args_file, "w" )) != NULL ))
		{
			for ( i = 0; i < g_argc; i++ ) {
				fprintf( fp, "%s ", g_argv[i] );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
438
			}
439
440
441
442
			fprintf( fp, "\n" );
			fclose( fp );
		}
	}
Kurt Zeilenga's avatar
Kurt Zeilenga committed
443

444
#ifdef HAVE_NT_EVENT_LOG
Howard Chu's avatar
Howard Chu committed
445
	if (is_NT_Service)
446
	LogSlapdStartedEvent( serverName, slap_debug, configfile, urls );
447
448
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
449
	rc = slapd_daemon();
450

451
#ifdef HAVE_NT_SERVICE_MANAGER
452
	/* Throw away the event that we used during the startup process. */
453
454
455
	if ( is_NT_Service )
		ldap_pvt_thread_cond_destroy( &started_event );
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
456

457
shutdown:
458
	/* remember an error during shutdown */
459
	rc |= slap_shutdown( NULL );
460

461
destroy:
462
463
464
	/* remember an error during destroy */
	rc |= slap_destroy();

465
466
467
468
#ifdef SLAPD_MODULES
	module_kill();
#endif

469
470
	extops_kill();

471
stop:
472
#ifdef HAVE_NT_EVENT_LOG
Howard Chu's avatar
Howard Chu committed
473
	if (is_NT_Service)
474
	LogSlapdStoppedEvent( serverName );
475
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
476

477
	Debug( LDAP_DEBUG_ANY, "slapd stopped.\n", 0, 0, 0 );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
478

479
#ifdef HAVE_NT_SERVICE_MANAGER
480
481
	ReportSlapdShutdownComplete();
#endif
482

483
#ifdef LOG_DEBUG
484
    closelog();
485
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
486
	slapd_daemon_destroy();
487

488
489
490
491
#ifdef CSRIMALLOC
	mal_dumpleaktrace( leakfile );
#endif

492
	MAIN_RETURN(rc);
Kurt Zeilenga's avatar
Kurt Zeilenga committed
493
}
494
495


496
#ifdef LDAP_SIGCHLD
Hallvard Furuseth's avatar
Hallvard Furuseth committed
497
498
499
500
501
502
503
504
505

/*
 *  Catch and discard terminated child processes, to avoid zombies.
 */

static RETSIGTYPE
wait4child( int sig )
{
    int save_errno = errno;
Hallvard Furuseth's avatar
Hallvard Furuseth committed
506
507

#ifdef WNOHANG
Hallvard Furuseth's avatar
Hallvard Furuseth committed
508
    errno = 0;
Hallvard Furuseth's avatar
Hallvard Furuseth committed
509
#ifdef HAVE_WAITPID
Hallvard Furuseth's avatar
Hallvard Furuseth committed
510
511
    while ( waitpid( (pid_t)-1, NULL, WNOHANG ) >= 0 || errno == EINTR )
	;	/* NULL */
Hallvard Furuseth's avatar
Hallvard Furuseth committed
512
#else
Hallvard Furuseth's avatar
Hallvard Furuseth committed
513
514
    while ( wait3( NULL, WNOHANG, NULL ) >= 0 || errno == EINTR )
	;	/* NULL */
Hallvard Furuseth's avatar
Hallvard Furuseth committed
515
#endif
516
#else
Hallvard Furuseth's avatar
Hallvard Furuseth committed
517
518
    (void) wait( NULL );
#endif
Hallvard Furuseth's avatar
Hallvard Furuseth committed
519
    (void) SIGNAL( sig, wait4child );
Hallvard Furuseth's avatar
Hallvard Furuseth committed
520
521
522
523
524
525
    errno = save_errno;
}

#endif /* SIGCHLD || SIGCLD */


526
527
528
529
530
531
532
533
#ifdef LOG_LOCAL4

/*
 *  Convert a string to an integer by means of a dispatcher table
 *  if the string is not in the table return the default
 */

static int
Hallvard Furuseth's avatar
Hallvard Furuseth committed
534
cnvt_str2int( char *stringVal, STRDISP_P dispatcher, int defaultVal )
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
{
    int        retVal = defaultVal;
    STRDISP_P  disp;

    for (disp = dispatcher; disp->stringVal; disp++) {

        if (!strncasecmp (stringVal, disp->stringVal, disp->abbr)) {

            retVal = disp->intVal;
            break;

        }
    }

    return (retVal);
Kurt Zeilenga's avatar
Kurt Zeilenga committed
550
}
551
552

#endif  /* LOG_LOCAL4 */