Skip to content

Commit

Permalink
Backported CORE-6000: gbak issues "Your user name and password are no…
Browse files Browse the repository at this point in the history
…t defined" when command switch "-fe(tch_password) ..." is specified when run as service
  • Loading branch information
AlexPeshkoff committed Oct 11, 2019
1 parent 2a33ed9 commit 66742f8
Showing 1 changed file with 43 additions and 27 deletions.
70 changes: 43 additions & 27 deletions src/burp/burp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ static gbak_action open_files(const TEXT *, const TEXT**, USHORT,
static int svc_api_gbak(Firebird::UtilSvc*, const Switches& switches);
static void burp_usage(const Switches& switches);
static Switches::in_sw_tab_t* findSwitchOrThrow(Firebird::UtilSvc*, Switches& switches, Firebird::string& sw);
static void processFetchPass(const SCHAR*& password, int& itr, const int argc, Firebird::UtilSvc::ArgvType& argv);


// fil.fil_length is FB_UINT64
const ULONG KBYTE = 1024;
Expand Down Expand Up @@ -179,6 +181,7 @@ static int svc_api_gbak(Firebird::UtilSvc* uSvc, const Switches& switches)
*
**********************************************/
Firebird::string usr, pswd, service;
const SCHAR* pswd2 = NULL;
bool flag_restore = false;
bool flag_verbose = false;
#ifdef TRUSTED_AUTH
Expand Down Expand Up @@ -232,6 +235,7 @@ static int svc_api_gbak(Firebird::UtilSvc* uSvc, const Switches& switches)
break;
case IN_SW_BURP_PASS: // default password
pswd = argv[itr];
pswd2 = pswd.nullStr();
uSvc->hidePasswd(argv, itr);
break;
case IN_SW_BURP_SE: // service name
Expand All @@ -241,6 +245,12 @@ static int svc_api_gbak(Firebird::UtilSvc* uSvc, const Switches& switches)
argv[itr] = 0;
}
break;
case IN_SW_BURP_FETCHPASS:
argv[itr] = 0;
processFetchPass(pswd2, itr, argc, argv);
pswd = pswd2;
argv[itr] = 0;
break;
case IN_SW_BURP_V: // verify actions
if (flag_verbint)
BURP_error(329, true); // verify (verbose) and verbint options are mutually exclusive
Expand Down Expand Up @@ -671,33 +681,7 @@ int gbak(Firebird::UtilSvc* uSvc)
tdgbl->gbl_sw_password = argv[itr];
break;
case IN_SW_BURP_FETCHPASS:
if (++itr >= argc)
{
BURP_error(189, true);
// password parameter missing
}
if (tdgbl->gbl_sw_password)
{
BURP_error(307, true);
// too many passwords provided
}
switch (fb_utils::fetchPassword(argv[itr], tdgbl->gbl_sw_password))
{
case fb_utils::FETCH_PASS_OK:
break;
case fb_utils::FETCH_PASS_FILE_OPEN_ERROR:
BURP_error(308, true, MsgFormat::SafeArg() << argv[itr] << errno);
// error @2 opening password file @1
break;
case fb_utils::FETCH_PASS_FILE_READ_ERROR:
BURP_error(309, true, MsgFormat::SafeArg() << argv[itr] << errno);
// error @2 reading password file @1
break;
case fb_utils::FETCH_PASS_FILE_EMPTY:
BURP_error(310, true, MsgFormat::SafeArg() << argv[itr]);
// password file @1 is empty
break;
}
processFetchPass(tdgbl->gbl_sw_password, itr, argc, argv);
break;
case IN_SW_BURP_USER:
if (++itr >= argc)
Expand Down Expand Up @@ -2601,3 +2585,35 @@ UnicodeCollationHolder::~UnicodeCollationHolder()
// cs should be deleted by texttype_fn_destroy call above
delete tt;
}

static void processFetchPass(const SCHAR*& password, int& itr, const int argc, Firebird::UtilSvc::ArgvType& argv)
{
if (++itr >= argc)
{
BURP_error(189, true);
// password parameter missing
}
if (password)
{
BURP_error(307, true);
// too many passwords provided
}

switch (fb_utils::fetchPassword(argv[itr], password))
{
case fb_utils::FETCH_PASS_OK:
break;
case fb_utils::FETCH_PASS_FILE_OPEN_ERROR:
BURP_error(308, true, MsgFormat::SafeArg() << argv[itr] << errno);
// error @2 opening password file @1
break;
case fb_utils::FETCH_PASS_FILE_READ_ERROR:
BURP_error(309, true, MsgFormat::SafeArg() << argv[itr] << errno);
// error @2 reading password file @1
break;
case fb_utils::FETCH_PASS_FILE_EMPTY:
BURP_error(310, true, MsgFormat::SafeArg() << argv[itr]);
// password file @1 is empty
break;
}
}

0 comments on commit 66742f8

Please sign in to comment.