Skip to content

Commit

Permalink
console: repaired some of the conditional pam compilation for builts …
Browse files Browse the repository at this point in the history
…witout pam
  • Loading branch information
franku committed Oct 29, 2018
1 parent b10ed6c commit da6037c
Showing 1 changed file with 36 additions and 30 deletions.
66 changes: 36 additions & 30 deletions core/src/console/console.cc
Expand Up @@ -62,8 +62,6 @@ static void TerminateConsole(int sig);
static int CheckResources();
int GetCmd(FILE *input, const char *prompt, BareosSocket *sock, int sec);
static int DoOutputcmd(FILE *input, BareosSocket *UA_sock);
static bool ExaminePamAuthentication(bool use_pam_credentials_file,
const std::string &pam_credentials_filename);

extern "C" void GotSigstop(int sig);
extern "C" void GotSigcontinue(int sig);
Expand Down Expand Up @@ -863,6 +861,35 @@ static bool SelectDirector(const char *director, DirectorResource **ret_dir, Con
return 1;
}

#if defined(HAVE_PAM)
static bool ExaminePamAuthentication(bool use_pam_credentials_file, const std::string &pam_credentials_filename)
{
if (use_pam_credentials_file) {
std::fstream s(pam_credentials_filename, s.in);
if (!s.is_open()) {
Emsg0(M_ERROR_TERM, 0, _("Could not open PAM credentials file.\n"));
return false;
} else {
std::string user, pw;
s >> user >> pw;
if (user.empty() || pw.empty()) {
Emsg0(M_ERROR_TERM, 0, _("Could not read user or password.\n"));
}
BStringList args;
args << user << pw;
FormatAndSendResponseMessage(UA_sock, kMessageIdPamUserCredentials, args);
}
} else {
FormatAndSendResponseMessage(UA_sock, kMessageIdPamInteractive, "OK");
if (!ConsolePamAuthenticate(stdin, UA_sock)) {
TerminateConsole(0);
return false;
}
}
return true;
}
#endif

namespace console {
BareosSocket *ConnectToDirector(JobControlRecord &jcr, utime_t heart_beat, char *errmsg, int errmsg_len, uint32_t &response_id)
{
Expand Down Expand Up @@ -937,7 +964,9 @@ int main(int argc, char *argv[])
PoolMem history_file;
utime_t heart_beat;
std::string pam_credentials_filename;
#if defined(HAVE_PAM)
bool use_pam_credentials_file = false;
#endif

errmsg_len = sizeof(errmsg);
setlocale(LC_ALL, "");
Expand Down Expand Up @@ -984,6 +1013,7 @@ int main(int argc, char *argv[])
break;

case 'p':
#if defined(HAVE_PAM)
pam_credentials_filename = optarg;
if (pam_credentials_filename.empty()) {
Emsg0(M_ERROR_TERM, 0, _("No filename given for -p.\n"));
Expand All @@ -992,10 +1022,13 @@ int main(int argc, char *argv[])
if (FILE *f = fopen(pam_credentials_filename.c_str(), "r+")) {
use_pam_credentials_file = true;
fclose(f);
} else { /* file does not exist */
} else { /* file cannot be opened, i.e. does not exist */
Emsg0(M_ERROR_TERM, 0, _("Could not open file for -p.\n"));
}
}
#else
Emsg0(M_ERROR_TERM, 0, _("No PAM available on this system.\n"));
#endif
break;

case 's': /* turn off signals */
Expand Down Expand Up @@ -1181,33 +1214,6 @@ int main(int argc, char *argv[])
return 0;
}

static bool ExaminePamAuthentication(bool use_pam_credentials_file, const std::string &pam_credentials_filename)
{
if (use_pam_credentials_file) {
std::fstream s(pam_credentials_filename, s.in);
if (!s.is_open()) {
Emsg0(M_ERROR_TERM, 0, _("Could not open PAM credentials file.\n"));
return false;
} else {
std::string user, pw;
s >> user >> pw;
if (user.empty() || pw.empty()) {
Emsg0(M_ERROR_TERM, 0, _("Could not read user or password.\n"));
}
BStringList args;
args << user << pw;
FormatAndSendResponseMessage(UA_sock, kMessageIdPamUserCredentials, args);
}
} else {
FormatAndSendResponseMessage(UA_sock, kMessageIdPamInteractive, "OK");
if (!ConsolePamAuthenticate(stdin, UA_sock)) {
TerminateConsole(0);
return false;
}
}
return true;
}

static void TerminateConsole(int sig)
{
static bool already_here = false;
Expand Down

0 comments on commit da6037c

Please sign in to comment.