/* $NetBSD: main.c,v 1.1.1.7.6.1 2019/08/10 06:17:17 martin Exp $ */ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * * Copyright 1998-2019 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted only as authorized by the OpenLDAP * Public License. * * A copy of this license is available in the file LICENSE in the * top-level directory of the distribution or, alternatively, at * . */ /* Portions Copyright (c) 1995 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. */ #include __RCSID("$NetBSD: main.c,v 1.1.1.7.6.1 2019/08/10 06:17:17 martin Exp $"); #include "portable.h" #include #include #include #include #include #include #include #include #include "slap.h" #include "lutil.h" #include "ldif.h" #ifdef LDAP_SLAPI #include "slapi/slapi.h" #endif #ifdef LDAP_SIGCHLD static RETSIGTYPE wait4child( int sig ); #endif #ifdef HAVE_NT_SERVICE_MANAGER #define MAIN_RETURN(x) return static struct sockaddr_in bind_addr; #define SERVICE_EXIT( e, n ) do { \ if ( is_NT_Service ) { \ lutil_ServiceStatus.dwWin32ExitCode = (e); \ lutil_ServiceStatus.dwServiceSpecificExitCode = (n); \ } \ } while ( 0 ) #else #define SERVICE_EXIT( e, n ) #define MAIN_RETURN(x) return(x) #endif typedef int (MainFunc) LDAP_P(( int argc, char *argv[] )); extern MainFunc slapadd, slapcat, slapdn, slapindex, slappasswd, slaptest, slapauth, slapacl, slapschema; static struct { char *name; MainFunc *func; } tools[] = { {"slapadd", slapadd}, {"slapcat", slapcat}, {"slapdn", slapdn}, {"slapindex", slapindex}, {"slappasswd", slappasswd}, {"slapschema", slapschema}, {"slaptest", slaptest}, {"slapauth", slapauth}, {"slapacl", slapacl}, /* NOTE: new tools must be added in chronological order, * not in alphabetical order, because for backwards * compatibility name[4] is used to identify the * tools; so name[4]=='a' must refer to "slapadd" and * not to "slapauth". Alphabetical order can be used * for tools whose name[4] is not used yet */ {NULL, NULL} }; /* * 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 */ #ifndef HAVE_MKVERSION const char Versionstr[] = OPENLDAP_PACKAGE " " OPENLDAP_VERSION " Standalone LDAP Server (slapd)"; #endif extern OverlayInit slap_oinfo[]; extern BackendInfo slap_binfo[]; #define CHECK_NONE 0x00 #define CHECK_CONFIG 0x01 #define CHECK_LOGLEVEL 0x02 static int check = CHECK_NONE; static int version = 0; void *slap_tls_ctx; LDAP *slap_tls_ld; static int slapd_opt_slp( const char *val, void *arg ) { #ifdef HAVE_SLP /* NULL is default */ if ( val == NULL || *val == '(' || strcasecmp( val, "on" ) == 0 ) { slapd_register_slp = 1; slapd_slp_attrs = (val != NULL && *val == '(') ? val : NULL; } else if ( strcasecmp( val, "off" ) == 0 ) { slapd_register_slp = 0; /* NOTE: add support for URL specification? */ } else { fprintf(stderr, "unrecognized value \"%s\" for SLP option\n", val ); return -1; } return 0; #else fputs( "slapd: SLP support is not available\n", stderr ); return 0; #endif } /* * Option helper structure: * * oh_nam is left-hand part of