3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright (c) 1996 Regents of the University of Michigan.
10 * Redistribution and use in source and binary forms are permitted
11 * provided that this notice is preserved and that due credit is given
12 * to the University of Michigan at Ann Arbor. The name of the University
13 * may not be used to endorse or promote products derived from this
14 * software without specific prior written permission. This software
15 * is provided ``as is'' without express or implied warranty.
20 * reject.c - routines to write replication records to reject files.
21 * An Re struct is writted to a reject file if it cannot be propagated
22 * to a replica LDAP server.
30 #include <ac/unistd.h>
39 * Write a replication record to a reject file. The reject file has the
40 * same name as the replica's private copy of the file but with ".rej"
41 * appended (e.g. "/usr/tmp/<hostname>:<port>.rej")
43 * If errmsg is non-NULL, use that as the error message in the reject
44 * file. Otherwise, use ldap_err2string( lderr ).
54 char rejfile[ MAXPATHLEN ];
58 ldap_pvt_thread_mutex_lock( &sglob->rej_mutex );
59 sprintf( rejfile, "%s/%s:%d.rej", sglob->slurpd_rdir,
60 ri->ri_hostname, ri->ri_port );
62 if ( access( rejfile, F_OK ) < 0 ) {
63 /* Doesn't exist - try to create */
65 if (( rjfd = open( rejfile, O_RDWR | O_APPEND | O_CREAT,
66 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP )) < 0 ) {
67 Debug( LDAP_DEBUG_ANY,
68 "Error: write_reject: Cannot create \"%s\": %s\n",
69 rejfile, sys_errlist[ errno ], 0 );
70 ldap_pvt_thread_mutex_unlock( &sglob->rej_mutex );
76 if (( rc = acquire_lock( rejfile, &rfp, &lfp )) < 0 ) {
77 Debug( LDAP_DEBUG_ANY, "Error: cannot open reject file \"%s\"\n",
81 if ( errmsg != NULL ) {
82 fprintf( rfp, "%s: %s\n", ERROR_STR, errmsg );
84 fprintf( rfp, "%s: %s\n", ERROR_STR, ldap_err2string( lderr ));
86 if ((rc = re->re_write( ri, re, rfp )) < 0 ) {
87 Debug( LDAP_DEBUG_ANY,
88 "Error: cannot write reject file \"%s\"\n",
91 (void) relinquish_lock( rejfile, rfp, lfp );
92 Debug( LDAP_DEBUG_ANY,
93 "Error: ldap operation failed, data written to \"%s\"\n",
96 ldap_pvt_thread_mutex_unlock( &sglob->rej_mutex );