Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Dovecot auth over network #1678

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions radicale/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
"ldap",
"dovecot")

AUTH_SOCKET_FAMILY: Sequence[str] = ("AF_UNIX", "AF_INET", "AF_INET6")


def load(configuration: "config.Configuration") -> "BaseAuth":
"""Load the authentication module chosen in configuration."""
Expand Down
21 changes: 16 additions & 5 deletions radicale/auth/dovecot.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,21 @@
class Auth(auth.BaseAuth):
def __init__(self, configuration):
super().__init__(configuration)
self.socket = configuration.get("auth", "dovecot_socket")
self.timeout = 5
self.request_id_gen = itertools.count(1)

config_family = configuration.get("auth", "dovecot_connection_type")
if config_family == "AF_UNIX":
self.family = socket.AF_UNIX
self.address = configuration.get("auth", "dovecot_socket")
return

self.address = configuration.get("auth", "dovecot_host"), configuration.get("auth", "dovecot_port")
if config_family == "AF_INET":
self.family = socket.AF_INET
else:
self.family = socket.AF_INET6

def _login(self, login, password):
"""Validate credentials.

Expand All @@ -49,12 +60,12 @@ def _login(self, login, password):
return ""

with closing(socket.socket(
socket.AF_UNIX,
self.family,
socket.SOCK_STREAM)
) as sock:
try:
sock.settimeout(self.timeout)
sock.connect(self.socket)
sock.connect(self.address)

buf = bytes()
supported_mechs = []
Expand Down Expand Up @@ -171,8 +182,8 @@ def _login(self, login, password):

except socket.error as e:
logger.fatal(
"Failed to communicate with Dovecot socket %r: %s" %
(self.socket, e)
"Failed to communicate with Dovecot: %s" %
(e)
)

return ""
15 changes: 14 additions & 1 deletion radicale/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,23 @@ def json_str(value: Any) -> dict:
"value": "False",
"help": "enable caching of htpasswd file",
"type": bool}),
("dovecot_connection_type", {
"value": "AF_UNIX",
"help": "Connection type for dovecot authentication",
"type": str_or_callable,
"internal": auth.AUTH_SOCKET_FAMILY}),
("dovecot_socket", {
"value": "/var/run/dovecot/auth-client",
"help": "dovecot auth socket",
"help": "dovecot auth AF_UNIX socket",
"type": str}),
("dovecot_host", {
"value": "",
"help": "dovecot auth AF_INET or AF_INET6 host",
"type": str}),
("dovecot_port", {
"value": "12345",
"help": "dovecot auth port",
"type": int}),
("realm", {
"value": "Radicale - Password Required",
"help": "message displayed when a password is needed",
Expand Down
Loading