Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions CPP/7zip/UI/Common/ArchiveCommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ static bool StringToUInt32(const wchar_t *s, UInt32 &v)
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 {
enum Enum
Expand Down Expand Up @@ -209,6 +218,7 @@ enum Enum

#ifndef Z7_NO_CRYPTO
, kPassword
, kPasswordFd
#endif
};

Expand Down Expand Up @@ -360,6 +370,7 @@ static const CSwitchForm kSwitchForms[] =

#ifndef Z7_NO_CRYPTO
, { "p", SWFRM_STRING }
, { "pfd", SWFRM_STRING }
#endif
};

Expand Down Expand Up @@ -1460,6 +1471,22 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options)
options.PasswordEnabled = parser[NKey::kPassword].ThereIs;
if (options.PasswordEnabled)
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

options.ShowDialog = parser[NKey::kShowDialog].ThereIs;
Expand Down
1 change: 1 addition & 0 deletions CPP/7zip/UI/Common/ArchiveCommandLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ struct CArcCmdLineOptions
#ifndef Z7_NO_CRYPTO
bool PasswordEnabled;
UString Password;
int PasswordFd;
#endif

UStringVector HashMethods;
Expand Down
3 changes: 2 additions & 1 deletion CPP/7zip/UI/Console/List.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ HRESULT ListArchives(
const NWildcard::CCensorNode &wildcardCensor,
bool enableHeaders, bool techMode,
#ifndef Z7_NO_CRYPTO
bool &passwordEnabled, UString &password,
bool &passwordEnabled, UString &password, int &passwordFd,
#endif
#ifndef Z7_SFX
const CObjectVector<CProperty> *props,
Expand Down Expand Up @@ -1161,6 +1161,7 @@ HRESULT ListArchives(

openCallback.PasswordIsDefined = passwordEnabled;
openCallback.Password = password;
openCallback.PasswordFd = passwordFd;

#endif

Expand Down
2 changes: 1 addition & 1 deletion CPP/7zip/UI/Console/List.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ HRESULT ListArchives(
const NWildcard::CCensorNode &wildcardCensor,
bool enableHeaders, bool techMode,
#ifndef Z7_NO_CRYPTO
bool &passwordEnabled, UString &password,
bool &passwordEnabled, UString &password, int &passwordFd,
#endif
#ifndef Z7_SFX
const CObjectVector<CProperty> *props,
Expand Down
5 changes: 5 additions & 0 deletions CPP/7zip/UI/Console/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ static const char * const kHelpString =
" -o{Directory} : set Output directory\n"
#ifndef Z7_NO_CRYPTO
" -p{Password} : set Password\n"
" -pfd{N} : read Password from fd\n"
#endif
" -r[-|0] : Recurse subdirectories for name search\n"
" -sa{a|e|s} : set Archive name mode\n"
Expand Down Expand Up @@ -1333,6 +1334,7 @@ int Main2(
#ifndef Z7_NO_CRYPTO
ecs->PasswordIsDefined = options.PasswordEnabled;
ecs->Password = options.Password;
ecs->PasswordFd = options.PasswordFd;
#endif

ecs->Init(g_StdStream, g_ErrStream, percentsStream, options.DisablePercents);
Expand Down Expand Up @@ -1517,6 +1519,7 @@ int Main2(
#ifndef Z7_NO_CRYPTO
options.PasswordEnabled,
options.Password,
options.PasswordFd,
#endif
&options.Properties,
numErrors, numWarnings);
Expand Down Expand Up @@ -1551,6 +1554,7 @@ int Main2(
(options.PasswordEnabled && !options.Password.IsEmpty());
openCallback.PasswordIsDefined = passwordIsDefined;
openCallback.Password = options.Password;
openCallback.PasswordFd = options.PasswordFd;
#endif

CUpdateCallbackConsole callback;
Expand All @@ -1564,6 +1568,7 @@ int Main2(
callback.PasswordIsDefined = passwordIsDefined;
callback.AskPassword = (options.PasswordEnabled && options.Password.IsEmpty());
callback.Password = options.Password;
callback.PasswordFd = options.PasswordFd;
#endif

callback.StdOutMode = uo.StdOutMode;
Expand Down
9 changes: 9 additions & 0 deletions CPP/7zip/UI/Console/OpenCallbackConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ HRESULT COpenCallbackConsole::Open_CryptoGetTextPassword(BSTR *password)
if (!PasswordIsDefined)
{
ClosePercents();
if (PasswordFd) {
FILE *_file = fdopen(PasswordFd, "r");

if (!_file)
return S_FALSE;

g_StdIn = CStdInStream(_file);
}

RINOK(GetPassword_HRESULT(_so, Password))
PasswordIsDefined = true;
}
Expand Down
1 change: 1 addition & 0 deletions CPP/7zip/UI/Console/OpenCallbackConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class COpenCallbackConsole: public IOpenCallbackUI
bool PasswordIsDefined;
// bool PasswordWasAsked;
UString Password;
int PasswordFd;
#endif
};

Expand Down
19 changes: 19 additions & 0 deletions CPP/7zip/UI/Console/UpdateCallbackConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,16 @@ HRESULT CUpdateCallbackConsole::CryptoGetTextPassword2(Int32 *passwordIsDefined,

if (!PasswordIsDefined)
{
if (PasswordFd) {
FILE *_file = fdopen(PasswordFd, "r");

if (!_file)
return S_FALSE;

g_StdIn = CStdInStream(_file);
}


if (AskPassword)
{
RINOK(GetPassword_HRESULT(_so, Password))
Expand Down Expand Up @@ -857,6 +867,15 @@ HRESULT CUpdateCallbackConsole::CryptoGetTextPassword(BSTR *password)
if (!PasswordIsDefined)
{
{
if (PasswordFd) {
FILE *_file = fdopen(PasswordFd, "r");

if (!_file)
return S_FALSE;

g_StdIn = CStdInStream(_file);
}

RINOK(GetPassword_HRESULT(_so, Password))
PasswordIsDefined = true;
}
Expand Down
1 change: 1 addition & 0 deletions CPP/7zip/UI/Console/UpdateCallbackConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class CUpdateCallbackConsole Z7_final:
bool PasswordIsDefined;
bool AskPassword;
UString Password;
int PasswordFd;
#endif

CUpdateCallbackConsole():
Expand Down
1 change: 1 addition & 0 deletions CPP/7zip/UI/Console/UserInputUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#ifndef ZIP7_INC_USER_INPUT_UTILS_H
#define ZIP7_INC_USER_INPUT_UTILS_H

#include "../../../Common/StdInStream.h"
#include "../../../Common/StdOutStream.h"

namespace NUserAnswerMode {
Expand Down