MozNSS Compat. Layer: fix recursive directory deletion
- ad #1516409#c7 case 2 (cherry picked from commit c66191c12b1bf372204cf3bf0b31759e7b0bd133) (originally #1516409) Related: #1400570
This commit is contained in:
parent
716f3439ac
commit
e6c4c72153
@ -1,7 +1,7 @@
|
||||
MozNSS Interception Code
|
||||
|
||||
Author: Matus Honek <mhonek@redhat.com>
|
||||
Date: Thu Jan 11 01:00:55 CET 2018
|
||||
Date: Tue Jan 30 17:46:02 CET 2018
|
||||
diff --git a/configure.in b/configure.in
|
||||
--- a/configure.in
|
||||
+++ b/configure.in
|
||||
@ -283,7 +283,7 @@ diff --git a/libraries/libldap/tls_mc.c b/libraries/libldap/tls_mc.c
|
||||
new file mode 100644
|
||||
--- /dev/null
|
||||
+++ b/libraries/libldap/tls_mc.c
|
||||
@@ -0,0 +1,1308 @@
|
||||
@@ -0,0 +1,1316 @@
|
||||
+#include "portable.h"
|
||||
+
|
||||
+#ifdef HAVE_MOZNSS_COMPATIBILITY
|
||||
@ -294,6 +294,7 @@ new file mode 100644
|
||||
+#include <ac/errno.h>
|
||||
+#include <ac/termios.h>
|
||||
+#include <fcntl.h>
|
||||
+#include <dirent.h>
|
||||
+
|
||||
+#include <nspr/nspr.h>
|
||||
+#include <nspr/private/pprio.h>
|
||||
@ -392,49 +393,55 @@ new file mode 100644
|
||||
+}
|
||||
+
|
||||
+
|
||||
+int
|
||||
+tlsmc_remove_dir_recursively( char *dir_name )
|
||||
+static int
|
||||
+tlsmc_remove_dir_recursively( const char *dir_name )
|
||||
+{
|
||||
+ int rv = 0;
|
||||
+ PRDir *dir = NULL;
|
||||
+ PRDirEntry *entry = NULL;
|
||||
+ DIR *dir = NULL;
|
||||
+ struct dirent *entry = NULL;
|
||||
+ char *full_path = NULL;
|
||||
+
|
||||
+ Debug( LDAP_DEBUG_TRACE,
|
||||
+ "tlsmc_remove_dir_recursively: INFO: starting recursively removing directory `%s'.\n",
|
||||
+ dir_name, 0, 0 );
|
||||
+ if ( NULL == ( dir = PR_OpenDir( dir_name ) ) ) {
|
||||
+ if ( NULL == ( dir = opendir( dir_name ) ) ) {
|
||||
+ Debug( LDAP_DEBUG_ANY,
|
||||
+ "tlsmc_remove_dir_recursively: WARN: could not open directory `%s'.\n",
|
||||
+ dir_name, 0, 0 );
|
||||
+ rv = 0;
|
||||
+ "tlsmc_remove_dir_recursively: ERROR: could not open the directory (errno %d: %s).\n",
|
||||
+ errno, strerror( errno ), 0 );
|
||||
+ goto bail;
|
||||
+ }
|
||||
+
|
||||
+ while ( NULL != ( entry = PR_ReadDir( dir, PR_SKIP_BOTH ) ) ) {
|
||||
+ PRFileInfo info;
|
||||
+ PRStatus prv;
|
||||
+ while ( NULL != ( entry = readdir( dir ) ) ) {
|
||||
+ struct stat info;
|
||||
+
|
||||
+ full_path = NULL;
|
||||
+ full_path = PR_smprintf( "%s/%s", dir_name, entry->name );
|
||||
+ full_path = PR_smprintf( "%s/%s", dir_name, entry->d_name );
|
||||
+
|
||||
+ if ( ( PR_SUCCESS == ( prv = PR_GetFileInfo( full_path, &info ) ) ) ) {
|
||||
+ if ( PR_FILE_DIRECTORY == info.type ) {
|
||||
+ Debug( LDAP_DEBUG_TRACE,
|
||||
+ "tlsmc_remove_dir_recursively: INFO: stepping in directory `%s'.\n",
|
||||
+ full_path, 0, 0 );
|
||||
+ if ( 0 == tlsmc_remove_dir_recursively( full_path ) ) {
|
||||
+ rv = 0;
|
||||
+ goto bail;
|
||||
+ if ( 0 != strcmp( entry->d_name, "." ) && 0 != strcmp( entry->d_name, ".." ) ) {
|
||||
+ if ( 0 == lstat( full_path, &info ) ) {
|
||||
+ if ( S_ISDIR( info.st_mode ) ) {
|
||||
+ Debug( LDAP_DEBUG_TRACE,
|
||||
+ "tlsmc_remove_dir_recursively: INFO: stepping into directory `%s'.\n",
|
||||
+ entry->d_name, 0, 0 );
|
||||
+ if ( 0 == tlsmc_remove_dir_recursively( full_path ) ) {
|
||||
+ goto bail_and_close_dir;
|
||||
+ }
|
||||
+ } else {
|
||||
+ Debug( LDAP_DEBUG_TRACE,
|
||||
+ "tlsmc_remove_dir_recursively: INFO: removing file `%s'.\n",
|
||||
+ entry->d_name, 0, 0 );
|
||||
+ if ( 0 != remove( full_path ) ) {
|
||||
+ Debug( LDAP_DEBUG_ANY,
|
||||
+ "tlsmc_remove_dir_recursively: ERROR: could not remove the file (errno %d: %s).\n",
|
||||
+ errno, strerror( errno ), 0 );
|
||||
+ goto bail_and_close_dir;
|
||||
+ }
|
||||
+ }
|
||||
+ } else {
|
||||
+ Debug( LDAP_DEBUG_TRACE,
|
||||
+ "tlsmc_remove_dir_recursively: INFO: removing file `%s'.\n",
|
||||
+ full_path, 0, 0 );
|
||||
+ if ( PR_FAILURE == PR_Delete( full_path ) ) {
|
||||
+ rv = 0;
|
||||
+ goto bail;
|
||||
+ }
|
||||
+ Debug( LDAP_DEBUG_ANY,
|
||||
+ "tlsmc_remove_dir_recursively: ERROR: could not stat `%s', (errno %d: %s).\n",
|
||||
+ full_path, errno, strerror( errno ) );
|
||||
+ goto bail_and_close_dir;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
@ -445,29 +452,30 @@ new file mode 100644
|
||||
+
|
||||
+ }
|
||||
+ Debug( LDAP_DEBUG_TRACE,
|
||||
+ "tlsmc_remove_dir_recursively: INFO: stepping out of directory `%s'.\n",
|
||||
+ dir_name, 0, 0 );
|
||||
+ if ( PR_FAILURE == PR_CloseDir( dir ) ) {
|
||||
+ "tlsmc_remove_dir_recursively: INFO: stepping out of the directory.\n",
|
||||
+ 0, 0, 0 );
|
||||
+ if ( 0 != closedir( dir ) ) {
|
||||
+ Debug( LDAP_DEBUG_ANY,
|
||||
+ "tlsmc_remove_dir_recursively: WARN: could not close directory `%s'.\n",
|
||||
+ dir_name, 0, 0 );
|
||||
+ rv = 0;
|
||||
+ "tlsmc_remove_dir_recursively: WARN: could not close the directory (errno %d: %s).\n",
|
||||
+ errno, strerror( errno ), 0 );
|
||||
+ goto bail;
|
||||
+ }
|
||||
+
|
||||
+ Debug( LDAP_DEBUG_TRACE,
|
||||
+ "tlsmc_remove_dir_recursively: INFO: removing the directory `%s'.\n",
|
||||
+ dir_name, 0, 0 );
|
||||
+ if ( PR_FAILURE == PR_RmDir( dir_name ) ) {
|
||||
+ "tlsmc_remove_dir_recursively: INFO: removing the directory itself.\n",
|
||||
+ 0, 0, 0 );
|
||||
+ if ( 0 != remove( dir_name ) ) {
|
||||
+ PRErrorCode errcode = PR_GetError();
|
||||
+ Debug( LDAP_DEBUG_ANY,
|
||||
+ "tlsmc_remove_dir_recursively: WARN: could not remove the directory `%s'.\n",
|
||||
+ dir_name, 0, 0 );
|
||||
+ rv = 0;
|
||||
+ "tlsmc_remove_dir_recursively: ERROR: could not remove the directory (errno %d: %s).\n",
|
||||
+ errno, strerror( errno ), 0 );
|
||||
+ goto bail;
|
||||
+ }
|
||||
+
|
||||
+ rv = 1;
|
||||
+
|
||||
+ goto bail;
|
||||
+bail_and_close_dir:
|
||||
+ closedir( dir );
|
||||
+bail:
|
||||
+ if ( full_path ) PR_smprintf_free( full_path );
|
||||
+ return rv;
|
||||
|
@ -518,6 +518,7 @@ exit 0
|
||||
%changelog
|
||||
* Wed Feb 7 2018 Matus Honek <mhonek@redhat.com> - 2.4.45-7
|
||||
- MozNSS Compat. Layer fixes (#1400570)
|
||||
- fix recursive directory deletion (orig. #1516409)
|
||||
- Ensure consistency of a PEM dir before usage (orig. #1516409)
|
||||
+ Warn just before use of a PIN about key file extraction
|
||||
- Enable usage of NSS DB with PEM cert/key (orig. #1525485)
|
||||
|
Loading…
Reference in New Issue
Block a user