python-bareos 23.0.1__py3-none-any.whl → 23.0.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
bareos/VERSION.txt CHANGED
@@ -1 +1 @@
1
- 23.0.1
1
+ 23.0.4
bareos/bsock/__init__.py CHANGED
@@ -1,6 +1,6 @@
1
1
  # BAREOS - Backup Archiving REcovery Open Sourced
2
2
  #
3
- # Copyright (C) 2016-2020 Bareos GmbH & Co. KG
3
+ # Copyright (C) 2016-2024 Bareos GmbH & Co. KG
4
4
  #
5
5
  # This program is Free Software; you can redistribute it and/or
6
6
  # modify it under the terms of version three of the GNU Affero General Public
@@ -17,17 +17,18 @@
17
17
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
18
  # 02110-1301, USA.
19
19
 
20
- """Module to access a http://www.bareos.org backup system.
20
+ """Module to access a https://www.bareos.com backup system.
21
21
 
22
22
  .. note::
23
23
 
24
- By default, the Bareos Director (>= 18.2.4) uses TLS-PSK when communicating through the network.
24
+ By default, the Bareos Director (>= 18.2.4)
25
+ uses TLS-PSK when communicating through the network.
25
26
 
26
- Unfortunately the Python core module ``ssl``
27
- does not support TLS-PSK.
28
- For testing this module should be used without TLS.
27
+ The Python (https://github.com/python/cpython) core module ``ssl``
28
+ does support TLS-PSK only since Python >= 3.13.
29
29
  The section `Transport Encryption (TLS-PSK)`_ describes
30
30
  how to use TLS-PSK and about the limitations.
31
+ For testing this module can also be used without TLS.
31
32
 
32
33
 
33
34
  Preparations
@@ -44,7 +45,7 @@ Create some named consoles for testing:
44
45
 
45
46
  This creates a console user with name `user1` and the profile `operator`.
46
47
  The `operator` profile is a default profile that comes with the Bareos Director.
47
- It does allow most commands. It only deny some dangerous commands (see ``show profile=operator``),
48
+ It does allow most commands, but deny some dangerous commands (see ``show profile=operator``),
48
49
  so it is well suited for this purpose.
49
50
  Futhermore, TLS enforcement is disabled for this console user.
50
51
 
@@ -119,6 +120,7 @@ Example:
119
120
  Full
120
121
  Differential
121
122
 
123
+
122
124
  The results the the `call` method is a ``dict`` object.
123
125
 
124
126
  In case of an error, an exception, derived from :py:class:`bareos.exceptions.Error` is raised.
@@ -142,22 +144,25 @@ Transport Encryption (TLS-PSK)
142
144
 
143
145
  Since Bareos >= 18.2.4, Bareos supports TLS-PSK (Transport-Layer-Security Pre-Shared-Key) to secure its network connections and uses this by default.
144
146
 
145
- Unfortenatly, the Python core module `ssl` does not support TLS-PSK.
146
- There is limited support by the extra module `sslpsk` (see https://github.com/drbild/sslpsk).
147
+ Unfortunately the Python core module ``ssl`` does support TLS-PSK only with Python >= 3.13.
148
+ For some older versions of Python,
149
+ the extra module ``sslpsk`` (see https://github.com/drbild/sslpsk) offers limited support.
147
150
 
148
151
  Fallback To Unencrypted Connections
149
152
  -----------------------------------
150
153
 
151
- In order to work in most cases, even if ``sslpsk`` is not available,
152
- the `DirectorConsole` uses a fallback.
154
+ Normally `DirectorConsole` tries to connect using the latest known protocol version.
155
+ In order to allow connections in more environments,
156
+ the `DirectorConsole` can fall back to older protocol versions.
157
+ Specify `protocolversion = None` (or 0 as command line argument) to enable automatic fall back.
153
158
  If connecting via TLS-PSK fails, it falls back to the old, unencrypted protocol version.
154
- In this case, a warning is issued, but the connection will work nevertheless:
159
+ Depending on your bareos-director configuration, unencrypted connections will be accepted:
155
160
 
156
161
  .. code:: python
157
162
 
158
163
  >>> import bareos.bsock
159
- /.../bareos/bsock/lowlevel.py:39: UserWarning: Connection encryption via TLS-PSK is not available, as the module sslpsk is not installed.
160
- >>> directorconsole=bareos.bsock.DirectorConsole(address='localhost', port=9101, name='user-tls', password='secret')
164
+ /.../bareos/bsock/lowlevel.py:39: UserWarning: Connection encryption via TLS-PSK is not available (TLS-PSK is not available in the ssl module and the extra module sslpsk is not installed).
165
+ >>> directorconsole=bareos.bsock.DirectorConsole(address='localhost', port=9101, name='user-tls', password='secret', protocolversion=None)
161
166
  socket error: Conversation terminated (-4)
162
167
  Failed to connect using protocol version 2. Trying protocol version 1.
163
168
  >>> print(directorconsole.call('help').decode("utf-8"))
@@ -172,7 +177,7 @@ To enforce a encrypted connection, use the ``tls_psk_require=True`` parameter:
172
177
  >>> directorconsole=bareos.bsock.DirectorConsole(address='localhost', port=9101, name='user-tls', password='secret', tls_psk_require=True)
173
178
  Traceback (most recent call last):
174
179
  ...
175
- bareos.exceptions.ConnectionError: TLS-PSK is required, but sslpsk module not loaded/available.
180
+ bareos.exceptions.ConnectionError: TLS-PSK is required, but not available.
176
181
 
177
182
 
178
183
  In this case, an exception is raised, if the connection can not be established via TLS-PSK.
@@ -183,10 +188,18 @@ sslpsk
183
188
  The extra module `sslpsk` (see https://github.com/drbild/sslpsk)
184
189
  extends the core module `ssl` by TLS-PSK.
185
190
 
186
- At the time of writing, the lasted version installable via pip is 1.0.0 (https://pypi.org/project/sslpsk/), which is not working with Python >= 3.
191
+ At the time of writing, the lasted version installable via pip is 1.0.0 (https://pypi.org/project/sslpsk/),
192
+ which is not working with Python >= 3.
193
+
194
+ For using `python-bareos` with TLS-PSK with
195
+ Python >= 3 and Python <= 3.9
196
+ the latest version must by installed manually.
197
+ At the time of writing, even the latest version
198
+ (https://github.com/drbild/sslpsk/commit/d88123a75786953f82f5e25d6c43d9d9259acb62)
199
+ does not support Python >= 3.10.
200
+ However, Python >= 3.13 has direct support for TLS-PSK in the core `ssl` module.
187
201
 
188
- If `python-bareos` should use TLS-PSK with Python >= 3,
189
- the latest version must by installed manually:
202
+ Installing the `sslpsk` module manually:
190
203
 
191
204
  .. code:: shell
192
205
 
@@ -1,6 +1,6 @@
1
1
  # BAREOS - Backup Archiving REcovery Open Sourced
2
2
  #
3
- # Copyright (C) 2016-2023 Bareos GmbH & Co. KG
3
+ # Copyright (C) 2016-2024 Bareos GmbH & Co. KG
4
4
  #
5
5
  # This program is Free Software; you can redistribute it and/or
6
6
  # modify it under the terms of version three of the GNU Affero General Public
@@ -22,7 +22,6 @@ Send and receive the response to Bareos Director Daemon Console interface.
22
22
  """
23
23
 
24
24
  from bareos.bsock.connectiontype import ConnectionType
25
- from bareos.bsock.constants import Constants
26
25
  from bareos.bsock.lowlevel import LowLevel
27
26
  from bareos.bsock.protocolmessageids import ProtocolMessageIds
28
27
  from bareos.bsock.protocolmessages import ProtocolMessages
@@ -61,16 +60,19 @@ class DirectorConsole(LowLevel):
61
60
  >>> director = DirectorConsole(**bareos_args)
62
61
 
63
62
  Args:
64
- argparser (ArgParser): ArgParser instance.
63
+ argparser (ArgParser or ConfigArgParser): (Config)ArgParser instance.
65
64
  """
66
- argparser.add_argument(
65
+
66
+ group = argparser.add_argument_group(title="Bareos Director connection options")
67
+
68
+ group.add_argument(
67
69
  "--name",
68
70
  default="*UserAgent*",
69
- help='use this to access a specific Bareos director named console. Otherwise it connects to the default console ("*UserAgent*").',
71
+ help='use this to access a specific Bareos director named console. Otherwise it connects to the default console ("%(default)s").',
70
72
  dest="BAREOS_name",
71
73
  )
72
74
 
73
- argparser.add_argument(
75
+ group.add_argument(
74
76
  "-p",
75
77
  "--password",
76
78
  help="Password to authenticate to a Bareos Director console.",
@@ -78,58 +80,58 @@ class DirectorConsole(LowLevel):
78
80
  dest="BAREOS_password",
79
81
  )
80
82
 
81
- argparser.add_argument(
83
+ group.add_argument(
82
84
  "--port",
83
85
  default=9101,
84
- help="Bareos Director network port.",
86
+ help="Bareos Director network port. Default: %(default)s.",
85
87
  dest="BAREOS_port",
86
88
  )
87
89
 
88
90
  # argparser.add_argument('--dirname', help="Bareos Director name")
89
- argparser.add_argument(
91
+ group.add_argument(
90
92
  "--address",
91
93
  default="localhost",
92
- help="Bareos Director network address.",
94
+ help="Bareos Director network address. Default: %(default)s.",
93
95
  dest="BAREOS_address",
94
96
  )
95
97
 
96
- argparser.add_argument(
98
+ group.add_argument(
97
99
  "--timeout",
98
100
  type=int,
99
101
  help="Timeout (in seconds) for the connection to the Bareos Director.",
100
102
  dest="BAREOS_timeout",
101
103
  )
102
104
 
103
- argparser.add_argument(
105
+ group.add_argument(
104
106
  "--protocolversion",
105
- default=ProtocolVersions.last,
106
107
  type=int,
107
- help="Specify the Bareos console protocol version. Default: {0} (current).".format(
108
- ProtocolVersions.last
109
- ),
108
+ choices=set(protocolversion.value for protocolversion in ProtocolVersions)
109
+ | set([0]),
110
+ default=ProtocolVersions.last.value,
111
+ help="Specify the Bareos console protocol version (0: auto-detect, %(default)s: latest). Default: %(default)s.",
110
112
  dest="BAREOS_protocolversion",
111
113
  )
112
114
 
113
- argparser.add_argument(
115
+ group.add_argument(
114
116
  "--pam-username",
115
117
  help="Username to authenticate against PAM on top off the normal authentication.",
116
118
  dest="BAREOS_pam_username",
117
119
  )
118
120
 
119
- argparser.add_argument(
121
+ group.add_argument(
120
122
  "--pam-password",
121
123
  help="Password to authenticate against PAM on top off the normal authentication.",
122
124
  dest="BAREOS_pam_password",
123
125
  )
124
126
 
125
- argparser.add_argument(
127
+ group.add_argument(
126
128
  "--tls-psk-require",
127
- help="Allow only encrypted connections. Default: False.",
129
+ help="Allow only encrypted connections. Default: %(default)s.",
128
130
  action="store_true",
129
131
  dest="BAREOS_tls_psk_require",
130
132
  )
131
133
 
132
- TlsVersionParser().add_argument(argparser)
134
+ TlsVersionParser().add_argument(group)
133
135
 
134
136
  def __init__(
135
137
  self,
@@ -192,7 +194,7 @@ class DirectorConsole(LowLevel):
192
194
  if tls_version is not None:
193
195
  self.tls_version = tls_version
194
196
  self.identity_prefix = "R_CONSOLE"
195
- if protocolversion is not None:
197
+ if protocolversion is not None and protocolversion > 0:
196
198
  self.requested_protocol_version = int(protocolversion)
197
199
  self.protocol_messages.set_version(self.requested_protocol_version)
198
200
  self.connect(
bareos/bsock/lowlevel.py CHANGED
@@ -1,6 +1,6 @@
1
1
  # BAREOS - Backup Archiving REcovery Open Sourced
2
2
  #
3
- # Copyright (C) 2015-2023 Bareos GmbH & Co. KG
3
+ # Copyright (C) 2015-2024 Bareos GmbH & Co. KG
4
4
  #
5
5
  # This program is Free Software; you can redistribute it and/or
6
6
  # modify it under the terms of version three of the GNU Affero General Public
@@ -46,17 +46,26 @@ from bareos.util.bareosbase64 import BareosBase64
46
46
  from bareos.util.password import Password
47
47
  import bareos.exceptions
48
48
 
49
- # Try to load the sslpsk module,
50
- # with implement TLS-PSK (Transport Layer Security - Pre-Shared-Key)
51
- # on top of the ssl module.
52
- # If it is not available, we continue anyway,
49
+ # The ssl module support TLS-PSK (Transport Layer Security - Pre-Shared-Key)
50
+ # since Python >= 3.13.
51
+ # For some older Python versions, the TLS-PSK functionality
52
+ # can be added by the sslpsk module,
53
+ # with implement TLS-PSK on top of the ssl module.
54
+ # If it is also not available, we continue anyway,
53
55
  # but don't use TLS-PSK.
54
- try:
55
- import sslpsk
56
- except ImportError:
57
- warnings.warn(
58
- "Connection encryption via TLS-PSK is not available, as the module sslpsk is not installed."
59
- )
56
+ if not getattr(ssl, "HAS_PSK", False):
57
+
58
+ def format_warning_short(message, category, filename, lineno, line=""):
59
+ return f"{category.__name__}: {message}\n"
60
+
61
+ warnings.formatwarning = format_warning_short
62
+ try:
63
+ import sslpsk
64
+ except ImportError:
65
+ warnings.warn(
66
+ "Connection encryption via TLS-PSK is not available "
67
+ "(not available in 'ssl' and extra module 'sslpsk' is not installed)."
68
+ )
60
69
 
61
70
 
62
71
  class LowLevel(object):
@@ -71,7 +80,7 @@ class LowLevel(object):
71
80
  def argparser_get_bareos_parameter(args):
72
81
  """Extract arguments.
73
82
 
74
- This method is usally used together with the method :py:func:`argparser_add_default_command_line_arguments`.
83
+ This method is usually used together with the method :py:func:`argparser_add_default_command_line_arguments`.
75
84
 
76
85
  Args:
77
86
  args (ArgParser.Namespace): Arguments retrieved by :py:func:`ArgumentParser.parse_args`.
@@ -182,7 +191,7 @@ class LowLevel(object):
182
191
  if self.tls_psk_require:
183
192
  if not self.is_tls_psk_available():
184
193
  raise bareos.exceptions.ConnectionError(
185
- "TLS-PSK is required, but sslpsk module not loaded/available."
194
+ "TLS-PSK is required, but not available."
186
195
  )
187
196
  if not self.tls_psk_enable:
188
197
  raise bareos.exceptions.ConnectionError(
@@ -267,23 +276,32 @@ class LowLevel(object):
267
276
  else:
268
277
  raise bareos.exceptions.ConnectionError("No password provided.")
269
278
  self.logger.debug("identity = {0}, password = {1}".format(identity, password))
270
- try:
271
- self.socket = sslpsk.wrap_socket(
272
- client_socket,
273
- ssl_version=self.tls_version,
274
- ciphers="ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH",
275
- psk=(password, identity),
276
- server_side=False,
277
- )
278
- except ssl.SSLError as e:
279
- # raise ConnectionError(
280
- # "failed to connect to host {0}, port {1}: {2}".format(self.address, self.port, str(e)))
281
- # Using a general raise keep more information about the type of error.
282
- raise
279
+ ciphers = "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"
280
+
281
+ if getattr(ssl, "HAS_PSK", False):
282
+ context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
283
+ context.check_hostname = False
284
+ context.set_ciphers(ciphers)
285
+ context.set_psk_client_callback(lambda hint: (identity, password))
286
+ self.socket = context.wrap_socket(client_socket, server_side=False)
287
+ else:
288
+ try:
289
+ self.socket = sslpsk.wrap_socket(
290
+ client_socket,
291
+ ssl_version=self.tls_version,
292
+ ciphers=ciphers,
293
+ psk=(password, identity),
294
+ server_side=False,
295
+ )
296
+ except ssl.SSLError as e:
297
+ # raise ConnectionError(
298
+ # "failed to connect to host {0}, port {1}: {2}".format(self.address, self.port, str(e)))
299
+ # Using a general raise to keep more information about the type of error.
300
+ raise
283
301
  return True
284
302
 
285
303
  def get_tls_psk_identity(self):
286
- """Bareos TLS-PSK excepts the identiy is a specific format."""
304
+ """Bareos TLS-PSK excepts the identity is a specific format."""
287
305
  name = str(self.name)
288
306
  if isinstance(self.name, bytes):
289
307
  name = self.name.decode("utf-8")
@@ -294,8 +312,8 @@ class LowLevel(object):
294
312
 
295
313
  @staticmethod
296
314
  def is_tls_psk_available():
297
- """Checks if we have all required modules for TLS-PSK."""
298
- return "sslpsk" in sys.modules
315
+ """Checks if TLS-PSK is available."""
316
+ return getattr(ssl, "HAS_PSK", False) or ("sslpsk" in sys.modules)
299
317
 
300
318
  def get_protocol_version(self):
301
319
  """Get the Bareos Console protocol version that is used.
@@ -524,7 +542,7 @@ class LowLevel(object):
524
542
  msg = self.recv_submsg(length)
525
543
  return msg
526
544
 
527
- def recv_msg(self, regex=b"^\d\d\d\d OK.*$"):
545
+ def recv_msg(self, regex=b"^\\d\\d\\d\\d OK.*$"):
528
546
  """Receive a full message.
529
547
 
530
548
  It retrieves messages (header + message text),
@@ -1,6 +1,6 @@
1
1
  # BAREOS - Backup Archiving REcovery Open Sourced
2
2
  #
3
- # Copyright (C) 2019-2021 Bareos GmbH & Co. KG
3
+ # Copyright (C) 2019-2024 Bareos GmbH & Co. KG
4
4
  #
5
5
  # This program is Free Software; you can redistribute it and/or
6
6
  # modify it under the terms of version three of the GNU Affero General Public
@@ -21,8 +21,10 @@
21
21
  Bareos Protocol Versions.
22
22
  """
23
23
 
24
+ from enum import IntEnum
24
25
 
25
- class ProtocolVersions(object):
26
+
27
+ class ProtocolVersions(IntEnum):
26
28
  """
27
29
  Bareos Protocol Versions.
28
30
  """
@@ -1,6 +1,6 @@
1
1
  # BAREOS - Backup Archiving REcovery Open Sourced
2
2
  #
3
- # Copyright (C) 2020-2021 Bareos GmbH & Co. KG
3
+ # Copyright (C) 2020-2024 Bareos GmbH & Co. KG
4
4
  #
5
5
  # This program is Free Software; you can redistribute it and/or
6
6
  # modify it under the terms of version three of the GNU Affero General Public
@@ -57,7 +57,7 @@ class TlsVersionParser:
57
57
  def add_argument(self, argparser):
58
58
  argparser.add_argument(
59
59
  "--tls-version",
60
- help="Use a specific TLS protocol version.",
60
+ help="Use a specific TLS protocol version (only used with the sslpsk module).",
61
61
  action=ArgParserTlsVersionAction,
62
62
  choices=OrderedDict(sorted(self.tls_version_options.items())),
63
63
  dest="BAREOS_tls_version",
bareos/util/__init__.py CHANGED
@@ -1,6 +1,6 @@
1
1
  # BAREOS - Backup Archiving REcovery Open Sourced
2
2
  #
3
- # Copyright (C) 2015-2023 Bareos GmbH & Co. KG
3
+ # Copyright (C) 2015-2024 Bareos GmbH & Co. KG
4
4
  #
5
5
  # This program is Free Software; you can redistribute it and/or
6
6
  # modify it under the terms of version three of the GNU Affero General Public
@@ -21,9 +21,10 @@
21
21
  Bareos utility classes.
22
22
  """
23
23
 
24
+ from bareos.util.argparse import ArgumentParser
24
25
  from bareos.util.bareosbase64 import BareosBase64
25
26
  from bareos.util.password import Password
26
27
  from bareos.util.path import Path
27
28
  from bareos.util.version import Version
28
29
 
29
- __all__ = ["BareosBase64", "Password", "Path", "Version"]
30
+ __all__ = ["ArgumentParser", "BareosBase64", "Password", "Path", "Version"]
@@ -0,0 +1,52 @@
1
+ # BAREOS - Backup Archiving REcovery Open Sourced
2
+ #
3
+ # Copyright (C) 2024-2024 Bareos GmbH & Co. KG
4
+ #
5
+ # This program is Free Software; you can redistribute it and/or
6
+ # modify it under the terms of version three of the GNU Affero General Public
7
+ # License as published by the Free Software Foundation and included
8
+ # in the file LICENSE.
9
+ #
10
+ # This program is distributed in the hope that it will be useful, but
11
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
+ # 02110-1301, USA.
19
+
20
+ """
21
+ ArgumentParser wrapper.
22
+
23
+ Uses configargparse, if available,
24
+ otherwise, falls back to argparse.
25
+ """
26
+
27
+ from pprint import pformat
28
+
29
+ HAVE_CONFIG_ARG_PARSE_MODULE = False
30
+ try:
31
+ import configargparse as argparse
32
+
33
+ HAVE_CONFIG_ARG_PARSE_MODULE = True
34
+ except ImportError:
35
+ import argparse
36
+
37
+
38
+ class ArgumentParser(argparse.ArgumentParser):
39
+ """ArgumentParser wrapper"""
40
+
41
+ def __init__(self, *args, **kwargs):
42
+ super().__init__(*args, **kwargs)
43
+ if HAVE_CONFIG_ARG_PARSE_MODULE:
44
+ self.add_argument(
45
+ "-c", "--config", is_config_file=True, help="Config file path."
46
+ )
47
+
48
+ def format_values(self):
49
+ try:
50
+ return super().format_values()
51
+ except AttributeError:
52
+ return pformat(vars(self.parse_args()))
bareos/util/path.py CHANGED
@@ -1,6 +1,6 @@
1
1
  # BAREOS - Backup Archiving REcovery Open Sourced
2
2
  #
3
- # Copyright (C) 2015-2021 Bareos GmbH & Co. KG
3
+ # Copyright (C) 2015-2024 Bareos GmbH & Co. KG
4
4
  #
5
5
  # This program is Free Software; you can redistribute it and/or
6
6
  # modify it under the terms of version three of the GNU Affero General Public
@@ -21,8 +21,6 @@
21
21
  Handle file paths.
22
22
  """
23
23
 
24
- from copy import copy
25
-
26
24
 
27
25
  class Path(object):
28
26
  """
@@ -55,7 +53,7 @@ class Path(object):
55
53
  self.path = None
56
54
 
57
55
  def set_path(self, path):
58
- if path == None:
56
+ if path is None:
59
57
  self.__set_defaults()
60
58
  elif isinstance(path, str):
61
59
  self.path_orig = path
@@ -76,10 +74,9 @@ class Path(object):
76
74
  pass
77
75
 
78
76
  def get(self, index=None):
79
- if index == None:
77
+ if index is None:
80
78
  return self.path
81
- else:
82
- return self.path[index]
79
+ return self.path[index]
83
80
 
84
81
  def shift(self):
85
82
  """
@@ -1,7 +1,8 @@
1
1
  #!python
2
+ #
2
3
  # BAREOS - Backup Archiving REcovery Open Sourced
3
4
  #
4
- # Copyright (C) 2019-2020 Bareos GmbH & Co. KG
5
+ # Copyright (C) 2019-2024 Bareos GmbH & Co. KG
5
6
  #
6
7
  # This program is Free Software; you can redistribute it and/or
7
8
  # modify it under the terms of version three of the GNU Affero General Public
@@ -18,8 +19,7 @@
18
19
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
20
  # 02110-1301, USA.
20
21
 
21
-
22
- import argparse
22
+ from bareos.util import argparse
23
23
  import bareos.bsock
24
24
  from bareos.bsock.filedaemon import FileDaemon
25
25
  import logging
@@ -53,11 +53,11 @@ if __name__ == "__main__":
53
53
  logger.debug("options: %s" % (bareos_args))
54
54
  try:
55
55
  bsock = FileDaemon(**bareos_args)
56
- except (bareos.exceptions.Error) as e:
56
+ except bareos.exceptions.Error as e:
57
57
  print(str(e))
58
58
  sys.exit(1)
59
59
  logger.debug("authentication successful")
60
60
  if args.command:
61
- print(bsock.call(args.command))
61
+ print(bsock.call(args.command).decode("utf-8"))
62
62
  else:
63
63
  bsock.interactive()
@@ -1,7 +1,8 @@
1
1
  #!python
2
+ #
2
3
  # BAREOS - Backup Archiving REcovery Open Sourced
3
4
  #
4
- # Copyright (C) 2019-2020 Bareos GmbH & Co. KG
5
+ # Copyright (C) 2019-2024 Bareos GmbH & Co. KG
5
6
  #
6
7
  # This program is Free Software; you can redistribute it and/or
7
8
  # modify it under the terms of version three of the GNU Affero General Public
@@ -19,8 +20,7 @@
19
20
  # 02110-1301, USA.
20
21
 
21
22
 
22
- from __future__ import print_function
23
- import argparse
23
+ from bareos.util import argparse
24
24
  import bareos.bsock
25
25
  import bareos.exceptions
26
26
  import logging
@@ -53,7 +53,7 @@ if __name__ == "__main__":
53
53
  logger.debug("options: %s" % (bareos_args))
54
54
  try:
55
55
  director = bareos.bsock.DirectorConsoleJson(**bareos_args)
56
- except (bareos.exceptions.Error) as e:
56
+ except bareos.exceptions.Error as e:
57
57
  print(str(e))
58
58
  sys.exit(1)
59
59
 
@@ -1,7 +1,8 @@
1
1
  #!python
2
+ #
2
3
  # BAREOS - Backup Archiving REcovery Open Sourced
3
4
  #
4
- # Copyright (C) 2019-2020 Bareos GmbH & Co. KG
5
+ # Copyright (C) 2019-2024 Bareos GmbH & Co. KG
5
6
  #
6
7
  # This program is Free Software; you can redistribute it and/or
7
8
  # modify it under the terms of version three of the GNU Affero General Public
@@ -18,9 +19,7 @@
18
19
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
20
  # 02110-1301, USA.
20
21
 
21
-
22
- from __future__ import print_function
23
- import argparse
22
+ from bareos.util import argparse
24
23
  import bareos.bsock
25
24
  import bareos.exceptions
26
25
  import logging
@@ -34,6 +33,8 @@ def getArguments():
34
33
  )
35
34
  bareos.bsock.DirectorConsole.argparser_add_default_command_line_arguments(argparser)
36
35
  args = argparser.parse_args()
36
+ if args.debug:
37
+ print(argparser.format_values())
37
38
  return args
38
39
 
39
40
 
@@ -51,7 +52,7 @@ if __name__ == "__main__":
51
52
  logger.debug("options: %s" % (bareos_args))
52
53
  try:
53
54
  director = bareos.bsock.DirectorConsole(**bareos_args)
54
- except (bareos.exceptions.Error) as e:
55
+ except bareos.exceptions.Error as e:
55
56
  print(str(e))
56
57
  sys.exit(1)
57
58
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-bareos
3
- Version: 23.0.1
3
+ Version: 23.0.4
4
4
  Summary: Client library and tools for Bareos console access.
5
5
  Home-page: https://github.com/bareos/bareos/
6
6
  Author: Bareos Team
@@ -12,31 +12,32 @@ Classifier: License :: OSI Approved :: GNU Affero General Public License v3
12
12
  Classifier: Operating System :: OS Independent
13
13
  Classifier: Programming Language :: Python
14
14
  Classifier: Topic :: System :: Archiving :: Backup
15
- Requires-Python: >=2.6
15
+ Requires-Python: >=3.6
16
16
  Description-Content-Type: text/x-rst
17
17
  License-File: LICENSE.txt
18
- Provides-Extra: tls-psk
19
- Requires-Dist: sslpsk ; extra == 'tls-psk'
18
+ Provides-Extra: configfile
19
+ Requires-Dist: configargparse; extra == "configfile"
20
20
 
21
21
  python-bareos
22
22
  =============
23
23
 
24
- `python-bareos` is a Python module to access a http://www.bareos.org backup system.
24
+ `python-bareos` is a Python module to access a https://www.bareos.com backup system.
25
25
 
26
26
  Packages for `python-bareos` are included in the Bareos core distribution and available via https://pypi.org/.
27
27
 
28
28
  Documentation is available at https://docs.bareos.org/DeveloperGuide/PythonBareos.html
29
29
 
30
+
30
31
  .. note::
31
32
 
32
- By default, the Bareos Director (>= 18.2.4) uses TLS-PSK when communicating through the network.
33
+ By default, the Bareos Director (>= 18.2.4)
34
+ uses TLS-PSK when communicating through the network.
33
35
 
34
- Unfortunately the Python core module ``ssl``
35
- does not support TLS-PSK.
36
- For testing ``python-bareos`` should be used without TLS.
36
+ The Python (https://github.com/python/cpython) core module ``ssl``
37
+ does support TLS-PSK only since Python >= 3.13.
37
38
  The section `Transport Encryption (TLS-PSK)`_ describes
38
- how to use ``python-bareos`` with TLS-PSK
39
- and about the limitations.
39
+ how to use TLS-PSK and about the limitations.
40
+ For testing this module can also be used without TLS.
40
41
 
41
42
 
42
43
  Preparations
@@ -53,12 +54,13 @@ Create some named consoles for testing:
53
54
 
54
55
  This creates a console user with name `user1` and the profile `operator`.
55
56
  The `operator` profile is a default profile that comes with the Bareos Director.
56
- It does allow most commands. It only deny some dangerous commands (see ``show profile=operator``),
57
+ It does allow most commands, but deny some dangerous commands (see ``show profile=operator``),
57
58
  so it is well suited for this purpose.
58
59
  Futhermore, TLS enforcement is disabled for this console user.
59
60
 
60
61
  For testing with TLS-PSK, we also create the user `user-tls`.
61
62
 
63
+
62
64
  Examples
63
65
  ========
64
66
 
@@ -94,7 +96,7 @@ Simple version of the bconsole in Python
94
96
  >>> directorconsole = bareos.bsock.DirectorConsole(address='localhost', port=9101, password='secret')
95
97
  >>> directorconsole.interactive()
96
98
 
97
- Or use the included ``bconsole.py`` script:
99
+ Or use the ``bconsole.py`` script:
98
100
 
99
101
  .. code-block:: shell-session
100
102
 
@@ -127,9 +129,10 @@ Example:
127
129
  Full
128
130
  Differential
129
131
 
132
+
130
133
  The results the the `call` method is a ``dict`` object.
131
134
 
132
- In case of an error, an exception, derived from ``bareos.exceptions.Error`` is raised.
135
+ In case of an error, an exception, derived from `bareos.exceptions.Error` is raised.
133
136
 
134
137
  Example:
135
138
 
@@ -150,26 +153,30 @@ Transport Encryption (TLS-PSK)
150
153
 
151
154
  Since Bareos >= 18.2.4, Bareos supports TLS-PSK (Transport-Layer-Security Pre-Shared-Key) to secure its network connections and uses this by default.
152
155
 
153
- Unfortenatly, the Python core module `ssl` does not support TLS-PSK.
154
- There is limited support by the extra module `sslpsk` (see https://github.com/drbild/sslpsk).
156
+ Unfortunately the Python core module ``ssl`` does support TLS-PSK only with Python >= 3.13.
157
+ For some older versions of Python,
158
+ the extra module ``sslpsk`` (see https://github.com/drbild/sslpsk) offers limited support.
155
159
 
156
160
  Fallback To Unencrypted Connections
157
161
  -----------------------------------
158
162
 
159
- In order to work in most cases, even if ``sslpsk`` is not available,
160
- the `DirectorConsole` uses a fallback.
163
+ Normally `DirectorConsole` tries to connect using the latest known protocol version.
164
+ In order to allow connections in more environments,
165
+ the `DirectorConsole` can fall back to older protocol versions.
166
+ Specify `protocolversion = None` (or 0 as command line argument) to enable automatic fall back.
161
167
  If connecting via TLS-PSK fails, it falls back to the old, unencrypted protocol version.
162
- In this case, a warning is issued, but the connection will work nevertheless:
168
+ Depending on your bareos-director configuration, unencrypted connections will be accepted:
163
169
 
164
170
  .. code:: python
165
171
 
166
172
  >>> import bareos.bsock
167
- /.../bareos/bsock/lowlevel.py:39: UserWarning: Connection encryption via TLS-PSK is not available, as the module sslpsk is not installed.
168
- >>> directorconsole=bareos.bsock.DirectorConsole(address='localhost', port=9101, name='user-tls', password='secret')
173
+ /.../bareos/bsock/lowlevel.py:39: UserWarning: Connection encryption via TLS-PSK is not available (TLS-PSK is not available in the ssl module and the extra module sslpsk is not installed).
174
+ >>> directorconsole=bareos.bsock.DirectorConsole(address='localhost', port=9101, name='user-tls', password='secret', protocolversion=None)
169
175
  socket error: Conversation terminated (-4)
170
176
  Failed to connect using protocol version 2. Trying protocol version 1.
171
177
  >>> print(directorconsole.call('help').decode("utf-8"))
172
178
 
179
+
173
180
  To enforce a encrypted connection, use the ``tls_psk_require=True`` parameter:
174
181
 
175
182
  .. code:: python
@@ -178,8 +185,9 @@ To enforce a encrypted connection, use the ``tls_psk_require=True`` parameter:
178
185
  /.../bareos/bsock/lowlevel.py:39: UserWarning: Connection encryption via TLS-PSK is not available, as the module sslpsk is not installed.
179
186
  >>> directorconsole=bareos.bsock.DirectorConsole(address='localhost', port=9101, name='user-tls', password='secret', tls_psk_require=True)
180
187
  Traceback (most recent call last):
181
- [...]
182
- bareos.exceptions.ConnectionError: TLS-PSK is required, but sslpsk module not loaded/available.
188
+ ...
189
+ bareos.exceptions.ConnectionError: TLS-PSK is required, but not available.
190
+
183
191
 
184
192
  In this case, an exception is raised, if the connection can not be established via TLS-PSK.
185
193
 
@@ -189,10 +197,18 @@ sslpsk
189
197
  The extra module `sslpsk` (see https://github.com/drbild/sslpsk)
190
198
  extends the core module `ssl` by TLS-PSK.
191
199
 
192
- At the time of writing, the lasted version installable via pip is 1.0.0 (https://pypi.org/project/sslpsk/), which is not working with Python >= 3.
200
+ At the time of writing, the lasted version installable via pip is 1.0.0 (https://pypi.org/project/sslpsk/),
201
+ which is not working with Python >= 3.
202
+
203
+ For using `python-bareos` with TLS-PSK with
204
+ Python >= 3 and Python <= 3.9
205
+ the latest version must by installed manually.
206
+ At the time of writing, even the latest version
207
+ (https://github.com/drbild/sslpsk/commit/d88123a75786953f82f5e25d6c43d9d9259acb62)
208
+ does not support Python >= 3.10.
209
+ However, Python >= 3.13 has direct support for TLS-PSK in the core `ssl` module.
193
210
 
194
- If `python-bareos` should use TLS-PSK with Python >= 3,
195
- the latest version must by installed manually:
211
+ Installing the `sslpsk` module manually:
196
212
 
197
213
  .. code:: shell
198
214
 
@@ -0,0 +1,30 @@
1
+ bareos/VERSION.txt,sha256=_lnDqGzjENucmF8ZJxcWoFMoLZUPuyXKxZv9C9uN2Cg,7
2
+ bareos/__init__.py,sha256=WPq-fXxGDZSIwfkXZkwJAZdGcVSeVBcLsTum5qOmX2I,1423
3
+ bareos/exceptions.py,sha256=3oeC_jXq2imzPxiqJmGTq4TsgFRtDlzwnAwumzYsB5M,4071
4
+ bareos/bsock/__init__.py,sha256=lXn5TYH3-UvwneHfLHWEzQYRSvUmUzRq5c6iSAqcnuo,8658
5
+ bareos/bsock/bsock.py,sha256=SIAPU7ouXOW5ScnnpgtVbcugKmzXlNhSs6lrC0ofspw,1242
6
+ bareos/bsock/bsockjson.py,sha256=pnnX7b83dJH86pOw140CBz5etVJgafcQhXtKhr219TE,1289
7
+ bareos/bsock/connectiontype.py,sha256=PNEHpqZfuAHV310NaOMgMXj6VKiZxAZwXeRIOUfHJWI,1043
8
+ bareos/bsock/constants.py,sha256=U9RlPy8XYNkFCG1j6B89gI5cCiODVHyfQMWNumz7pbY,5127
9
+ bareos/bsock/directorconsole.py,sha256=ou1IYXoMxgv46zws0ERrB28VWvrs0npA3iC1b5pLMz0,10368
10
+ bareos/bsock/directorconsolejson.py,sha256=LdsMIwHZeaK-y9ydwOVl7EndMavqb2_v98ZRqWL0G7o,4457
11
+ bareos/bsock/filedaemon.py,sha256=bl8QD97R3uc5qTFV2wN0mfi2C3ePJsjaN_bKeZAclsk,6067
12
+ bareos/bsock/lowlevel.py,sha256=iDFqyU7XS3psoYnPQuah3lr6vl6hUFpc56wWf16pHzg,29916
13
+ bareos/bsock/protocolmessageids.py,sha256=WKlbo8qbgSL5V48fQnFXtyvjBBgIu_lOYzvQ8vQrGaQ,1228
14
+ bareos/bsock/protocolmessages.py,sha256=GgtstzAwA_gjOJCYQTG_wevsA6zTMn_bbz3E2yr8TCU,3008
15
+ bareos/bsock/protocolversions.py,sha256=7i5AaSnG9F-8WNVds7SJcezVzJU-SyjTNryJTNWikns,1030
16
+ bareos/bsock/tlsversionparser.py,sha256=kvRJ5CkR1scPpQ1f8LWD8h3qa3cBxye6ya-IiXwqF7c,2852
17
+ bareos/util/__init__.py,sha256=6Eml_u5V3eE6luss_ZwZMXlQsCCV50bdt244QC2T-cE,1159
18
+ bareos/util/argparse.py,sha256=ivizAADA9aZEremTfooR9gjqHdLoN51nOO4EOe5cE24,1629
19
+ bareos/util/bareosbase64.py,sha256=5bsv6-sxNJEnO1M3f0LyZP9CV6ZPyQ1axoi9Tfno4U8,3744
20
+ bareos/util/password.py,sha256=w71h7KnVHNik37oRl0ljj8krBVslz6a2tB_1jBJBJfM,2531
21
+ bareos/util/path.py,sha256=nycMxK3V-P9Cx-CMsWo4e-IVlnl6_Im61pFUIPQEbL0,3099
22
+ bareos/util/version.py,sha256=xqNm9vvkaHMKpS0xJozQs11XrQYJR1U4j5oOUCnPiMw,1201
23
+ python_bareos-23.0.4.data/scripts/bareos-fd-connect.py,sha256=y7Jh2A-tkQeBNjyKYo8RsA7POHyDEYuOuy8ozjCEE1o,2127
24
+ python_bareos-23.0.4.data/scripts/bconsole-json.py,sha256=0vFaTeQvJYt_Vk3ldGefMb1rZbPhdO16FaT7dZH0b2k,1960
25
+ python_bareos-23.0.4.data/scripts/bconsole.py,sha256=m7ylVGq-ibYBbi1ZdkDdMC891WLZ3Cf5mg4IIe27i64,1993
26
+ python_bareos-23.0.4.dist-info/LICENSE.txt,sha256=V8j_M8nAz8PvAOZQocyRDX7keai8UJ9skgmnwqETmdY,34520
27
+ python_bareos-23.0.4.dist-info/METADATA,sha256=mizizFC-7dOYXemb5aeSF3kG2yib4ijC_EY_2s3WhtM,8201
28
+ python_bareos-23.0.4.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
29
+ python_bareos-23.0.4.dist-info/top_level.txt,sha256=NlKJmA3FY973VTk-0zlxwwhDtFZHYVjpSNzgeMJsknY,7
30
+ python_bareos-23.0.4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.42.0)
2
+ Generator: setuptools (75.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,29 +0,0 @@
1
- bareos/VERSION.txt,sha256=kwEuJ6S5wBRXqy5Mw2eo3U9PQubbiGvmAw1UJ3Ezi_s,7
2
- bareos/__init__.py,sha256=WPq-fXxGDZSIwfkXZkwJAZdGcVSeVBcLsTum5qOmX2I,1423
3
- bareos/exceptions.py,sha256=3oeC_jXq2imzPxiqJmGTq4TsgFRtDlzwnAwumzYsB5M,4071
4
- bareos/bsock/__init__.py,sha256=wGlk0u6b09If5YWzfUNE_aN0jijZX1A99_Coyy9wJBU,7997
5
- bareos/bsock/bsock.py,sha256=SIAPU7ouXOW5ScnnpgtVbcugKmzXlNhSs6lrC0ofspw,1242
6
- bareos/bsock/bsockjson.py,sha256=pnnX7b83dJH86pOw140CBz5etVJgafcQhXtKhr219TE,1289
7
- bareos/bsock/connectiontype.py,sha256=PNEHpqZfuAHV310NaOMgMXj6VKiZxAZwXeRIOUfHJWI,1043
8
- bareos/bsock/constants.py,sha256=U9RlPy8XYNkFCG1j6B89gI5cCiODVHyfQMWNumz7pbY,5127
9
- bareos/bsock/directorconsole.py,sha256=_mLjpvubp-CW3QiWF8GW1DVu6GX8R_y2BfVSzy-FSqg,10168
10
- bareos/bsock/directorconsolejson.py,sha256=LdsMIwHZeaK-y9ydwOVl7EndMavqb2_v98ZRqWL0G7o,4457
11
- bareos/bsock/filedaemon.py,sha256=bl8QD97R3uc5qTFV2wN0mfi2C3ePJsjaN_bKeZAclsk,6067
12
- bareos/bsock/lowlevel.py,sha256=DluKCOwkCtT9Pi1b14NQ3bS3K-1mozwF7K_-ag-PK64,29061
13
- bareos/bsock/protocolmessageids.py,sha256=WKlbo8qbgSL5V48fQnFXtyvjBBgIu_lOYzvQ8vQrGaQ,1228
14
- bareos/bsock/protocolmessages.py,sha256=GgtstzAwA_gjOJCYQTG_wevsA6zTMn_bbz3E2yr8TCU,3008
15
- bareos/bsock/protocolversions.py,sha256=y_kP2iryuOQqZIcn6cUkL4NqwMhN6VNTLBUfvCWy9hQ,1003
16
- bareos/bsock/tlsversionparser.py,sha256=Iwj-RVs4BmEUohQUJUyiFZcM262X3UGuWECEgbi0vSw,2817
17
- bareos/util/__init__.py,sha256=pWio3INApoNIsldB1yAA2wZDTSCot_JCbGVQnWLqjSQ,1093
18
- bareos/util/bareosbase64.py,sha256=5bsv6-sxNJEnO1M3f0LyZP9CV6ZPyQ1axoi9Tfno4U8,3744
19
- bareos/util/password.py,sha256=w71h7KnVHNik37oRl0ljj8krBVslz6a2tB_1jBJBJfM,2531
20
- bareos/util/path.py,sha256=NKSI6r-4oaviBKnR66KirguP70K-cxuAKSxNfiIuBO8,3140
21
- bareos/util/version.py,sha256=xqNm9vvkaHMKpS0xJozQs11XrQYJR1U4j5oOUCnPiMw,1201
22
- python_bareos-23.0.1.data/scripts/bareos-fd-connect.py,sha256=CKWTt90lUOJ2bwoo1F80GfUdH_eypNIuuBIKcDnegSI,2095
23
- python_bareos-23.0.1.data/scripts/bconsole-json.py,sha256=R7u6uG6ox-h3piB_CZ18-2Bzx1FY65FhH3ECPmrKrSA,1981
24
- python_bareos-23.0.1.data/scripts/bconsole.py,sha256=3AdLbKqIV36uviR2AVQTcTaevMRyMJyYIJgs9jjjdn0,1955
25
- python_bareos-23.0.1.dist-info/LICENSE.txt,sha256=V8j_M8nAz8PvAOZQocyRDX7keai8UJ9skgmnwqETmdY,34520
26
- python_bareos-23.0.1.dist-info/METADATA,sha256=5KdGHyu6dY8WKBb4WS_qSKnlzFSRsu9yIpH_sHvCRoc,7568
27
- python_bareos-23.0.1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
28
- python_bareos-23.0.1.dist-info/top_level.txt,sha256=NlKJmA3FY973VTk-0zlxwwhDtFZHYVjpSNzgeMJsknY,7
29
- python_bareos-23.0.1.dist-info/RECORD,,