# BAREOS - Backup Archiving REcovery Open Sourced## Copyright (C) 2015-2020 Bareos GmbH & Co. KG## This program is Free Software; you can redistribute it and/or# modify it under the terms of version three of the GNU Affero General Public# License as published by the Free Software Foundation and included# in the file LICENSE.## This program is distributed in the hope that it will be useful, but# WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU# Affero General Public License for more details.## You should have received a copy of the GNU Affero General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA# 02110-1301, USA."""Protocol messages between bareos-director and user-agent."""frombareosimport__version__frombareos.bsock.connectiontypeimportConnectionTypefrombareos.bsock.constantsimportConstantsfrombareos.bsock.protocolmessageidsimportProtocolMessageIdsfrombareos.bsock.protocolversionsimportProtocolVersions
[docs]classProtocolMessages:""" strings defined by the protocol to talk to the Bareos Director. """def__init__(self,protocolversion=ProtocolVersions.last):self.set_version(protocolversion)defset_version(self,protocolversion):self.protocolversion=protocolversiondefget_version(self):returnself.protocolversiondefhello(self,name,type=ConnectionType.DIRECTOR):iftype==ConnectionType.FILEDAEMON:returnbytearray("Hello Director %s calling\n"%(name),"utf-8")else:ifself.protocolversion<ProtocolVersions.bareos_18_2:returnbytearray("Hello %s calling\n"%(name),"utf-8")else:returnbytearray("Hello %s calling version %s\n"%(name,__version__),"utf-8")# @staticmethod# def ok():# return "1000 OK:"@staticmethoddefauth_ok():returnb"1000 OK auth\n"@staticmethoddefauth_failed():returnb"1999 Authorization failed.\n"@staticmethoddefnot_authorized():returnb"1999 You are not authorized.\n"@staticmethoddefis_auth_ok(msg):returnmsg==ProtocolMessages.auth_ok()@staticmethoddefis_not_authorized(msg):returnmsg==ProtocolMessages.not_authorized()
[docs]@staticmethoddefpam_user_credentials(pam_username,pam_password):""" Returns a string similar to: 4002 USERNAME PASSWORD """returnbytearray("{id}{s}{username}{s}{password}".format(id=ProtocolMessageIds.PamUserCredentials,username=pam_username,password=pam_password,s=Constants.record_separator,),"utf-8",)