1 /* 2 BAREOS® - Backup Archiving REcovery Open Sourced 3 4 Copyright (C) 2018-2020 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 #ifndef BAREOS_LIB_BNET_H_ 22 #define BAREOS_LIB_BNET_H_ 23 24 #include "tls.h" 25 26 class dlist; 27 28 int32_t BnetRecv(BareosSocket* bsock); 29 bool BnetSend(BareosSocket* bsock); 30 bool BnetFsend(BareosSocket* bs, const char* fmt, ...); 31 bool BnetSetBufferSize(BareosSocket* bs, uint32_t size, int rw); 32 bool BnetSig(BareosSocket* bs, int sig); 33 bool BnetTlsServer(BareosSocket* bsock, 34 const std::vector<std::string>& verify_list); 35 bool BnetTlsClient(BareosSocket* bsock, 36 bool VerifyPeer, 37 const std::vector<std::string>& verify_list); 38 int BnetGetPeer(BareosSocket* bs, char* buf, socklen_t buflen); 39 BareosSocket* dup_bsock(BareosSocket* bsock); 40 const char* BnetStrerror(BareosSocket* bsock); 41 std::string BnetSignalToString(const BareosSocket*); 42 std::string BnetSignalToString(int signal); 43 std::string BnetSignalToDescription(int signal); 44 int BnetWaitData(BareosSocket* bsock, int sec); 45 int BnetWaitDataIntr(BareosSocket* bsock, int sec); 46 bool IsBnetStop(BareosSocket* bsock); 47 int IsBnetError(BareosSocket* bsock); 48 void BnetSuppressErrorMessages(BareosSocket* bsock, bool flag); 49 dlist* BnetHost2IpAddrs(const char* host, int family, const char** errstr); 50 int BnetSetBlocking(BareosSocket* sock); 51 int BnetSetNonblocking(BareosSocket* sock); 52 void BnetRestoreBlocking(BareosSocket* sock, int flags); 53 int NetConnect(int port); 54 BareosSocket* BnetBind(int port); 55 BareosSocket* BnetAccept(BareosSocket* bsock, char* who); 56 57 enum : uint32_t 58 { 59 kMessageIdUnknown = 0, 60 kMessageIdProtokollError = 1, 61 kMessageIdReceiveError = 2, 62 kMessageIdOk = 1000, 63 kMessageIdPamRequired = 1001, 64 kMessageIdInfoMessage = 1002, 65 kMessageIdPamInteractive = 4001, 66 kMessageIdPamUserCredentials = 4002 67 }; 68 69 class BStringList; 70 71 #ifdef BAREOS_TEST_LIB 72 bool ReadoutCommandIdFromMessage(const BStringList& list_of_arguments, 73 uint32_t& id_out); 74 bool EvaluateResponseMessageId(const std::string& message, 75 uint32_t& id_out, 76 BStringList& args_out); 77 #endif 78 79 bool ReceiveAndEvaluateResponseMessage(BareosSocket* bsock, 80 uint32_t& id_out, 81 BStringList& args_out); 82 bool FormatAndSendResponseMessage(BareosSocket* bsock, 83 uint32_t id, 84 const std::string& str); 85 bool FormatAndSendResponseMessage(BareosSocket* bsock, 86 uint32_t id, 87 const BStringList& list_of_agruments); 88 89 #endif // BAREOS_LIB_BNET_H_ 90