X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslurpd%2Freject.c;h=9b872925a0f9100045dc560442200a069cd6866e;hb=98a13edc3989792355dbe9496107a5ba06c3be0c;hp=8ae0dc63635728ca298566a8cced943f1ff4d134;hpb=42e0d83cb3a1a1c5b25183f1ab74ce7edbe25de7;p=openldap diff --git a/servers/slurpd/reject.c b/servers/slurpd/reject.c index 8ae0dc6363..9b872925a0 100644 --- a/servers/slurpd/reject.c +++ b/servers/slurpd/reject.c @@ -1,5 +1,18 @@ -/* - * Copyright (c) 1996 Regents of the University of Michigan. +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software . + * + * Copyright 1998-2005 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 file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . + */ +/* Portions Copyright (c) 1996 Regents of the University of Michigan. * All rights reserved. * * Redistribution and use in source and binary forms are permitted @@ -9,6 +22,10 @@ * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. */ +/* ACKNOWLEDGEMENTS: + * This work was originally developed by the University of Michigan + * (as part of U-MICH LDAP). + */ /* @@ -17,20 +34,25 @@ * to a replica LDAP server. */ +#include "portable.h" #include -#include + +#include +#include +#include + #include #include -#include #include "slurp.h" #include "globals.h" -#ifndef SYSERRLIST_IN_STDIO -extern char *sys_errlist[]; -#endif /* SYSERRLIST_IN_STDIO */ - +#ifdef _WIN32 +#define PORTSEP "," +#else +#define PORTSEP ":" +#endif /* * Write a replication record to a reject file. The reject file has the @@ -52,19 +74,19 @@ write_reject( FILE *rfp, *lfp; int rc; - pthread_mutex_lock( &sglob->rej_mutex ); - sprintf( rejfile, "%s/%s:%d.rej", sglob->slurpd_rdir, - ri->ri_hostname, ri->ri_port ); + ldap_pvt_thread_mutex_lock( &sglob->rej_mutex ); + snprintf( rejfile, sizeof rejfile, "%s" LDAP_DIRSEP "%s" PORTSEP "%d.rej", + sglob->slurpd_rdir, ri->ri_hostname, ri->ri_port ); if ( access( rejfile, F_OK ) < 0 ) { /* Doesn't exist - try to create */ int rjfd; - if (( rjfd = open( rejfile, O_RDWR | O_APPEND | O_CREAT, + if (( rjfd = open( rejfile, O_RDWR|O_APPEND|O_CREAT|O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP )) < 0 ) { Debug( LDAP_DEBUG_ANY, "Error: write_reject: Cannot create \"%s\": %s\n", rejfile, sys_errlist[ errno ], 0 ); - pthread_mutex_unlock( &sglob->rej_mutex ); + ldap_pvt_thread_mutex_unlock( &sglob->rej_mutex ); return; } else { close( rjfd ); @@ -75,11 +97,11 @@ write_reject( rejfile, 0, 0 ); } else { fseek( rfp, 0, 2 ); - if ( errmsg != NULL ) { - fprintf( rfp, "%s: %s\n", ERROR_STR, errmsg ); - } else { - fprintf( rfp, "%s: %s\n", ERROR_STR, ldap_err2string( lderr )); + fprintf( rfp, "%s: %s", ERROR_STR, ldap_err2string( lderr )); + if ( errmsg && *errmsg ) { + fprintf( rfp, ": %s", errmsg ); } + fprintf( rfp, "\n" ); if ((rc = re->re_write( ri, re, rfp )) < 0 ) { Debug( LDAP_DEBUG_ANY, "Error: cannot write reject file \"%s\"\n", @@ -90,7 +112,7 @@ write_reject( "Error: ldap operation failed, data written to \"%s\"\n", rejfile, 0, 0 ); } - pthread_mutex_unlock( &sglob->rej_mutex ); + ldap_pvt_thread_mutex_unlock( &sglob->rej_mutex ); return; }