From 5ea77a75dd2d2158401331879f3c8f47940a732c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 18:35:32 +0200 Subject: Adding upstream version 2.5.13+dfsg. Signed-off-by: Daniel Baumann --- servers/slapd/slaptest.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 servers/slapd/slaptest.c (limited to 'servers/slapd/slaptest.c') diff --git a/servers/slapd/slaptest.c b/servers/slapd/slaptest.c new file mode 100644 index 0000000..4992147 --- /dev/null +++ b/servers/slapd/slaptest.c @@ -0,0 +1,121 @@ +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software . + * + * Copyright 2004-2022 The OpenLDAP Foundation. + * Portions Copyright 2004 Pierangelo Masarati. + * 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 file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . + */ +/* ACKNOWLEDGEMENTS: + * This work was initially developed by Pierangelo Masarati for inclusion + * in OpenLDAP Software. + */ + +#include "portable.h" + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "slapcommon.h" + +#ifndef S_IWRITE +#define S_IWRITE S_IWUSR +#endif + +static int +test_file( const char *fname, const char *ftype ) +{ + struct stat st; + char ebuf[128]; + int save_errno; + + switch ( stat( fname, &st ) ) { + case 0: + if ( !( st.st_mode & S_IWRITE ) ) { + Debug( LDAP_DEBUG_ANY, "%s file " + "\"%s\" exists, but user does not have access\n", + ftype, fname ); + return -1; + } + break; + + case -1: + default: + save_errno = errno; + if ( save_errno == ENOENT ) { + FILE *fp = fopen( fname, "w" ); + + if ( fp == NULL ) { + save_errno = errno; + + Debug( LDAP_DEBUG_ANY, "unable to open file " + "\"%s\": %d (%s)\n", + fname, + save_errno, AC_STRERROR_R( save_errno, ebuf, sizeof(ebuf) ) ); + + return -1; + } + fclose( fp ); + unlink( fname ); + break; + } + + Debug( LDAP_DEBUG_ANY, "unable to stat file " + "\"%s\": %d (%s)\n", + slapd_pid_file, + save_errno, AC_STRERROR_R( save_errno, ebuf, sizeof(ebuf) ) ); + return -1; + } + + return 0; +} + +int +slaptest( int argc, char **argv ) +{ + int rc = EXIT_SUCCESS; + const char *progname = "slaptest"; + + slap_tool_init( progname, SLAPTEST, argc, argv ); + + if ( slapd_pid_file != NULL ) { + if ( test_file( slapd_pid_file, "pid" ) ) { + return EXIT_FAILURE; + } + } + + if ( slapd_args_file != NULL ) { + if ( test_file( slapd_args_file, "args" ) ) { + return EXIT_FAILURE; + } + } + + if ( !quiet ) { + fprintf( stderr, "config file testing succeeded\n"); + } + + if ( slap_tool_destroy()) + rc = EXIT_FAILURE; + + return rc; +} -- cgit v1.2.3