{
public:
ConsoleAuthenticate(BSOCK *dir):
- AuthenticateBase(NULL, dir, dtCli, dcCON, dcDIR)
+ AuthenticateBase(NULL, dir, dtCli, dcCON, dcDIR),
+ avoid_getpass(false)
{
}
virtual ~ConsoleAuthenticate() {};
int authenticate_director(DIRRES *director, CONRES *cons);
bool ClientAuthenticate(CONRES *cons, const char *password);
+
+ bool avoid_getpass; // this is for regress testing
};
-int authenticate_director(BSOCK *dir, DIRRES *director, CONRES *cons)
+int authenticate_director(BSOCK *dir, DIRRES *director, CONRES *cons, bool avoid_getpass = false)
{
ConsoleAuthenticate auth(dir);
+ auth.avoid_getpass = avoid_getpass;
return auth.authenticate_director(director, cons);
}
char *data = msg.c_str();
POOL_MEM buf(PM_MESSAGE);
- char *passwd;
char *input;
+ char *passwd;
// the command is encoded as a first char of the message
switch (dir->msg[0]){
break;
case UA_AUTH_INTERACTIVE_HIDDEN:
+#if defined(DEVELOPER)
+ if (!avoid_getpass){
+ // normal pass handling
+#endif
#if defined(HAVE_WIN32)
- sendit(data);
- if (win32_cgets(buf.c_str(), buf.size()) == NULL) {
- buf[0] = 0;
- return 0;
+ sendit(data);
+ if (win32_cgets(buf.c_str(), buf.size()) == NULL) {
+ pm_strcpy(buf, NULL);
+ }
+#else
+ passwd = getpass(data);
+ bstrncpy(buf.c_str(), passwd, buf.size());
+#endif
+#if defined(DEVELOPER)
} else {
- return strlen(buf);
+ sendit(data);
+ input = fgets(buf.c_str(), buf.size(), stdin);
+ if (!input){
+ Dmsg0(1, "Error reading user input!\n");
+ return false;
+ }
+ strip_trailing_junk(buf.c_str());
}
-#else
- passwd = getpass(data);
- bstrncpy(buf.c_str(), passwd, buf.size());
#endif
// now we should get a hidden response at `buf` class, return it to director
dir->fsend("%c%s", UA_AUTH_INTERACTIVE_RESPONSE, buf.c_str());
//extern int rl_catch_signals;
/* Imported functions */
-int authenticate_director(BSOCK *dir, DIRRES *director, CONRES *cons);
+int authenticate_director(BSOCK *dir, DIRRES *director, CONRES *cons, bool avoid_getpass);
/* Forward referenced functions */
static void terminate_console(int sig);
" -s no signals\n"
" -u <nn> set command execution timeout to <nn> seconds\n"
" -t test - read configuration and exit\n"
+#if defined(DEVELOPER)
+" -p regress test - avoid getpass()\n"
+#endif
" -? print this message.\n"
"\n"), 2000, BDEMO, HOST_OS, DISTNAME, DISTVER);
}
if (!next) {
if (do_history) {
add_history(line);
- /* Count the number of lines added, we use it to truncate the history
+ /* Count the number of lines added, we use it to truncate the history
* file correctly
*/
history_lines_added++;
bool no_signals = false;
bool test_config = false;
utime_t heart_beat;
+ bool avoid_getpass = false;
setlocale(LC_ALL, "");
bindtextdomain("bacula", LOCALEDIR);
working_directory = "/tmp";
args = get_pool_memory(PM_FNAME);
- while ((ch = getopt(argc, argv, "D:lc:d:nstu:?C:L")) != -1) {
+ while ((ch = getopt(argc, argv, "D:lc:d:npstu:?C:L")) != -1) {
switch (ch) {
case 'D': /* Director */
if (director) {
timeout = atoi(optarg);
break;
+#if defined(DEVELOPER)
+ case 'p':
+ avoid_getpass = true;
+ break;
+#endif
+
case '?':
default:
usage();
terminate_console(0);
return 1;
}
-
+
if (dir->heartbeat_interval) {
heart_beat = dir->heartbeat_interval;
} else if (cons) {
}
/* If cons==NULL, default console will be used */
- if (!authenticate_director(UA_sock, dir, cons)) {
+ if (!authenticate_director(UA_sock, dir, cons, avoid_getpass)) {
terminate_console(0);
return 1;
}