This commit is contained in:
Earnestly 2026-02-17 03:05:56 +08:00 committed by GitHub
commit eda6eeb1d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 67 additions and 2 deletions

View file

@ -120,6 +120,15 @@ static bool StringToUInt32(const wchar_t *s, UInt32 &v)
return *end == 0; return *end == 0;
} }
static bool StringToInt32(const wchar_t *s, Int32 &v)
{
if (*s == 0)
return false;
const wchar_t *end;
v = ConvertStringToInt32(s, &end);
return *end == 0;
}
namespace NKey { namespace NKey {
enum Enum enum Enum
@ -209,6 +218,7 @@ enum Enum
#ifndef Z7_NO_CRYPTO #ifndef Z7_NO_CRYPTO
, kPassword , kPassword
, kPasswordFd
#endif #endif
}; };
@ -360,6 +370,7 @@ static const CSwitchForm kSwitchForms[] =
#ifndef Z7_NO_CRYPTO #ifndef Z7_NO_CRYPTO
, { "p", SWFRM_STRING } , { "p", SWFRM_STRING }
, { "pfd", SWFRM_STRING }
#endif #endif
}; };
@ -1460,6 +1471,22 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options)
options.PasswordEnabled = parser[NKey::kPassword].ThereIs; options.PasswordEnabled = parser[NKey::kPassword].ThereIs;
if (options.PasswordEnabled) if (options.PasswordEnabled)
options.Password = parser[NKey::kPassword].PostStrings[0]; options.Password = parser[NKey::kPassword].PostStrings[0];
options.PasswordFd = 0;
if (parser[NKey::kPasswordFd].ThereIs)
{
const UString &s = parser[NKey::kPasswordFd].PostStrings[0];
if (s.IsEmpty())
throw CArcCmdLineException("No file descriptor given to -pfd", s);
else
{
Int32 v;
if (!StringToInt32(s, v))
throw CArcCmdLineException("A file descriptor is required for -pfd", s);
options.PasswordFd = (int)v;
}
}
#endif #endif
options.ShowDialog = parser[NKey::kShowDialog].ThereIs; options.ShowDialog = parser[NKey::kShowDialog].ThereIs;

View file

@ -89,6 +89,7 @@ struct CArcCmdLineOptions
#ifndef Z7_NO_CRYPTO #ifndef Z7_NO_CRYPTO
bool PasswordEnabled; bool PasswordEnabled;
UString Password; UString Password;
int PasswordFd;
#endif #endif
UStringVector HashMethods; UStringVector HashMethods;

View file

@ -1081,7 +1081,7 @@ HRESULT ListArchives(
const NWildcard::CCensorNode &wildcardCensor, const NWildcard::CCensorNode &wildcardCensor,
bool enableHeaders, bool techMode, bool enableHeaders, bool techMode,
#ifndef Z7_NO_CRYPTO #ifndef Z7_NO_CRYPTO
bool &passwordEnabled, UString &password, bool &passwordEnabled, UString &password, int &passwordFd,
#endif #endif
#ifndef Z7_SFX #ifndef Z7_SFX
const CObjectVector<CProperty> *props, const CObjectVector<CProperty> *props,
@ -1161,6 +1161,7 @@ HRESULT ListArchives(
openCallback.PasswordIsDefined = passwordEnabled; openCallback.PasswordIsDefined = passwordEnabled;
openCallback.Password = password; openCallback.Password = password;
openCallback.PasswordFd = passwordFd;
#endif #endif

View file

@ -31,7 +31,7 @@ HRESULT ListArchives(
const NWildcard::CCensorNode &wildcardCensor, const NWildcard::CCensorNode &wildcardCensor,
bool enableHeaders, bool techMode, bool enableHeaders, bool techMode,
#ifndef Z7_NO_CRYPTO #ifndef Z7_NO_CRYPTO
bool &passwordEnabled, UString &password, bool &passwordEnabled, UString &password, int &passwordFd,
#endif #endif
#ifndef Z7_SFX #ifndef Z7_SFX
const CObjectVector<CProperty> *props, const CObjectVector<CProperty> *props,

View file

@ -163,6 +163,7 @@ static const char * const kHelpString =
" -o{Directory} : set Output directory\n" " -o{Directory} : set Output directory\n"
#ifndef Z7_NO_CRYPTO #ifndef Z7_NO_CRYPTO
" -p{Password} : set Password\n" " -p{Password} : set Password\n"
" -pfd{N} : read Password from fd\n"
#endif #endif
" -r[-|0] : Recurse subdirectories for name search\n" " -r[-|0] : Recurse subdirectories for name search\n"
" -sa{a|e|s} : set Archive name mode\n" " -sa{a|e|s} : set Archive name mode\n"
@ -1333,6 +1334,7 @@ int Main2(
#ifndef Z7_NO_CRYPTO #ifndef Z7_NO_CRYPTO
ecs->PasswordIsDefined = options.PasswordEnabled; ecs->PasswordIsDefined = options.PasswordEnabled;
ecs->Password = options.Password; ecs->Password = options.Password;
ecs->PasswordFd = options.PasswordFd;
#endif #endif
ecs->Init(g_StdStream, g_ErrStream, percentsStream, options.DisablePercents); ecs->Init(g_StdStream, g_ErrStream, percentsStream, options.DisablePercents);
@ -1517,6 +1519,7 @@ int Main2(
#ifndef Z7_NO_CRYPTO #ifndef Z7_NO_CRYPTO
options.PasswordEnabled, options.PasswordEnabled,
options.Password, options.Password,
options.PasswordFd,
#endif #endif
&options.Properties, &options.Properties,
numErrors, numWarnings); numErrors, numWarnings);
@ -1551,6 +1554,7 @@ int Main2(
(options.PasswordEnabled && !options.Password.IsEmpty()); (options.PasswordEnabled && !options.Password.IsEmpty());
openCallback.PasswordIsDefined = passwordIsDefined; openCallback.PasswordIsDefined = passwordIsDefined;
openCallback.Password = options.Password; openCallback.Password = options.Password;
openCallback.PasswordFd = options.PasswordFd;
#endif #endif
CUpdateCallbackConsole callback; CUpdateCallbackConsole callback;
@ -1564,6 +1568,7 @@ int Main2(
callback.PasswordIsDefined = passwordIsDefined; callback.PasswordIsDefined = passwordIsDefined;
callback.AskPassword = (options.PasswordEnabled && options.Password.IsEmpty()); callback.AskPassword = (options.PasswordEnabled && options.Password.IsEmpty());
callback.Password = options.Password; callback.Password = options.Password;
callback.PasswordFd = options.PasswordFd;
#endif #endif
callback.StdOutMode = uo.StdOutMode; callback.StdOutMode = uo.StdOutMode;

View file

@ -87,6 +87,15 @@ HRESULT COpenCallbackConsole::Open_CryptoGetTextPassword(BSTR *password)
if (!PasswordIsDefined) if (!PasswordIsDefined)
{ {
ClosePercents(); ClosePercents();
if (PasswordFd) {
FILE *_file = fdopen(PasswordFd, "r");
if (!_file)
return S_FALSE;
g_StdIn = CStdInStream(_file);
}
RINOK(GetPassword_HRESULT(_so, Password)) RINOK(GetPassword_HRESULT(_so, Password))
PasswordIsDefined = true; PasswordIsDefined = true;
} }

View file

@ -67,6 +67,7 @@ public:
bool PasswordIsDefined; bool PasswordIsDefined;
// bool PasswordWasAsked; // bool PasswordWasAsked;
UString Password; UString Password;
int PasswordFd;
#endif #endif
}; };

View file

@ -828,6 +828,16 @@ HRESULT CUpdateCallbackConsole::CryptoGetTextPassword2(Int32 *passwordIsDefined,
if (!PasswordIsDefined) if (!PasswordIsDefined)
{ {
if (PasswordFd) {
FILE *_file = fdopen(PasswordFd, "r");
if (!_file)
return S_FALSE;
g_StdIn = CStdInStream(_file);
}
if (AskPassword) if (AskPassword)
{ {
RINOK(GetPassword_HRESULT(_so, Password)) RINOK(GetPassword_HRESULT(_so, Password))
@ -857,6 +867,15 @@ HRESULT CUpdateCallbackConsole::CryptoGetTextPassword(BSTR *password)
if (!PasswordIsDefined) if (!PasswordIsDefined)
{ {
{ {
if (PasswordFd) {
FILE *_file = fdopen(PasswordFd, "r");
if (!_file)
return S_FALSE;
g_StdIn = CStdInStream(_file);
}
RINOK(GetPassword_HRESULT(_so, Password)) RINOK(GetPassword_HRESULT(_so, Password))
PasswordIsDefined = true; PasswordIsDefined = true;
} }

View file

@ -122,6 +122,7 @@ public:
bool PasswordIsDefined; bool PasswordIsDefined;
bool AskPassword; bool AskPassword;
UString Password; UString Password;
int PasswordFd;
#endif #endif
CUpdateCallbackConsole(): CUpdateCallbackConsole():

View file

@ -3,6 +3,7 @@
#ifndef ZIP7_INC_USER_INPUT_UTILS_H #ifndef ZIP7_INC_USER_INPUT_UTILS_H
#define ZIP7_INC_USER_INPUT_UTILS_H #define ZIP7_INC_USER_INPUT_UTILS_H
#include "../../../Common/StdInStream.h"
#include "../../../Common/StdOutStream.h" #include "../../../Common/StdOutStream.h"
namespace NUserAnswerMode { namespace NUserAnswerMode {