X-Git-Url: http://code.wpia.club/?a=blobdiff_plain;f=src%2Futil.cpp;h=ed7b42e61ff87a407c981ff791cd92d05459136a;hb=87325777087f80af2065a09977ae6abf39bc50d1;hp=f3d95c0ad522f3933ab1e7e57bf94d445a28d715;hpb=cb4c74b47e6643f15e503067c197f86cbc5e6263;p=cassiopeia.git diff --git a/src/util.cpp b/src/util.cpp index f3d95c0..ed7b42e 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -14,6 +14,8 @@ void writeFile( const std::string& name, const std::string& content ) { file.open( name ); file << content; file.close(); + + //! \FIXME: Error checking } std::string readFile( const std::string& name ) { @@ -25,10 +27,25 @@ std::string readFile( const std::string& name ) { } std::string writeBackFile( const std::string& serial, const std::string& cert, const std::string& keydir ) { + errno = 0; + std::string filename = keydir; - mkdir( filename.c_str(), 0755 ); + if( 0 != mkdir( filename.c_str(), 0755 ) ) { + if( EEXIST != errno ) { + return ""; + } + + //! \FIXME: Check this is a directory + } + filename += "/crt"; - mkdir( filename.c_str(), 0755 ); + if( 0 != mkdir( filename.c_str(), 0755 ) ) { + if( EEXIST != errno ) { + return ""; + } + + //! \FIXME: Check this is a directory + } std::string first; if( serial.length() < 3 ) { @@ -38,12 +55,20 @@ std::string writeBackFile( const std::string& serial, const std::string& cert, c } filename += "/" + first; - mkdir( filename.c_str(), 0755 ); + if( 0 != mkdir( filename.c_str(), 0755 ) ) { + if( EEXIST != errno ) { + return ""; + } + + //! \FIXME: Check this is a directory + } + filename += "/" + serial + ".crt"; writeFile( filename, cert ); return filename; } + bool isDigit( char c ) { return ( c >= '0' ) && ( c <= '9' ); } @@ -78,7 +103,7 @@ std::pair parseDate( const std::string& date ) { std::size_t siz = strftime( check, 11, "%Y-%m-%d", &t ); if( siz != 10 ) { - return std::pair( false, 0 ); + return std::pair( false, 0 ); // NO-COVERAGE (by contract of strftime) } std::string checkS( check, siz );