From 50f1d813e2b532e0dd2bec66f9ea12e2abdfcc81 Mon Sep 17 00:00:00 2001 From: Matchman Green Date: Thu, 24 May 2012 19:06:03 +0800 Subject: [PATCH] set the mode of .grive to 0600 for security. Thanks Huin for the reminder. --- grive/src/Config.cc | 8 +++++--- libgrive/src/drive/Drive.cc | 3 --- libgrive/src/protocol/Json.cc | 7 +++++++ libgrive/src/protocol/Json.hh | 3 +++ 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/grive/src/Config.cc b/grive/src/Config.cc index b5fbbef..cc3341d 100644 --- a/grive/src/Config.cc +++ b/grive/src/Config.cc @@ -19,7 +19,8 @@ #include "Config.hh" -#include +#include "util/StdioFile.hh" + #include namespace gr { @@ -39,8 +40,9 @@ Config::Config() : void Config::Save( ) { - std::ofstream ofile( Filename().c_str() ) ; - ofile << m_cfg ; + StdioFile file( Filename(), "w" ) ; + file.Chmod( 0600 ) ; + m_cfg.Write( file ) ; } Json& Config::Get() diff --git a/libgrive/src/drive/Drive.cc b/libgrive/src/drive/Drive.cc index 5b50a20..e812b4c 100644 --- a/libgrive/src/drive/Drive.cc +++ b/libgrive/src/drive/Drive.cc @@ -117,7 +117,6 @@ Drive::Drive( OAuth2& auth ) : if ( has_next ) { -// http::ResponseLog log2( "second-", ".xml", &xrsp ) ; http.Get( nss["@href"], &xrsp, m_http_hdr ) ; resp = xrsp.Response() ; } @@ -132,8 +131,6 @@ void Drive::SaveState() void Drive::ConstructDirTree( http::Agent *http ) { http::XmlResponse xml ; -// http::ResponseLog log( "dir-", ".xml", &xml ) ; - http->Get( feed_base + "/-/folder?max-results=10&showroot=true", &xml, m_http_hdr ) ; xml::Node resp = xml.Response() ; diff --git a/libgrive/src/protocol/Json.cc b/libgrive/src/protocol/Json.cc index 257a18a..948b5cc 100644 --- a/libgrive/src/protocol/Json.cc +++ b/libgrive/src/protocol/Json.cc @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -256,6 +257,12 @@ std::ostream& operator<<( std::ostream& os, const Json& json ) return os << ::json_object_to_json_string( json.m_json ) ; } +void Json::Write( StdioFile& file ) const +{ + const char *str = ::json_object_to_json_string( m_json ) ; + file.Write( str, std::strlen(str) ) ; +} + Json::Type Json::DataType() const { assert( m_json != 0 ) ; diff --git a/libgrive/src/protocol/Json.hh b/libgrive/src/protocol/Json.hh index 18cb88a..f5fc66f 100644 --- a/libgrive/src/protocol/Json.hh +++ b/libgrive/src/protocol/Json.hh @@ -29,6 +29,8 @@ struct json_object ; namespace gr { +class StdioFile ; + class Json { public : @@ -72,6 +74,7 @@ public : bool FindInArray( const std::string& key, const std::string& value, Json& result ) const ; friend std::ostream& operator<<( std::ostream& os, const Json& json ) ; + void Write( StdioFile& file ) const ; enum Type { null_type, bool_type, double_type, int_type, object_type, array_type, string_type } ;