Re: table-procexec for opensmtpd (another try)

2021-10-15 Thread aisha
A very small change with fixing an off by one copy to the return value.
It was also copying the '\n' character by mistake.

diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y
index 832f4f2aec9..ff7b9a9a340 100644
--- a/usr.sbin/smtpd/parse.y
+++ b/usr.sbin/smtpd/parse.y
@@ -2543,13 +2543,6 @@ table: TABLE STRING STRING   {
config  = p+1;
}
}
-   if (config != NULL && *config != '/') {
-   yyerror("invalid backend parameter for table: 
%s",
-   $2);
-   free($2);
-   free($3);
-   YYERROR;
-   }
table = table_create(conf, backend, $2, config);
if (!table_config(table)) {
yyerror("invalid configuration file %s for 
table %s",
diff --git a/usr.sbin/smtpd/smtpctl/Makefile b/usr.sbin/smtpd/smtpctl/Makefile
index ef8148be8c9..46831d647dc 100644
--- a/usr.sbin/smtpd/smtpctl/Makefile
+++ b/usr.sbin/smtpd/smtpctl/Makefile
@@ -47,7 +47,7 @@ SRCS+=table.c
 SRCS+= table_static.c
 SRCS+= table_db.c
 SRCS+= table_getpwnam.c
-SRCS+= table_proc.c
+SRCS+= table_procexec.c
 SRCS+= unpack_dns.c
 SRCS+= spfwalk.c
 
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index e6fc114d0a6..8ef80add4e7 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1663,6 +1663,7 @@ int table_regex_match(const char *, const char *);
 void   table_open_all(struct smtpd *);
 void   table_dump_all(struct smtpd *);
 void   table_close_all(struct smtpd *);
+const char *table_service_name(enum table_service );
 
 
 /* to.c */
diff --git a/usr.sbin/smtpd/smtpd/Makefile b/usr.sbin/smtpd/smtpd/Makefile
index b31d4e42224..64e73c3bb70 100644
--- a/usr.sbin/smtpd/smtpd/Makefile
+++ b/usr.sbin/smtpd/smtpd/Makefile
@@ -62,7 +62,7 @@ SRCS+=compress_gzip.c
 
 SRCS+= table_db.c
 SRCS+= table_getpwnam.c
-SRCS+= table_proc.c
+SRCS+= table_procexec.c
 SRCS+= table_static.c
 
 SRCS+= queue_fs.c
diff --git a/usr.sbin/smtpd/table.c b/usr.sbin/smtpd/table.c
index 7328cf5df6e..81102ef90e1 100644
--- a/usr.sbin/smtpd/table.c
+++ b/usr.sbin/smtpd/table.c
@@ -35,9 +35,8 @@ struct table_backend *table_backend_lookup(const char *);
 extern struct table_backend table_backend_static;
 extern struct table_backend table_backend_db;
 extern struct table_backend table_backend_getpwnam;
-extern struct table_backend table_backend_proc;
+extern struct table_backend table_backend_procexec;
 
-static const char * table_service_name(enum table_service);
 static int table_parse_lookup(enum table_service, const char *, const char *,
 union lookup *);
 static int parse_sockaddr(struct sockaddr *, int, const char *);
@@ -48,7 +47,7 @@ static struct table_backend *backends[] = {
&table_backend_static,
&table_backend_db,
&table_backend_getpwnam,
-   &table_backend_proc,
+   &table_backend_procexec,
NULL
 };
 
@@ -67,7 +66,7 @@ table_backend_lookup(const char *backend)
return NULL;
 }
 
-static const char *
+const char *
 table_service_name(enum table_service s)
 {
switch (s) {
@@ -198,10 +197,9 @@ table_create(struct smtpd *conf, const char *backend, 
const char *name,
PATH_LIBEXEC"/table-%s\"", backend);
}
if (stat(path, &sb) == 0) {
-   tb = table_backend_lookup("proc");
-   (void)strlcpy(path, backend, sizeof(path));
+   tb = table_backend_lookup("proc-exec");
if (config) {
-   (void)strlcat(path, ":", sizeof(path));
+   (void)strlcat(path, " ", sizeof(path));
if (strlcat(path, config, sizeof(path))
>= sizeof(path))
fatalx("table_create: config file path 
too long");
diff --git a/usr.sbin/smtpd/table_proc.c b/usr.sbin/smtpd/table_proc.c
deleted file mode 100644
index 56893a0fb61..000
--- a/usr.sbin/smtpd/table_proc.c
+++ /dev/null
@@ -1,265 +0,0 @@
-/* $OpenBSD: table_proc.c,v 1.17 2021/06/14 17:58:16 eric Exp $*/
-
-/*
- * Copyright (c) 2013 Eric Faurot 
- *
- * 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 CONSEQU

table-procexec for opensmtpd (another try)

2021-10-13 Thread aisha
Hi all,
  I've made a refactored version of table-procexec,
hopefully with a lot less redundancy in code.

This patch adds the table-procexec backend which
is configured with a timeout of 500 milliseconds.
Currently this is hardcoded, but that is easy enough to
change and shouldnt be the holdback.

In case a table times out and the response has not reached
smtpd, this sets the table status to indicate that and
also starts an event to discard the next line coming on the socket.
After which we are "clear" for communication.

Comments would be very welcome and testing even more so.
I am not the most proficient C coder...

Cheers,
Aisha


diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y
index 832f4f2aec9..ff7b9a9a340 100644
--- a/usr.sbin/smtpd/parse.y
+++ b/usr.sbin/smtpd/parse.y
@@ -2543,13 +2543,6 @@ table: TABLE STRING STRING   {
config  = p+1;
}
}
-   if (config != NULL && *config != '/') {
-   yyerror("invalid backend parameter for table: 
%s",
-   $2);
-   free($2);
-   free($3);
-   YYERROR;
-   }
table = table_create(conf, backend, $2, config);
if (!table_config(table)) {
yyerror("invalid configuration file %s for 
table %s",
diff --git a/usr.sbin/smtpd/smtpctl/Makefile b/usr.sbin/smtpd/smtpctl/Makefile
index ef8148be8c9..46831d647dc 100644
--- a/usr.sbin/smtpd/smtpctl/Makefile
+++ b/usr.sbin/smtpd/smtpctl/Makefile
@@ -47,7 +47,7 @@ SRCS+=table.c
 SRCS+= table_static.c
 SRCS+= table_db.c
 SRCS+= table_getpwnam.c
-SRCS+= table_proc.c
+SRCS+= table_procexec.c
 SRCS+= unpack_dns.c
 SRCS+= spfwalk.c
 
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index e6fc114d0a6..8ef80add4e7 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1663,6 +1663,7 @@ int table_regex_match(const char *, const char *);
 void   table_open_all(struct smtpd *);
 void   table_dump_all(struct smtpd *);
 void   table_close_all(struct smtpd *);
+const char *table_service_name(enum table_service );
 
 
 /* to.c */
diff --git a/usr.sbin/smtpd/smtpd/Makefile b/usr.sbin/smtpd/smtpd/Makefile
index b31d4e42224..64e73c3bb70 100644
--- a/usr.sbin/smtpd/smtpd/Makefile
+++ b/usr.sbin/smtpd/smtpd/Makefile
@@ -62,7 +62,7 @@ SRCS+=compress_gzip.c
 
 SRCS+= table_db.c
 SRCS+= table_getpwnam.c
-SRCS+= table_proc.c
+SRCS+= table_procexec.c
 SRCS+= table_static.c
 
 SRCS+= queue_fs.c
diff --git a/usr.sbin/smtpd/table.c b/usr.sbin/smtpd/table.c
index 7328cf5df6e..81102ef90e1 100644
--- a/usr.sbin/smtpd/table.c
+++ b/usr.sbin/smtpd/table.c
@@ -35,9 +35,8 @@ struct table_backend *table_backend_lookup(const char *);
 extern struct table_backend table_backend_static;
 extern struct table_backend table_backend_db;
 extern struct table_backend table_backend_getpwnam;
-extern struct table_backend table_backend_proc;
+extern struct table_backend table_backend_procexec;
 
-static const char * table_service_name(enum table_service);
 static int table_parse_lookup(enum table_service, const char *, const char *,
 union lookup *);
 static int parse_sockaddr(struct sockaddr *, int, const char *);
@@ -48,7 +47,7 @@ static struct table_backend *backends[] = {
&table_backend_static,
&table_backend_db,
&table_backend_getpwnam,
-   &table_backend_proc,
+   &table_backend_procexec,
NULL
 };
 
@@ -67,7 +66,7 @@ table_backend_lookup(const char *backend)
return NULL;
 }
 
-static const char *
+const char *
 table_service_name(enum table_service s)
 {
switch (s) {
@@ -198,10 +197,9 @@ table_create(struct smtpd *conf, const char *backend, 
const char *name,
PATH_LIBEXEC"/table-%s\"", backend);
}
if (stat(path, &sb) == 0) {
-   tb = table_backend_lookup("proc");
-   (void)strlcpy(path, backend, sizeof(path));
+   tb = table_backend_lookup("proc-exec");
if (config) {
-   (void)strlcat(path, ":", sizeof(path));
+   (void)strlcat(path, " ", sizeof(path));
if (strlcat(path, config, sizeof(path))
>= sizeof(path))
fatalx("table_create: config file path 
too long");
diff --git a/usr.sbin/smtpd/table_proc.c b/usr.sbin/smtpd/table_proc.c
deleted file mode 100644
index 56893a0fb61..000
--- a/usr.sbin/smtpd/table_proc.c
+++ /dev/null
@@ -1,265 +0,0 @@
-/* $OpenBSD: table_proc.c,v 1.17 2021/06/14 17:58:16 eric Exp $*/
-
-/*
- * Copyrig