1 /**
2    BAREOS® - Backup Archiving REcovery Open Sourced
3 
4    Copyright (C) 2019-2019 Bareos GmbH & Co. KG
5 
6    This program is Free Software; you can redistribute it and/or
7    modify it under the terms of version three of the GNU Affero General Public
8    License as published by the Free Software Foundation and included
9    in the file LICENSE.
10 
11    This program is distributed in the hope that it will be useful, but
12    WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14    Affero General Public License for more details.
15 
16    You should have received a copy of the GNU Affero General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19    02110-1301, USA.
20 */
21 
22 #include "filed/evaluate_job_command.h"
23 #include "include/bareos.h"
24 
25 namespace filedaemon {
26 
27 const std::string JobCommand::jobcmd_{
28     "JobId=%d Job=%127s SDid=%u SDtime=%u Authorization=%100s"};
29 const std::string JobCommand::jobcmdssl_{
30     "JobId=%d Job=%127s SDid=%u SDtime=%u Authorization=%100s ssl=%d\n"};
31 
JobCommand(const char * msg)32 JobCommand::JobCommand(const char* msg) : job_{0}, sd_auth_key_{0}
33 {
34   ProtocolVersion protocol = ProtocolVersion::kVersionUndefinded;
35 
36   std::vector<ProtocolVersion> implemented_protocols{
37       ProtocolVersion::kVersionFrom_18_2, ProtocolVersion::KVersionBefore_18_2};
38 
39   for (auto protocol_try : implemented_protocols) {
40     switch (protocol_try) {
41       case ProtocolVersion::kVersionFrom_18_2:
42         if (sscanf(msg, jobcmdssl_.c_str(), &job_id_, job_, &vol_session_id_,
43                    &vol_session_time_, sd_auth_key_, &tls_policy_) == 6) {
44           protocol = protocol_try;
45         }
46         break;
47       case ProtocolVersion::KVersionBefore_18_2:
48         if (sscanf(msg, jobcmd_.c_str(), &job_id_, job_, &vol_session_id_,
49                    &vol_session_time_, sd_auth_key_) == 5) {
50           protocol = protocol_try;
51         }
52         break;
53       default:
54         /* never */
55         break;
56     } /* switch () */
57     if (protocol != ProtocolVersion::kVersionUndefinded) { break; }
58   } /* for ( auto.. */
59   protocol_version_ = protocol;
60 }
61 
EvaluationSuccesful() const62 bool JobCommand::EvaluationSuccesful() const
63 {
64   return protocol_version_ != ProtocolVersion::kVersionUndefinded;
65 }
66 
67 }  // namespace filedaemon
68