andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone
dc8c34
From db6a42a3ea5f6773e0e4e350211f7fc5b2b342d2 Mon Sep 17 00:00:00 2001
dc8c34
From: Mark Reynolds <mreynolds@redhat.com>
dc8c34
Date: Tue, 27 Nov 2012 10:24:02 -0500
dc8c34
Subject: [PATCH 19/22] Ticket 20 - Allow automember to work on entries that
dc8c34
 have already been added
dc8c34
dc8c34
Bug Description:  If the server can not open a ldif for reading(mapping task), an
dc8c34
                  incorrect error and file name is returned.
dc8c34
dc8c34
Fix Description:  Report the correct file name, and correctly grab the OS error/string.
dc8c34
                  Also made slapd_pr_strerr() and slapd_system_strerr() public, so I
dc8c34
                  refactored the function names to be "slapi_" - so a lot of files are
dc8c34
                  touched but the main change for this ticket is still in automember.c
dc8c34
dc8c34
https://fedorahosted.org/389/ticket/20
dc8c34
dc8c34
Reviewed by: richm(Thanks)
dc8c34
(cherry picked from commit bf2bfaab8e61f335442e4341ff33521a822bd830)
dc8c34
---
dc8c34
 ldap/servers/plugins/automember/automember.c | 44 +++++++++-------
dc8c34
 ldap/servers/slapd/errormap.c                | 10 ++++
dc8c34
 ldap/servers/slapd/slapi-plugin.h            | 75 ++++++++++++++++++++++++++++
dc8c34
 3 files changed, 111 insertions(+), 18 deletions(-)
dc8c34
dc8c34
diff --git a/ldap/servers/plugins/automember/automember.c b/ldap/servers/plugins/automember/automember.c
dc8c34
index a11909f..424b507 100644
dc8c34
--- a/ldap/servers/plugins/automember/automember.c
dc8c34
+++ b/ldap/servers/plugins/automember/automember.c
dc8c34
@@ -2333,6 +2333,7 @@ void automember_export_task_thread(void *arg){
dc8c34
     task_data *td = NULL;
dc8c34
     PRFileDesc *ldif_fd;
dc8c34
     int i = 0;
dc8c34
+    int rc = 0;
dc8c34
 
dc8c34
     td = (task_data *)slapi_task_get_data(task);
dc8c34
     slapi_task_begin(task, 1);
dc8c34
@@ -2341,13 +2342,14 @@ void automember_export_task_thread(void *arg){
dc8c34
 
dc8c34
     /* make sure we can open the ldif file */
dc8c34
     if (( ldif_fd = PR_Open( td->ldif_out, PR_CREATE_FILE | PR_WRONLY, DEFAULT_FILE_MODE )) == NULL ){
dc8c34
-        slapi_task_log_notice(task, "Automember export task could not open ldif file \"%s\" for writing %d\n",
dc8c34
-                              td->ldif_out, PR_GetError() );
dc8c34
-        slapi_task_log_status(task, "Automember export task could not open ldif file \"%s\" for writing %d\n",
dc8c34
-                              td->ldif_out, PR_GetError() );
dc8c34
+        rc = PR_GetOSError();
dc8c34
+        slapi_task_log_notice(task, "Automember export task could not open ldif file \"%s\" for writing, error %d (%s)\n",
dc8c34
+                              td->ldif_out, rc, slapi_system_strerror(rc));
dc8c34
+        slapi_task_log_status(task, "Automember export task could not open ldif file \"%s\" for writing, error %d (%s)\n",
dc8c34
+                              td->ldif_out, rc, slapi_system_strerror(rc) );
dc8c34
         slapi_log_error( SLAPI_LOG_FATAL, AUTOMEMBER_PLUGIN_SUBSYSTEM,
dc8c34
-                        "Could not open ldif file \"%s\" for writing %d\n",
dc8c34
-                        td->ldif_out, PR_GetError() );
dc8c34
+                        "Could not open ldif file \"%s\" for writing, error %d (%s)\n",
dc8c34
+                        td->ldif_out, rc, slapi_system_strerror(rc) );
dc8c34
         result = SLAPI_DSE_CALLBACK_ERROR;
dc8c34
         goto out;
dc8c34
     }
dc8c34
@@ -2516,6 +2518,7 @@ void automember_map_task_thread(void *arg){
dc8c34
     task_data *td = NULL;
dc8c34
     PRFileDesc *ldif_fd_out = NULL;
dc8c34
     char *entrystr = NULL;
dc8c34
+    char *errstr = NULL;
dc8c34
 #if defined(USE_OPENLDAP)
dc8c34
     int buflen = 0;
dc8c34
     LDIFFP *ldif_fd_in = NULL;
dc8c34
@@ -2534,29 +2537,34 @@ void automember_map_task_thread(void *arg){
dc8c34
 
dc8c34
     /* make sure we can open the ldif files */
dc8c34
     if(( ldif_fd_out = PR_Open( td->ldif_out, PR_CREATE_FILE | PR_WRONLY, DEFAULT_FILE_MODE  )) == NULL ){
dc8c34
-        slapi_task_log_notice(task, "The ldif file %s could not be accessed, error %d.  Aborting task.\n",
dc8c34
-                              td->ldif_out, rc);
dc8c34
-        slapi_task_log_status(task, "The ldif file %s could not be accessed, error %d.  Aborting task.\n",
dc8c34
-    	                      td->ldif_out, rc);
dc8c34
+        rc = PR_GetOSError();
dc8c34
+        slapi_task_log_notice(task, "The ldif file %s could not be accessed, error %d (%s).  Aborting task.\n",
dc8c34
+                              td->ldif_out, rc, slapi_system_strerror(rc));
dc8c34
+        slapi_task_log_status(task, "The ldif file %s could not be accessed, error %d (%s).  Aborting task.\n",
dc8c34
+                              td->ldif_out, rc, slapi_system_strerror(rc));
dc8c34
         slapi_log_error( SLAPI_LOG_FATAL, AUTOMEMBER_PLUGIN_SUBSYSTEM,
dc8c34
-                        "Could not open ldif file \"%s\" for writing %d\n",
dc8c34
-                        td->ldif_out, PR_GetError() );
dc8c34
+                        "Could not open ldif file \"%s\" for writing, error %d (%s)\n",
dc8c34
+                        td->ldif_out, rc, slapi_system_strerror(rc) );
dc8c34
         result = SLAPI_DSE_CALLBACK_ERROR;
dc8c34
         goto out;
dc8c34
     }
dc8c34
 
dc8c34
 #if defined(USE_OPENLDAP)
dc8c34
     if(( ldif_fd_in = ldif_open(td->ldif_in, "r")) == NULL ){
dc8c34
+        rc = errno;
dc8c34
+        errstr = strerror(rc);
dc8c34
 #else
dc8c34
     if(( ldif_fd_in = PR_Open( td->ldif_in, PR_RDONLY, DEFAULT_FILE_MODE  )) == NULL ){
dc8c34
+        rc = PR_GetOSError();
dc8c34
+        errstr = slapi_system_strerror(rc);
dc8c34
 #endif
dc8c34
-        slapi_task_log_notice(task, "The ldif file %s could not be accessed, error %d.  Aborting task.\n",
dc8c34
-                              td->ldif_in, rc);
dc8c34
-        slapi_task_log_status(task, "The ldif file %s could not be accessed, error %d.  Aborting task.\n",
dc8c34
-                              td->ldif_in, rc);
dc8c34
+        slapi_task_log_notice(task, "The ldif file %s could not be accessed, error %d (%s).  Aborting task.\n",
dc8c34
+                              td->ldif_in, rc, errstr);
dc8c34
+        slapi_task_log_status(task, "The ldif file %s could not be accessed, error %d (%s).  Aborting task.\n",
dc8c34
+                              td->ldif_in, rc, errstr);
dc8c34
         slapi_log_error( SLAPI_LOG_FATAL, AUTOMEMBER_PLUGIN_SUBSYSTEM,
dc8c34
-                        "Could not open ldif file \"%s\" for reading %d\n",
dc8c34
-                        td->ldif_out, PR_GetError() );
dc8c34
+                        "Could not open ldif file \"%s\" for reading, error %d (%s)\n",
dc8c34
+                        td->ldif_in, rc, errstr );
dc8c34
         result = SLAPI_DSE_CALLBACK_ERROR;
dc8c34
         goto out;
dc8c34
     }
dc8c34
diff --git a/ldap/servers/slapd/errormap.c b/ldap/servers/slapd/errormap.c
dc8c34
index d05e495..c585d25 100644
dc8c34
--- a/ldap/servers/slapd/errormap.c
dc8c34
+++ b/ldap/servers/slapd/errormap.c
dc8c34
@@ -73,6 +73,11 @@ slapd_pr_strerror( const int prerrno )
dc8c34
     return( s );
dc8c34
 }
dc8c34
 
dc8c34
+char *
dc8c34
+slapi_pr_strerror( const int prerrno )
dc8c34
+{
dc8c34
+    return slapd_pr_strerror(prerrno);
dc8c34
+}
dc8c34
 
dc8c34
 /*
dc8c34
  * return the string equivalent of a system error
dc8c34
@@ -92,6 +97,11 @@ slapd_system_strerror( const int syserrno )
dc8c34
     return( s );
dc8c34
 }
dc8c34
 
dc8c34
+const char *
dc8c34
+slapi_system_strerror( const int syserrno )
dc8c34
+{
dc8c34
+    return slapd_system_strerror(syserrno);
dc8c34
+}
dc8c34
 
dc8c34
 /*
dc8c34
  * return the string equivalent of an NSPR error.  If "prerrno" is not
dc8c34
diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h
dc8c34
index 4316833..4962b2a 100644
dc8c34
--- a/ldap/servers/slapd/slapi-plugin.h
dc8c34
+++ b/ldap/servers/slapd/slapi-plugin.h
dc8c34
@@ -65,6 +65,7 @@ extern "C" {
dc8c34
 #include "prtypes.h"
dc8c34
 #include "ldap.h"
dc8c34
 #include "prprf.h"
dc8c34
+#include "nspr.h"
dc8c34
 NSPR_API(PRUint32) PR_snprintf(char *out, PRUint32 outlen, const char *fmt, ...)
dc8c34
 #ifdef __GNUC__ 
dc8c34
         __attribute__ ((format (printf, 3, 4)));
dc8c34
@@ -7156,6 +7157,80 @@ uint64_t slapi_str_to_u64(const char *s);
dc8c34
 
dc8c34
 void slapi_set_plugin_open_rootdn_bind(Slapi_PBlock *pb);
dc8c34
 
dc8c34
+/* 
dc8c34
+ * Public entry extension getter/setter functions
dc8c34
+ *
dc8c34
+ * Currently, only slapi_pw_get/set_entry_ext is implemented.
dc8c34
+ * The functions are in pw.c.  Detailed usage of the factory 
dc8c34
+ * is found in the comments at the top of factory.c.
dc8c34
+ *
dc8c34
+ * When you plan to add other entry extension code AND
dc8c34
+ * the type-value pair is managed via ordinary mod,
dc8c34
+ * setter, getter and copy function having the same API
dc8c34
+ * are supposed to be implemented, then add the set to
dc8c34
+ * attrs_in_extension list in entry.c.  The set is called
dc8c34
+ * in slapi_entry_apply_mod_extension.
dc8c34
+ *
dc8c34
+ * Note: setter and getter are public, but copy function
dc8c34
+ * is not. (for the copy function, see pw_copy_entry_ext in pw.c)
dc8c34
+ */
dc8c34
+/* operation used in the entry extension setter */
dc8c34
+#define SLAPI_EXT_SET_ADD     0
dc8c34
+#define SLAPI_EXT_SET_REPLACE 1
dc8c34
+
dc8c34
+/**
dc8c34
+ * Get entry extension
dc8c34
+ *
dc8c34
+ * \param entry is the entry to retrieve the extension from
dc8c34
+ * \param vals is the array of (Slapi_Value *), which directly refers the extension.  Caller must duplicate it to use it for other than referring.
dc8c34
+ *
dc8c34
+ * \return LDAP_SUCCESS if successful.
dc8c34
+ * \return non-zero otherwise.
dc8c34
+ */
dc8c34
+int slapi_pw_get_entry_ext(Slapi_Entry *entry, Slapi_Value ***vals);
dc8c34
+
dc8c34
+/**
dc8c34
+ * Set entry extension
dc8c34
+ *
dc8c34
+ * \param entry is the entry to set the extension to
dc8c34
+ * \param vals is the array of (Slapi_Value *), which is consumed in slapi_pw_set_ext if the call is successful. 
dc8c34
+ * \param flags: SLAPI_EXT_SET_ADD -- add vals to the existing extension if any.
dc8c34
+ *               SLAPI_EXT_SET_REPLACE -- replace vals with the existing extension if any.
dc8c34
+ * No difference if there is no extension in the entry.
dc8c34
+ *
dc8c34
+ * \return LDAP_SUCCESS if successful.
dc8c34
+ * \return non-zero otherwise.
dc8c34
+ */
dc8c34
+int slapi_pw_set_entry_ext(Slapi_Entry *entry, Slapi_Value **vals, int flags);
dc8c34
+
dc8c34
+/**
dc8c34
+ * Get stashed clear password.
dc8c34
+ * If multiple of them are in the extension, the first one is returned.
dc8c34
+ *
dc8c34
+ * \param entry is the entry to retrieve the extension from
dc8c34
+ *
dc8c34
+ * \return a pointer to the clear password string.  Caller is responsible to free the string.
dc8c34
+ */
dc8c34
+char *slapi_get_first_clear_text_pw(Slapi_Entry *entry);
dc8c34
+
dc8c34
+/**
dc8c34
+ * Return the string equivalent of an NSPR error
dc8c34
+ *  *
dc8c34
+ * \param a NSPR error code
dc8c34
+ *
dc8c34
+ * \return a pointer to the error code string.
dc8c34
+ */
dc8c34
+char *slapi_pr_strerror( const PRErrorCode prerrno );
dc8c34
+
dc8c34
+/**
dc8c34
+ * Return the string equivalent of an OS error
dc8c34
+ *
dc8c34
+ * \param a OS error code
dc8c34
+ *
dc8c34
+ * \return a pointer to the system error code string.
dc8c34
+ */
dc8c34
+const char *slapi_system_strerror( const int syserrno );
dc8c34
+
dc8c34
 #ifdef __cplusplus
dc8c34
 }
dc8c34
 #endif
dc8c34
-- 
dc8c34
1.7.11.7
dc8c34