Commit Diff


commit - /dev/null
commit + 2fa6b3ec0b20e9c45043017d4d1ef42608fa9ab6
blob - /dev/null
blob + e59a227ee383f195b6838ce5146b8b912770a6ec (mode 644)
--- /dev/null
+++ Makefile
@@ -0,0 +1,18 @@
+NAME =		table-passwd
+PREFIX =	/usr/local
+LIBEXECDIR =	${PREFIX}/libexec
+MANDIR =	${PREFIX}/man
+SMTPDDIR =	${LIBEXEC}/smtpd
+INSTALL =	install
+
+all:
+	echo 'Nothing to do'
+
+lint:
+	man -Tlint -l table-passwd.5
+
+install:
+	${INSTALL} -m 0555 table-passwd ${DESTDIR}${SMTPDDIR}/${NAME}
+	${INSTALL} -m 0444 table-passwd.5 ${DESTDIR}${MANDIR}/man5/${NAME}.5
+
+.PHONY: all lint install
blob - /dev/null
blob + e43de17394392778b05075be7ed3bb7528a98c4a (mode 644)
--- /dev/null
+++ README.md
@@ -0,0 +1,17 @@
+# table-passwd
+
+This is a reimplementation of the original
+[table-passwd][orig-table-passwd] in perl.
+The aim is to show how easy it is to write
+custom tables with the new table protocol.
+
+[orig-table-passwd]: https://github.com/OpenSMTPD/table-passwd
+
+Usage:
+
+	# /etc/mail/smtpd.conf
+	table users passwd:"/path/to//passwd"
+
+Installing:
+
+	# make install
blob - /dev/null
blob + ab65ad53b6c69560d04d09d70eb378cbdd5514cd (mode 755)
--- /dev/null
+++ table-passwd
@@ -0,0 +1,88 @@
+#!/usr/bin/perl
+
+use v5.36;
+
+my %passwd;
+sub parse {
+	foreach my $passwd (@ARGV) {
+		open(my $f, '<', $passwd)
+		    or die "table-passwd: can't open $passwd: $!\n";
+		while (<$f>) {
+			chomp;
+			my ($name, $passwd, $uid, $gid, $gecos,
+			    $homedir, $shell) = split /:/;
+			$passwd{$name} = {
+				passwd => $passwd,
+				uid => $uid,
+				gid => $gid,
+				home => $homedir,
+			};
+		}
+	}
+}
+
+die "table-passwd: invalid usage: no argument\n" unless @ARGV;
+
+parse; # fetch initial state
+
+while (<STDIN>) {
+	chomp;
+	my @args = split /\|/, $_, 8;
+
+	if ($args[0] eq 'config') {
+		if ($args[1] eq 'ready') {
+			say "register|credentials";
+			say "register|userinfo";
+			say "register|ready";
+		}
+		next; # ignore the configs for now
+	}
+
+	die "table-passwd: unknown message" if $args[0] ne 'table';
+	die "table-passwd: unknown protocol" if $args[1] ne '0.1';
+
+	my $cmd = $args[4];
+
+	if ($cmd eq 'update') {
+		my $id = $args[5];
+		parse;	# XXX this can die on error
+		say "update-result|$id|ok";
+		next;
+	}
+
+	if ($cmd eq 'check' or $cmd eq 'lookup') {
+		my ($kind, $id, $query) = ($args[5], $args[6], $args[7]);
+		if ($kind ne 'credentials' and $kind ne 'userinfo') {
+			say "$cmd-result|$id|error";
+			next;
+		}
+
+		my $res = $passwd{$query};
+		if (not defined $res) {
+			say "$cmd-result|$id|not-found";
+			next;
+		}
+
+		if ($cmd eq 'check') {
+			say "$cmd-result|$id|found";
+			next;
+		}
+
+		if ($kind eq 'userinfo') {
+			say "$cmd-result|$id|found|". $res->{'uid'} .":".
+			    $res->{'gid'} .":". $res->{'home'};
+			next;
+		}
+
+		say "$cmd-result|$id|found|". $query .":". $res->{'passwd'};
+		next;
+	}
+
+	if ($cmd eq 'fetch') {
+		my $id = $args[6];
+		say "fetch-result|$id|error";
+		next;
+	}
+
+	die "table-passwd: unknown operation $cmd";
+}
blob - /dev/null
blob + 5bfe2b0c4417556c4d8b28adc0b9de77f0681d6f (mode 644)
--- /dev/null
+++ table-passwd.5
@@ -0,0 +1,83 @@
+.\"
+.\" Copyright (c) 2014 Gilles Chehade <gilles@poolp.org>
+.\" Copyright (c) 2016 Joerg Jung <jung@openbsd.org>
+.\" Copyright (c) 2024 Omar Polo <op@openbsd.org>
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.\"
+.Dd $Mdocdate: April 30 2024 $
+.Dt TABLE_PASSWD 5
+.Os
+.Sh NAME
+.Nm table-passwd
+.Nd format description for smtpd passwd tables
+.Sh SYNOPSIS
+.Cm table Ar name Cm passwd : Ns Dq Ar path/to/passwd
+.Sh DESCRIPTION
+This manual page documents the file format of "passwd" tables used by the
+.Xr smtpd 8
+mail daemon.
+.Pp
+The
+.Nm
+accepts a single argument which is the path to a
+.Xr passwd 5
+file and allows the sharing of a user database across different software
+supporting this format.
+.Pp
+.Nm
+is used by
+.Xr smtpd 8
+when authenticating a user or when user information such as user-id or
+home directory is required for a delivery.
+.Pp
+A
+.Nm
+table consists of a flat file containing the user entries, each
+one on a line by itself, with fields separated by a colon:
+.Bd -literal -offset indent
+gilles:*:1000:1000:Gilles:/home/gilles:/sbin/nologin
+eric:*:1001:1001:Eric:/home/eric:/sbin/nologin
+chl:*:1002:1002:Charles:/home/chl:/sbin/nologin
+.Ed
+.Pp
+Besides the first username field and depending on the table type, fields are
+optional and might be empty.
+The gecos and the shell field are not used and ignored.
+.Pp
+If the table is used for authentication, the second field should contain a
+password encrypted using the
+.Xr crypt 3
+function.
+Such passwords can be generated using the
+.Xr encrypt 1
+utility or
+.Xr smtpctl 8
+encrypt command.
+.Pp
+If the table is used for user information, user-id, group-id, and home
+directory fields are required.
+.Pp
+In favor of supporting shared authentication with the Dovecot Passwd-file
+format, extra fields after the last shell field are allowed (and ignored).
+.Sh SEE ALSO
+.Xr passwd 5 ,
+.Xr smtpd.conf 5 ,
+.Xr smtpctl 8 ,
+.Xr smtpd 8
+.Sh AUTHORS
+.An -nosplit
+.Nm
+was written by
+.An Omar Polo Aq Mt op@openbsd.org .