mirror of https://github.com/aria2/aria2
Erase user and password specified in command-line from argv.
The user and password is masked with '*'.pull/1/head
parent
211c4ea9f4
commit
2c0476e6d9
|
@ -54,7 +54,8 @@ NameMatchOptionHandler::NameMatchOptionHandler
|
||||||
id_(0),
|
id_(0),
|
||||||
argType_(argType),
|
argType_(argType),
|
||||||
shortName_(shortName),
|
shortName_(shortName),
|
||||||
hidden_(false)
|
hidden_(false),
|
||||||
|
eraseAfterParse_(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
NameMatchOptionHandler::~NameMatchOptionHandler() {}
|
NameMatchOptionHandler::~NameMatchOptionHandler() {}
|
||||||
|
|
|
@ -63,6 +63,8 @@ protected:
|
||||||
|
|
||||||
bool hidden_;
|
bool hidden_;
|
||||||
|
|
||||||
|
bool eraseAfterParse_;
|
||||||
|
|
||||||
virtual void parseArg(Option& option, const std::string& arg) = 0;
|
virtual void parseArg(Option& option, const std::string& arg) = 0;
|
||||||
public:
|
public:
|
||||||
NameMatchOptionHandler(const std::string& optName,
|
NameMatchOptionHandler(const std::string& optName,
|
||||||
|
@ -127,6 +129,16 @@ public:
|
||||||
{
|
{
|
||||||
return argType_;
|
return argType_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual bool getEraseAfterParse() const
|
||||||
|
{
|
||||||
|
return eraseAfterParse_;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void setEraseAfterParse(bool eraseAfterParse)
|
||||||
|
{
|
||||||
|
eraseAfterParse_ = eraseAfterParse;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<NameMatchOptionHandler> NameMatchOptionHandlerHandle;
|
typedef SharedHandle<NameMatchOptionHandler> NameMatchOptionHandlerHandle;
|
||||||
|
|
|
@ -94,6 +94,12 @@ public:
|
||||||
virtual int getOptionID() const = 0;
|
virtual int getOptionID() const = 0;
|
||||||
|
|
||||||
virtual void setOptionID(int id) = 0;
|
virtual void setOptionID(int id) = 0;
|
||||||
|
|
||||||
|
// Returns true if option value should be erased from argv to
|
||||||
|
// prevent it from appearing in the output of ps.
|
||||||
|
virtual bool getEraseAfterParse() const = 0;
|
||||||
|
|
||||||
|
virtual void setEraseAfterParse(bool eraseAfterParse) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class OptionHandlerNameLesser:public std::binary_function
|
class OptionHandlerNameLesser:public std::binary_function
|
||||||
|
|
|
@ -619,6 +619,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
||||||
(PREF_RPC_USER,
|
(PREF_RPC_USER,
|
||||||
TEXT_RPC_USER));
|
TEXT_RPC_USER));
|
||||||
op->addTag(TAG_RPC);
|
op->addTag(TAG_RPC);
|
||||||
|
op->setEraseAfterParse(true);
|
||||||
handlers.push_back(op);
|
handlers.push_back(op);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -626,6 +627,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
||||||
(PREF_RPC_PASSWD,
|
(PREF_RPC_PASSWD,
|
||||||
TEXT_RPC_PASSWD));
|
TEXT_RPC_PASSWD));
|
||||||
op->addTag(TAG_RPC);
|
op->addTag(TAG_RPC);
|
||||||
|
op->setEraseAfterParse(true);
|
||||||
handlers.push_back(op);
|
handlers.push_back(op);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -676,6 +678,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
||||||
TEXT_XML_RPC_USER)),
|
TEXT_XML_RPC_USER)),
|
||||||
PREF_RPC_USER));
|
PREF_RPC_USER));
|
||||||
op->addTag(TAG_RPC);
|
op->addTag(TAG_RPC);
|
||||||
|
op->setEraseAfterParse(true);
|
||||||
handlers.push_back(op);
|
handlers.push_back(op);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -687,6 +690,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
||||||
TEXT_XML_RPC_PASSWD)),
|
TEXT_XML_RPC_PASSWD)),
|
||||||
PREF_RPC_PASSWD));
|
PREF_RPC_PASSWD));
|
||||||
op->addTag(TAG_RPC);
|
op->addTag(TAG_RPC);
|
||||||
|
op->setEraseAfterParse(true);
|
||||||
handlers.push_back(op);
|
handlers.push_back(op);
|
||||||
}
|
}
|
||||||
// HTTP/FTP options
|
// HTTP/FTP options
|
||||||
|
@ -971,6 +975,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
||||||
TEXT_HTTP_PASSWD));
|
TEXT_HTTP_PASSWD));
|
||||||
op->addTag(TAG_BASIC);
|
op->addTag(TAG_BASIC);
|
||||||
op->addTag(TAG_HTTP);
|
op->addTag(TAG_HTTP);
|
||||||
|
op->setEraseAfterParse(true);
|
||||||
handlers.push_back(op);
|
handlers.push_back(op);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -979,6 +984,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
||||||
TEXT_HTTP_USER));
|
TEXT_HTTP_USER));
|
||||||
op->addTag(TAG_BASIC);
|
op->addTag(TAG_BASIC);
|
||||||
op->addTag(TAG_HTTP);
|
op->addTag(TAG_HTTP);
|
||||||
|
op->setEraseAfterParse(true);
|
||||||
handlers.push_back(op);
|
handlers.push_back(op);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -1055,6 +1061,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
||||||
TEXT_FTP_PASSWD));
|
TEXT_FTP_PASSWD));
|
||||||
op->addTag(TAG_BASIC);
|
op->addTag(TAG_BASIC);
|
||||||
op->addTag(TAG_FTP);
|
op->addTag(TAG_FTP);
|
||||||
|
op->setEraseAfterParse(true);
|
||||||
handlers.push_back(op);
|
handlers.push_back(op);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -1091,6 +1098,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
||||||
TEXT_FTP_USER));
|
TEXT_FTP_USER));
|
||||||
op->addTag(TAG_BASIC);
|
op->addTag(TAG_BASIC);
|
||||||
op->addTag(TAG_FTP);
|
op->addTag(TAG_FTP);
|
||||||
|
op->setEraseAfterParse(true);
|
||||||
handlers.push_back(op);
|
handlers.push_back(op);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -1117,6 +1125,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
||||||
TEXT_HTTP_PROXY_PASSWD,
|
TEXT_HTTP_PROXY_PASSWD,
|
||||||
NO_DEFAULT_VALUE));
|
NO_DEFAULT_VALUE));
|
||||||
op->addTag(TAG_HTTP);
|
op->addTag(TAG_HTTP);
|
||||||
|
op->setEraseAfterParse(true);
|
||||||
handlers.push_back(op);
|
handlers.push_back(op);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -1125,6 +1134,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
||||||
TEXT_HTTP_PROXY_USER,
|
TEXT_HTTP_PROXY_USER,
|
||||||
NO_DEFAULT_VALUE));
|
NO_DEFAULT_VALUE));
|
||||||
op->addTag(TAG_HTTP);
|
op->addTag(TAG_HTTP);
|
||||||
|
op->setEraseAfterParse(true);
|
||||||
handlers.push_back(op);
|
handlers.push_back(op);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -1143,6 +1153,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
||||||
NO_DEFAULT_VALUE));
|
NO_DEFAULT_VALUE));
|
||||||
op->addTag(TAG_HTTP);
|
op->addTag(TAG_HTTP);
|
||||||
op->addTag(TAG_HTTPS);
|
op->addTag(TAG_HTTPS);
|
||||||
|
op->setEraseAfterParse(true);
|
||||||
handlers.push_back(op);
|
handlers.push_back(op);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -1152,6 +1163,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
||||||
NO_DEFAULT_VALUE));
|
NO_DEFAULT_VALUE));
|
||||||
op->addTag(TAG_HTTP);
|
op->addTag(TAG_HTTP);
|
||||||
op->addTag(TAG_HTTPS);
|
op->addTag(TAG_HTTPS);
|
||||||
|
op->setEraseAfterParse(true);
|
||||||
handlers.push_back(op);
|
handlers.push_back(op);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -1168,6 +1180,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
||||||
TEXT_FTP_PROXY_PASSWD,
|
TEXT_FTP_PROXY_PASSWD,
|
||||||
NO_DEFAULT_VALUE));
|
NO_DEFAULT_VALUE));
|
||||||
op->addTag(TAG_FTP);
|
op->addTag(TAG_FTP);
|
||||||
|
op->setEraseAfterParse(true);
|
||||||
handlers.push_back(op);
|
handlers.push_back(op);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -1176,6 +1189,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
||||||
TEXT_FTP_PROXY_USER,
|
TEXT_FTP_PROXY_USER,
|
||||||
NO_DEFAULT_VALUE));
|
NO_DEFAULT_VALUE));
|
||||||
op->addTag(TAG_FTP);
|
op->addTag(TAG_FTP);
|
||||||
|
op->setEraseAfterParse(true);
|
||||||
handlers.push_back(op);
|
handlers.push_back(op);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -1196,6 +1210,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
||||||
op->addTag(TAG_FTP);
|
op->addTag(TAG_FTP);
|
||||||
op->addTag(TAG_HTTP);
|
op->addTag(TAG_HTTP);
|
||||||
op->addTag(TAG_HTTPS);
|
op->addTag(TAG_HTTPS);
|
||||||
|
op->setEraseAfterParse(true);
|
||||||
handlers.push_back(op);
|
handlers.push_back(op);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -1206,6 +1221,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
||||||
op->addTag(TAG_FTP);
|
op->addTag(TAG_FTP);
|
||||||
op->addTag(TAG_HTTP);
|
op->addTag(TAG_HTTP);
|
||||||
op->addTag(TAG_HTTPS);
|
op->addTag(TAG_HTTPS);
|
||||||
|
op->setEraseAfterParse(true);
|
||||||
handlers.push_back(op);
|
handlers.push_back(op);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
|
|
@ -115,6 +115,13 @@ char NullOptionHandler::getShortName() const
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NullOptionHandler::getEraseAfterParse() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NullOptionHandler::setEraseAfterParse(bool eraseAfterParse) {}
|
||||||
|
|
||||||
BooleanOptionHandler::BooleanOptionHandler
|
BooleanOptionHandler::BooleanOptionHandler
|
||||||
(const std::string& optName,
|
(const std::string& optName,
|
||||||
const std::string& description,
|
const std::string& description,
|
||||||
|
@ -814,4 +821,14 @@ void DeprecatedOptionHandler::setOptionID(int id)
|
||||||
depOptHandler_->setOptionID(id);
|
depOptHandler_->setOptionID(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DeprecatedOptionHandler::getEraseAfterParse() const
|
||||||
|
{
|
||||||
|
return depOptHandler_->getEraseAfterParse();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeprecatedOptionHandler::setEraseAfterParse(bool eraseAfterParse)
|
||||||
|
{
|
||||||
|
depOptHandler_->setEraseAfterParse(eraseAfterParse);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -65,6 +65,8 @@ public:
|
||||||
virtual int getOptionID() const;
|
virtual int getOptionID() const;
|
||||||
virtual void setOptionID(int id);
|
virtual void setOptionID(int id);
|
||||||
virtual char getShortName() const;
|
virtual char getShortName() const;
|
||||||
|
virtual bool getEraseAfterParse() const;
|
||||||
|
virtual void setEraseAfterParse(bool eraseAfterParse);
|
||||||
};
|
};
|
||||||
|
|
||||||
class BooleanOptionHandler : public NameMatchOptionHandler {
|
class BooleanOptionHandler : public NameMatchOptionHandler {
|
||||||
|
@ -315,6 +317,8 @@ public:
|
||||||
virtual char getShortName() const;
|
virtual char getShortName() const;
|
||||||
virtual int getOptionID() const;
|
virtual int getOptionID() const;
|
||||||
virtual void setOptionID(int id);
|
virtual void setOptionID(int id);
|
||||||
|
virtual bool getEraseAfterParse() const;
|
||||||
|
virtual void setEraseAfterParse(bool eraseAfterParse);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -138,7 +138,7 @@ std::string createOptstring(InputIterator first, InputIterator last)
|
||||||
|
|
||||||
void OptionParser::parseArg
|
void OptionParser::parseArg
|
||||||
(std::ostream& out, std::vector<std::string>& nonopts,
|
(std::ostream& out, std::vector<std::string>& nonopts,
|
||||||
int argc, char* const argv[])
|
int argc, char* argv[])
|
||||||
{
|
{
|
||||||
size_t numPublicOption = countPublicOption(optionHandlers_.begin(),
|
size_t numPublicOption = countPublicOption(optionHandlers_.begin(),
|
||||||
optionHandlers_.end());
|
optionHandlers_.end());
|
||||||
|
@ -165,6 +165,11 @@ void OptionParser::parseArg
|
||||||
out << op->getName() << "=";
|
out << op->getName() << "=";
|
||||||
if(optarg) {
|
if(optarg) {
|
||||||
out << optarg;
|
out << optarg;
|
||||||
|
if(op->getEraseAfterParse()) {
|
||||||
|
for(char* p = optarg; *p != '\0'; ++p) {
|
||||||
|
*p = '*';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
out << "\n";
|
out << "\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ public:
|
||||||
// NAME=VALUE format. Non-option strings are stored in nonopts.
|
// NAME=VALUE format. Non-option strings are stored in nonopts.
|
||||||
// Throws Exception when an unrecognized option is found.
|
// Throws Exception when an unrecognized option is found.
|
||||||
void parseArg(std::ostream& out, std::vector<std::string>& nonopts,
|
void parseArg(std::ostream& out, std::vector<std::string>& nonopts,
|
||||||
int argc, char* const argv[]);
|
int argc, char* argv[]);
|
||||||
|
|
||||||
void parse(Option& option, std::istream& ios);
|
void parse(Option& option, std::istream& ios);
|
||||||
|
|
||||||
|
|
|
@ -174,7 +174,7 @@ void showFiles
|
||||||
#endif // ENABLE_BITTORRENT || ENABLE_METALINK
|
#endif // ENABLE_BITTORRENT || ENABLE_METALINK
|
||||||
|
|
||||||
extern void option_processing(Option& option, std::vector<std::string>& uris,
|
extern void option_processing(Option& option, std::vector<std::string>& uris,
|
||||||
int argc, char* const argv[]);
|
int argc, char* argv[]);
|
||||||
|
|
||||||
error_code::Value main(int argc, char* argv[])
|
error_code::Value main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
|
|
@ -85,7 +85,7 @@ void overrideWithEnv(Option& op, const OptionParser& optionParser,
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void option_processing(Option& op, std::vector<std::string>& uris,
|
void option_processing(Option& op, std::vector<std::string>& uris,
|
||||||
int argc, char* const argv[])
|
int argc, char* argv[])
|
||||||
{
|
{
|
||||||
OptionParser oparser;
|
OptionParser oparser;
|
||||||
oparser.setOptionHandlers(OptionHandlerFactory::createOptionHandlers());
|
oparser.setOptionHandlers(OptionHandlerFactory::createOptionHandlers());
|
||||||
|
|
Loading…
Reference in New Issue