subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From phi...@apache.org
Subject svn commit: r1596539 - /subversion/trunk/subversion/libsvn_subr/config_auth.c
Date Wed, 21 May 2014 11:17:56 GMT
Author: philip
Date: Wed May 21 11:17:55 2014
New Revision: 1596539

URL: http://svn.apache.org/r1596539
Log:
Fix issue 4504: writing to read-only auth cache files.

* subversion/libsvn_subr/config_auth.c
  (svn_config_write_auth_data): Use temporary file and rename to handle
   permissions problems, note some questions about existing behaviour.

Modified:
    subversion/trunk/subversion/libsvn_subr/config_auth.c

Modified: subversion/trunk/subversion/libsvn_subr/config_auth.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/config_auth.c?rev=1596539&r1=1596538&r2=1596539&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/config_auth.c (original)
+++ subversion/trunk/subversion/libsvn_subr/config_auth.c Wed May 21 11:17:55 2014
@@ -122,7 +122,7 @@ svn_config_write_auth_data(apr_hash_t *h
 {
   apr_file_t *authfile = NULL;
   svn_stream_t *stream;
-  const char *auth_path;
+  const char *auth_path, *tmp_path;
 
   SVN_ERR(svn_auth__file_path(&auth_path, cred_kind, realmstring, config_dir,
                               pool));
@@ -131,25 +131,25 @@ svn_config_write_auth_data(apr_hash_t *h
                             _("Unable to locate auth file"));
 
   /* Add the realmstring to the hash, so programs (or users) can
-     verify exactly which set of credentials this file holds.  */
+     verify exactly which set of credentials this file holds.
+     ### What if realmstring key is already in the hash? */
   svn_hash_sets(hash, SVN_CONFIG_REALMSTRING_KEY,
                 svn_string_create(realmstring, pool));
 
-  SVN_ERR_W(svn_io_file_open(&authfile, auth_path,
-                             (APR_WRITE | APR_CREATE | APR_TRUNCATE
-                              | APR_BUFFERED),
-                             APR_OS_DEFAULT, pool),
+  SVN_ERR_W(svn_stream_open_unique(&stream, &tmp_path,
+                                   svn_dirent_dirname(auth_path, pool),
+                                   svn_io_file_del_on_pool_cleanup,
+                                   pool, pool),
             _("Unable to open auth file for writing"));
-
-  stream = svn_stream_from_aprfile2(authfile, FALSE, pool);
   SVN_ERR_W(svn_hash_write2(hash, stream, SVN_HASH_TERMINATOR, pool),
             apr_psprintf(pool, _("Error writing hash to '%s'"),
                          svn_dirent_local_style(auth_path, pool)));
-
   SVN_ERR(svn_stream_close(stream));
+  SVN_ERR(svn_io_file_rename(tmp_path, auth_path, pool));
 
   /* To be nice, remove the realmstring from the hash again, just in
-     case the caller wants their hash unchanged. */
+     case the caller wants their hash unchanged.
+     ### Should we also do this when a write error occurs? */
   svn_hash_sets(hash, SVN_CONFIG_REALMSTRING_KEY, NULL);
 
   return SVN_NO_ERROR;



Mime
View raw message