From: Benny Baumann Date: Mon, 23 Feb 2015 18:34:58 +0000 (+0100) Subject: fix: Properly check for success to create the necessary directories X-Git-Url: https://code.wpia.club/?a=commitdiff_plain;ds=inline;h=91814cbc6f74173f40278062f8de1859c9b2e7c4;hp=-c;p=cassiopeia.git fix: Properly check for success to create the necessary directories --- 91814cbc6f74173f40278062f8de1859c9b2e7c4 diff --git a/src/util.cpp b/src/util.cpp index 20d4660..5cf30da 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -25,10 +25,17 @@ 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 ) ) { + return ""; + } + filename += "/crt"; - mkdir( filename.c_str(), 0755 ); + if( 0 != mkdir( filename.c_str(), 0755 ) ) { + return ""; + } std::string first; if( serial.length() < 3 ) { @@ -38,12 +45,15 @@ 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 ) ) { + return ""; + } filename += "/" + serial + ".crt"; writeFile( filename, cert ); return filename; } + bool isDigit( char c ) { return ( c >= '0' ) && ( c <= '9' ); }