ldap/servers/plugins/automember/automember.c | 44 +++++++++++++++------------ ldap/servers/slapd/errormap.c | 10 ++++++ ldap/servers/slapd/slapi-plugin.h | 19 +++++++++++ 3 files changed, 55 insertions(+), 18 deletions(-)
New commits: commit 2b98d672c11a5e4111e5d22a322f4e8a414ca104 Author: Mark Reynolds mreynolds@redhat.com Date: Tue Nov 27 10:24:02 2012 -0500
Ticket 20 - Allow automember to work on entries that have already been added
Bug Description: If the server can not open a ldif for reading(mapping task), an incorrect error and file name is returned.
Fix Description: Report the correct file name, and correctly grab the OS error/string. Also made slapd_pr_strerr() and slapd_system_strerr() public, so I refactored the function names to be "slapi_" - so a lot of files are touched but the main change for this ticket is still in automember.c
https://fedorahosted.org/389/ticket/20
Reviewed by: richm(Thanks)
diff --git a/ldap/servers/plugins/automember/automember.c b/ldap/servers/plugins/automember/automember.c index a11909f..424b507 100644 --- a/ldap/servers/plugins/automember/automember.c +++ b/ldap/servers/plugins/automember/automember.c @@ -2333,6 +2333,7 @@ void automember_export_task_thread(void *arg){ task_data *td = NULL; PRFileDesc *ldif_fd; int i = 0; + int rc = 0;
td = (task_data *)slapi_task_get_data(task); slapi_task_begin(task, 1); @@ -2341,13 +2342,14 @@ void automember_export_task_thread(void *arg){
/* make sure we can open the ldif file */ if (( ldif_fd = PR_Open( td->ldif_out, PR_CREATE_FILE | PR_WRONLY, DEFAULT_FILE_MODE )) == NULL ){ - slapi_task_log_notice(task, "Automember export task could not open ldif file "%s" for writing %d\n", - td->ldif_out, PR_GetError() ); - slapi_task_log_status(task, "Automember export task could not open ldif file "%s" for writing %d\n", - td->ldif_out, PR_GetError() ); + rc = PR_GetOSError(); + slapi_task_log_notice(task, "Automember export task could not open ldif file "%s" for writing, error %d (%s)\n", + td->ldif_out, rc, slapi_system_strerror(rc)); + slapi_task_log_status(task, "Automember export task could not open ldif file "%s" for writing, error %d (%s)\n", + td->ldif_out, rc, slapi_system_strerror(rc) ); slapi_log_error( SLAPI_LOG_FATAL, AUTOMEMBER_PLUGIN_SUBSYSTEM, - "Could not open ldif file "%s" for writing %d\n", - td->ldif_out, PR_GetError() ); + "Could not open ldif file "%s" for writing, error %d (%s)\n", + td->ldif_out, rc, slapi_system_strerror(rc) ); result = SLAPI_DSE_CALLBACK_ERROR; goto out; } @@ -2516,6 +2518,7 @@ void automember_map_task_thread(void *arg){ task_data *td = NULL; PRFileDesc *ldif_fd_out = NULL; char *entrystr = NULL; + char *errstr = NULL; #if defined(USE_OPENLDAP) int buflen = 0; LDIFFP *ldif_fd_in = NULL; @@ -2534,29 +2537,34 @@ void automember_map_task_thread(void *arg){
/* make sure we can open the ldif files */ if(( ldif_fd_out = PR_Open( td->ldif_out, PR_CREATE_FILE | PR_WRONLY, DEFAULT_FILE_MODE )) == NULL ){ - slapi_task_log_notice(task, "The ldif file %s could not be accessed, error %d. Aborting task.\n", - td->ldif_out, rc); - slapi_task_log_status(task, "The ldif file %s could not be accessed, error %d. Aborting task.\n", - td->ldif_out, rc); + rc = PR_GetOSError(); + slapi_task_log_notice(task, "The ldif file %s could not be accessed, error %d (%s). Aborting task.\n", + td->ldif_out, rc, slapi_system_strerror(rc)); + slapi_task_log_status(task, "The ldif file %s could not be accessed, error %d (%s). Aborting task.\n", + td->ldif_out, rc, slapi_system_strerror(rc)); slapi_log_error( SLAPI_LOG_FATAL, AUTOMEMBER_PLUGIN_SUBSYSTEM, - "Could not open ldif file "%s" for writing %d\n", - td->ldif_out, PR_GetError() ); + "Could not open ldif file "%s" for writing, error %d (%s)\n", + td->ldif_out, rc, slapi_system_strerror(rc) ); result = SLAPI_DSE_CALLBACK_ERROR; goto out; }
#if defined(USE_OPENLDAP) if(( ldif_fd_in = ldif_open(td->ldif_in, "r")) == NULL ){ + rc = errno; + errstr = strerror(rc); #else if(( ldif_fd_in = PR_Open( td->ldif_in, PR_RDONLY, DEFAULT_FILE_MODE )) == NULL ){ + rc = PR_GetOSError(); + errstr = slapi_system_strerror(rc); #endif - slapi_task_log_notice(task, "The ldif file %s could not be accessed, error %d. Aborting task.\n", - td->ldif_in, rc); - slapi_task_log_status(task, "The ldif file %s could not be accessed, error %d. Aborting task.\n", - td->ldif_in, rc); + slapi_task_log_notice(task, "The ldif file %s could not be accessed, error %d (%s). Aborting task.\n", + td->ldif_in, rc, errstr); + slapi_task_log_status(task, "The ldif file %s could not be accessed, error %d (%s). Aborting task.\n", + td->ldif_in, rc, errstr); slapi_log_error( SLAPI_LOG_FATAL, AUTOMEMBER_PLUGIN_SUBSYSTEM, - "Could not open ldif file "%s" for reading %d\n", - td->ldif_out, PR_GetError() ); + "Could not open ldif file "%s" for reading, error %d (%s)\n", + td->ldif_in, rc, errstr ); result = SLAPI_DSE_CALLBACK_ERROR; goto out; } diff --git a/ldap/servers/slapd/errormap.c b/ldap/servers/slapd/errormap.c index d05e495..c585d25 100644 --- a/ldap/servers/slapd/errormap.c +++ b/ldap/servers/slapd/errormap.c @@ -73,6 +73,11 @@ slapd_pr_strerror( const int prerrno ) return( s ); }
+char * +slapi_pr_strerror( const int prerrno ) +{ + return slapd_pr_strerror(prerrno); +}
/* * return the string equivalent of a system error @@ -92,6 +97,11 @@ slapd_system_strerror( const int syserrno ) return( s ); }
+const char * +slapi_system_strerror( const int syserrno ) +{ + return slapd_system_strerror(syserrno); +}
/* * return the string equivalent of an NSPR error. If "prerrno" is not diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h index 978b02c..0e7220b 100644 --- a/ldap/servers/slapd/slapi-plugin.h +++ b/ldap/servers/slapd/slapi-plugin.h @@ -65,6 +65,7 @@ extern "C" { #include "prtypes.h" #include "ldap.h" #include "prprf.h" +#include "nspr.h" NSPR_API(PRUint32) PR_snprintf(char *out, PRUint32 outlen, const char *fmt, ...) #ifdef __GNUC__ __attribute__ ((format (printf, 3, 4))); @@ -7303,6 +7304,24 @@ int slapi_pw_set_entry_ext(Slapi_Entry *entry, Slapi_Value **vals, int flags); */ char *slapi_get_first_clear_text_pw(Slapi_Entry *entry);
+/** + * Return the string equivalent of an NSPR error + * * + * \param a NSPR error code + * + * \return a pointer to the error code string. + */ +char *slapi_pr_strerror( const PRErrorCode prerrno ); + +/** + * Return the string equivalent of an OS error + * + * \param a OS error code + * + * \return a pointer to the system error code string. + */ +const char *slapi_system_strerror( const int syserrno ); + #ifdef __cplusplus } #endif
389-commits@lists.fedoraproject.org