[2021-10-18 11:09] Jonathan Gray <[email protected]>
> On Sun, Oct 17, 2021 at 04:23:50PM +0200, Philipp wrote:
> > Hello
> >
> > I'm currently working on getting OpenSMTPD-portable build. During this
> > I found some missing includes.
>
> It would help if you could describe the platform you are building on and
> show the compile errors.
Oh sorry, I currently work on Debian and FreeBSD.
Error on Debian 11.1 with clang-11:
======================================================
clang-11 -DHAVE_CONFIG_H -I. -I../.. -I../../usr.sbin/smtpd
-I../../openbsd-compat -I../../openbsd-compat/err_h
-I../../openbsd-compat/libasr -I. -I/usr/include
-DSMTPD_CONFDIR=\"/usr/local/etc\" -DPATH_CHROOT=\"/var/empty\"
-DPATH_SMTPCTL=\"/usr/local/sbin/smtpctl\"
-DPATH_MAILLOCAL=\"/usr/local/libexec/opensmtpd/mail.local\"
-DPATH_MAKEMAP=\"/usr/local/sbin/makemap\"
-DPATH_LIBEXEC=\"/usr/local/libexec/opensmtpd\" -DHAVE_CONFIG_H -DNO_IO
-DCONFIG_MINIMUM -DPATH_GZCAT=\"/bin/zcat\"
-DPATH_ENCRYPT=\"/usr/local/libexec/opensmtpd/encrypt\" -g -O2 -fPIC -DPIC
-Qunused-arguments -Wunknown-warning-option -Wall -Wpointer-arith
-Wuninitialized -Wsign-compare -Wformat-security -Wsizeof-pointer-memaccess
-Wno-pointer-sign -Wno-unused-result -fno-strict-aliasing -fno-builtin-memset
-D_BSD_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -c -o
../../usr.sbin/smtpd/smtpctl-smtpctl.o `test -f
'../../usr.sbin/smtpd/smtpctl.c' || echo './'`../../usr.sbin/smtpd/smtpctl.c
../../usr.sbin/smtpd/smtpctl.c:519:7: warning: implicit declaration of function
'setgroups' is invalid in C99 [-Wimplicit-function-declaration]
if ((setgroups(1, &pw->pw_gid) ||
^
../../usr.sbin/smtpd/smtpctl.c:1067:12: warning: implicit declaration of
function 'getgrnam' is invalid in C99 [-Wimplicit-function-declaration]
if ((gr = getgrnam(SMTPD_QUEUE_GROUP)) == NULL)
^
../../usr.sbin/smtpd/smtpctl.c:1067:10: warning: incompatible integer to
pointer conversion assigning to 'struct group *' from 'int' [-Wint-conversion]
if ((gr = getgrnam(SMTPD_QUEUE_GROUP)) == NULL)
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../usr.sbin/smtpd/smtpctl.c:1069:13: error: incomplete definition of type
'struct group'
else if (gr->gr_gid != getegid())
~~^
../../usr.sbin/smtpd/smtpctl.c:1058:9: note: forward declaration of 'struct
group'
struct group *gr;
^
3 warnings and 1 error generated.
======================================================
The include grp.h fixes the build, with some other portable specific
changes:
https://github.com/OpenSMTPD/OpenSMTPD/pull/1153
https://github.com/OpenSMTPD/OpenSMTPD/pull/1154
First error on FreeBSD 13.0-RELEASE-p4 with clang12:
======================================================
clang12 -DHAVE_CONFIG_H -I. -I../.. -I../../usr.sbin/smtpd
-I../../openbsd-compat -I../../openbsd-compat/err_h
-I../../openbsd-compat/paths_h -I../../openbsd-compat/libtls -I.
-DSMTPD_CONFDIR=\"/usr/local/etc\"
-DPATH_CHROOT=\"/var/empty\"
-DPATH_SMTPCTL=\"/usr/local/sbin/smtpctl\"
-DPATH_MAILLOCAL=\"/usr/local/libexec/opensmtpd/mail.local\"
-DPATH_MAKEMAP=\"/usr/local/sbin/makemap\"
-DPATH_LIBEXEC=\"/usr/local/libexec/opensmtpd\" -DHAVE_CONFIG_H
-I/usr/local/include -DIO_TLS -DCA_FILE=\"/etc/ssl/cert.pem\"
-I/usr/local/include -fPIC -DPIC -Qunused-arguments -Wunknown-warning-option
-Wall -Wpointer-arith -Wuninitialized -Wsign-compare -Wformat-security
-Wsizeof-pointer-memaccess -Wno-pointer-sign -Wno-unused-result
-fno-strict-aliasing -fno-builtin-memset -c -o
../../usr.sbin/smtpd/smtpd-parse.o `test -f '../../usr.sbin/smtpd/parse.c' ||
echo './'`../../usr.sbin/smtpd/parse.c
../../usr.sbin/smtpd/parse.y:2639:2: warning: implicitly declaring library
function 'free' with type 'void (void *)' [-Wimplicit-function-declaration]
free(msg);
^
../../usr.sbin/smtpd/parse.y:2639:2: note: include the header <stdlib.h> or
explicitly provide a declaration for 'free'
../../usr.sbin/smtpd/parse.y:2646:10: warning: implicitly declaring library
function 'strcmp' with type 'int (const char *, const char *)'
[-Wimplicit-function-declaration]
return (strcmp(k, ((const struct keywords *)e)->k_name));
^
../../usr.sbin/smtpd/parse.y:2646:10: note: include the header <string.h> or
explicitly provide a declaration for 'strcmp'
../../usr.sbin/smtpd/parse.y:2758:6: warning: implicit declaration of function
'bsearch' is invalid in C99 [-Wimplicit-function-declaration]
p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]),
^
../../usr.sbin/smtpd/parse.y:2758:4: warning: incompatible integer to pointer
conversion assigning to 'const struct keywords *' from 'int' [-Wint-conversion]
p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]),
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../usr.sbin/smtpd/parse.y:2845:13: warning: implicit declaration of function
'reallocarray' is invalid in C99 [-Wimplicit-function-declaration]
void *p = reallocarray(file->ungetbuf, file->ungetsize, 2);
^
../../usr.sbin/smtpd/parse.y:2845:9: warning: incompatible integer to pointer
conversion initializing 'void *' with an expression of type 'int'
[-Wint-conversion]
void *p = reallocarray(file->ungetbuf, file->ungetsize, 2);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../usr.sbin/smtpd/parse.y:2911:13: warning: implicitly declaring library
function 'strlen' with type 'unsigned long (const char *)'
[-Wimplicit-function-declaration]
p = val + strlen(val) - 1;
^
../../usr.sbin/smtpd/parse.y:2911:13: note: include the header <string.h> or
explicitly provide a declaration for 'strlen'
../../usr.sbin/smtpd/parse.y:2955:21: warning: implicitly declaring library
function 'strdup' with type 'char *(const char *)'
[-Wimplicit-function-declaration]
yylval.v.string = strdup(buf);
^
../../usr.sbin/smtpd/parse.y:2955:21: note: include the header <string.h> or
explicitly provide a declaration for 'strdup'
../../usr.sbin/smtpd/parse.y:2979:22: warning: implicit declaration of function
'strtonum' is invalid in C99 [-Wimplicit-function-declaration]
yylval.v.number = strtonum(buf, LLONG_MIN,
^
../../usr.sbin/smtpd/parse.y:3059:15: warning: implicitly declaring library
function 'calloc' with type 'void *(unsigned long, unsigned long)'
[-Wimplicit-function-declaration]
if ((nfile = calloc(1, sizeof(struct file))) == NULL) {
^
../../usr.sbin/smtpd/parse.y:3059:15: note: include the header <stdlib.h> or
explicitly provide a declaration for 'calloc'
../../usr.sbin/smtpd/parse.y:3082:20: warning: implicitly declaring library
function 'malloc' with type 'void *(unsigned long)'
[-Wimplicit-function-declaration]
nfile->ungetbuf = malloc(nfile->ungetsize);
^
../../usr.sbin/smtpd/parse.y:3082:20: note: include the header <stdlib.h> or
explicitly provide a declaration for 'malloc'
../../usr.sbin/smtpd/parse.y:3136:3: warning: implicit declaration of function
'memset' is invalid in C99 [-Wimplicit-function-declaration]
memset(&listen_opts, 0, sizeof listen_opts);
^
../../usr.sbin/smtpd/parse.y:3212:13: warning: implicitly declaring library
function 'strrchr' with type 'char *(const char *, int)'
[-Wimplicit-function-declaration]
if ((val = strrchr(s, '=')) == NULL)
^
../../usr.sbin/smtpd/parse.y:3212:13: note: include the header <string.h> or
explicitly provide a declaration for 'strrchr'
../../usr.sbin/smtpd/parse.y:3214:8: warning: implicitly declaring library
function 'strndup' with type 'char *(const char *, unsigned long)'
[-Wimplicit-function-declaration]
sym = strndup(s, val - s);
^
../../usr.sbin/smtpd/parse.y:3214:8: note: include the header <string.h> or
explicitly provide a declaration for 'strndup'
../../usr.sbin/smtpd/parse.y:3313:9: warning: implicitly declaring library
function 'strlcpy' with type 'unsigned long (char *, const char *, unsigned
long)' [-Wimplicit-function-declaration]
(void)strlcpy(h->filter_name,
^
../../usr.sbin/smtpd/parse.y:3313:9: note: include the header <string.h> or
explicitly provide a declaration for 'strlcpy'
../../usr.sbin/smtpd/parse.y:3387:2: warning: implicit declaration of function
'memset' is invalid in C99 [-Wimplicit-function-declaration]
memset(&ina, 0, sizeof(ina));
^
../../usr.sbin/smtpd/parse.y:3417:2: warning: implicit declaration of function
'memset' is invalid in C99 [-Wimplicit-function-declaration]
memset(&ina6, 0, sizeof(ina6));
^
../../usr.sbin/smtpd/parse.y:3428:2: warning: implicitly declaring library
function 'memcpy' with type 'void *(void *, const void *, unsigned long)'
[-Wimplicit-function-declaration]
memcpy(&sin6->sin6_addr, &ina6, sizeof(ina6));
^
../../usr.sbin/smtpd/parse.y:3428:2: note: include the header <string.h> or
explicitly provide a declaration for 'memcpy'
../../usr.sbin/smtpd/parse.y:3446:2: warning: implicit declaration of function
'memset' is invalid in C99 [-Wimplicit-function-declaration]
memset(&hints, 0, sizeof(hints));
^
../../usr.sbin/smtpd/parse.y:3603:10: warning: implicit declaration of function
'strtonum' is invalid in C99 [-Wimplicit-function-declaration]
delay = strtonum(str, 1, INT_MAX / factor, &errstr);
^
In file included from ../../usr.sbin/smtpd/parse.c:2281:
/usr/include/stdlib.h:96:7: error: conflicting types for 'bsearch'
void *bsearch(const void *, const void *, size_t,
^
../../usr.sbin/smtpd/parse.y:2758:6: note: previous implicit declaration is here
p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]),
^
In file included from ../../usr.sbin/smtpd/parse.c:2281:
/usr/include/stdlib.h:316:7: error: conflicting types for 'reallocarray'
void *reallocarray(void *, size_t, size_t) __result_use_check
^
../../usr.sbin/smtpd/parse.y:2845:13: note: previous implicit declaration is
here
void *p = reallocarray(file->ungetbuf, file->ungetsize, 2);
^
In file included from ../../usr.sbin/smtpd/parse.c:2281:
/usr/include/stdlib.h:325:2: error: conflicting types for 'strtonum'
strtonum(const char *, long long, long long, const char **);
^
../../usr.sbin/smtpd/parse.y:2979:22: note: previous implicit declaration is
here
yylval.v.number = strtonum(buf, LLONG_MIN,
^
In file included from ../../usr.sbin/smtpd/parse.c:2282:
/usr/include/string.h:69:7: error: conflicting types for 'memset'
void *memset(void *, int, size_t);
^
../../usr.sbin/smtpd/parse.y:3136:3: note: previous implicit declaration is here
memset(&listen_opts, 0, sizeof listen_opts);
^
20 warnings and 4 errors generated.
======================================================
The include of stdlib.h and string.h fix this.
Later in the build the same error as in Debian ocour:
======================================================
clang12 -DHAVE_CONFIG_H -I. -I../.. -I../../usr.sbin/smtpd
-I../../openbsd-compat -I../../openbsd-compat/err_h -I. -I/usr/local/include
-DSMTPD_CONFDIR=\"/usr/local/etc\" -DPATH_CHROOT=\"/var/empty\"
-DPATH_SMTPCTL=\"/usr/local/sbin/smtpctl\"
-DPATH_MAILLOCAL=\"/usr/local/libexec/opensmtpd/mail.local\"
-DPATH_MAKEMAP=\"/usr/local/sbin/makemap\"
-DPATH_LIBEXEC=\"/usr/local/libexec/opensmtpd\" -DHAVE_CONFIG_H -DNO_IO
-DCONFIG_MINIMUM -DPATH_GZCAT=\"/usr/bin/zcat\"
-DPATH_ENCRYPT=\"/usr/local/libexec/opensmtpd/encrypt\" -I/usr/local/include
-fPIC -DPIC -Qunused-arguments -Wunknown-warning-option -Wall -Wpointer-arith
-Wuninitialized -Wsign-compare -Wformat-security -Wsizeof-pointer-memaccess
-Wno-pointer-sign -Wno-unused-result -fno-strict-aliasing -fno-builtin-memset
-D_GNU_SOURCE -c -o ../../usr.sbin/smtpd/smtpctl-smtpctl.o `test -f
'../../usr.sbin/smtpd/smtpctl.c' || echo './'`../../usr.sbin/smtpd/smtpctl.c
../../usr.sbin/smtpd/smtpctl.c:1067:12: warning: implicit declaration of
function 'getgrnam' is invalid in C99 [-Wimplicit-function-declaration]
if ((gr = getgrnam(SMTPD_QUEUE_GROUP)) == NULL)
^
../../usr.sbin/smtpd/smtpctl.c:1067:10: warning: incompatible integer to
pointer conversion assigning to 'struct group *' from 'int' [-Wint-conversion]
if ((gr = getgrnam(SMTPD_QUEUE_GROUP)) == NULL)
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../usr.sbin/smtpd/smtpctl.c:1069:13: error: incomplete definition of type
'struct group'
else if (gr->gr_gid != getegid())
~~^
../../usr.sbin/smtpd/smtpctl.c:1058:9: note: forward declaration of 'struct
group'
struct group *gr;
^
2 warnings and 1 error generated.
*** Error code 1
Stop.
======================================================
The same solution as on Debian worked. To fix the build on FreeBSD I
also removed the IN6_IS_ADDR_MC_INTFACELOCAL() in parse.y and config.c.
See my other mail for details.
Philipp
> >
> > diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y
> > index 7de52a1c568..b1307c4daa6 100644
> > --- a/usr.sbin/smtpd/parse.y
> > +++ b/usr.sbin/smtpd/parse.y
> > @@ -28,6 +28,8 @@
> > #include <net/if.h>
> > #include <netinet/in.h>
> >
> > +#include <stdlib.h>
> > +#include <string.h>
> > #include <arpa/inet.h>
> > #include <ctype.h>
> > #include <errno.h>
> > diff --git a/usr.sbin/smtpd/smtpctl.c b/usr.sbin/smtpd/smtpctl.c
> > index 3d5926efdad..9e88f150ae5 100644
> > --- a/usr.sbin/smtpd/smtpctl.c
> > +++ b/usr.sbin/smtpd/smtpctl.c
> > @@ -27,6 +27,7 @@
> > #include <err.h>
> > #include <errno.h>
> > #include <fts.h>
> > +#include <grp.h>
> > #include <inttypes.h>
> > #include <pwd.h>
> > #include <stdlib.h>
> >
> >