Author: aschnell Date: Fri Jul 25 15:21:32 2008 New Revision: 49417 URL: http://svn.opensuse.org/viewcvs/yast?rev=49417&view=rev Log: - more shell quoting Modified: trunk/storage/libstorage/src/Md.cc trunk/storage/libstorage/src/SystemCmd.cc trunk/storage/libstorage/src/SystemCmd.h Modified: trunk/storage/libstorage/src/Md.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/Md.cc?rev=49417&r1=49416&r2=49417&view=diff ============================================================================== --- trunk/storage/libstorage/src/Md.cc (original) +++ trunk/storage/libstorage/src/Md.cc Fri Jul 25 15:21:32 2008 @@ -344,14 +344,8 @@ string Md::createCmd() const { - string dnames; - for( list<string>::const_iterator i=devs.begin(); i!=devs.end(); ++i ) - dnames += " " + *i; - for( list<string>::const_iterator i=spare.begin(); i!=spare.end(); ++i ) - dnames += " " + *i; - - string cmd = "ls -l --full-time " + dnames + "; "; - cmd += "modprobe " + pName() + "; mdadm --create " + device() + + string cmd = "ls -l --full-time " + SystemCmd::quote(devs) + " " + SystemCmd::quote(spare) + "; "; + cmd += "modprobe " + pName() + "; mdadm --create " + SystemCmd::quote(device()) + " --run --level=" + pName() + " -e 1.0"; if (pName() == "raid1" || pName() == "raid5" || pName() == "raid6" || pName() == "raid10") @@ -363,7 +357,7 @@ cmd += " --raid-devices=" + decString(devs.size()); if( !spare.empty() ) cmd += " --spare-devices=" + decString(spare.size()); - cmd += " " + dnames; + cmd += " " + SystemCmd::quote(devs) + " " + SystemCmd::quote(spare); y2milestone( "ret:%s", cmd.c_str() ); return( cmd ); } Modified: trunk/storage/libstorage/src/SystemCmd.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/SystemCmd.cc?rev=49417&r1=49416&r2=49417&view=diff ============================================================================== --- trunk/storage/libstorage/src/SystemCmd.cc (original) +++ trunk/storage/libstorage/src/SystemCmd.cc Fri Jul 25 15:21:32 2008 @@ -684,3 +684,16 @@ { return "'" + boost::replace_all_copy(str, "'", "'\\''") + "'"; } + + +string SystemCmd::quote(const list<string>& strs) +{ + string ret(""); + for(std::list<string>::const_iterator it = strs.begin(); it != strs.end(); it++) + { + if (it != strs.begin()) + ret.append(" "); + ret.append(quote(*it)); + } + return ret; +} Modified: trunk/storage/libstorage/src/SystemCmd.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/SystemCmd.h?rev=49417&r1=49416&r2=49417&view=diff ============================================================================== --- trunk/storage/libstorage/src/SystemCmd.h (original) +++ trunk/storage/libstorage/src/SystemCmd.h Fri Jul 25 15:21:32 2008 @@ -58,8 +58,16 @@ int getStderr( std::list<string> &Ret_Cr, const bool Append_bv = false ) const { return placeOutput( IDX_STDERR, Ret_Cr, Append_bv); } + /** + * Quotes and protects a single string for shell execution. + */ static string quote(const string& str); + /** + * Quotes and protects every single string in the list for shell execution. + */ + static string quote(const std::list<string>& strs); + protected: int placeOutput( unsigned Which_iv, std::vector<string> &Ret_Cr, const bool Append_bv ) const; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org