Giter VIP home page Giter VIP logo

libasr's Introduction

OpenSMTPD

Version Coverity Scan analysis Packaging status License: ISC

Warning This repository may be out of date compared to OpenBSD smtpd source code. Downstream package maintainers should be aware of this when backporting security fixes and other changes.

OpenSMTPD is a FREE implementation of the server-side SMTP protocol as defined by RFC 5321, with some additional standard extensions.

It allows ordinary machines to exchange e-mails with other systems speaking the SMTP protocol.

OpenSMTPD runs on various Unix and Unix-like operating systems including:

For more information: http://www.opensmtpd.org/portable.html

If you are looking for a comprehensive manual on how to build your own mail server visit our wiki.

Get in touch

If you want to stay up to day with most recent developments or chat about OpenSMTPD you can:

Documentation

The manual pages are available online, which you are encouraged to contribute to.

Install via package manager

Many distributions already provide a packaged version of opensmtpd. All you need to do is install it via your package manager.

Warning Some distributions might ship old versions of OpenSMTPD, and some distributions may selectively backport security fixes and other code changes.

Debian/Ubuntu

sudo apt install opensmtpd

Archlinux

Has a dedicated wiki page

Alpine Linux

apk install opensmtpd

Fedora

yum install opensmtpd

macOS

OpenSMTPD is available from MacPorts:

port install opensmtpd

Install via container

Container images available at this repo's packages page.

Install from source

Install dependencies

OpenSMTPD relies on:

When not building from a release tarball (e.g. from the git repository), the following dependencies are needed too:

By default OpenSMTPD expects latest versions of all dependencies unless noted otherwise.

Note that some distributions have different packages for a same library, you should always use the -dev or -devel package (for example, libevent-dev or libevent-devel) if you're going to build OpenSMTPD yourself.

Get the source code

Clone from github:

git clone https://github.com/OpenSMTPD/OpenSMTPD.git

Download tarball

Latest release can always be found here

Compile

cd opensmtpd*
./bootstrap  # Only if you build from git sources
./configure
make
sudo make install

Special notes for macOS

Please launch configure with special directive about libevent directory:

./configure --with-libevent=/opt/local

Though macOS includes a copy of bison in the bases system, you will need to install a more recent version from, e.g., MacPorts.

Install

sudo make install

Setup historical interface

OpenSMTPD provides a single utility smtpctl to control the daemon and the local submission subsystem.

To accomodate systems that require historical interfaces such as sendmail, newaliases or makemap, the smtpctl utility can operate in compatibility mode if called with the historical name.

On mailwrapper-enabled systems, this is achieved by editing /etc/mailer.conf and adding the following lines:

sendmail        /usr/sbin/smtpctl
send-mail       /usr/sbin/smtpctl
mailq           /usr/sbin/smtpctl
makemap         /usr/sbin/smtpctl
newaliases      /usr/sbin/smtpctl

Whereas on systems that don't provide mailwrapper, it can be achieved by setting the appropriate symbolic links:

ln -s /usr/sbin/smtpctl sendmail
ln -s /usr/sbin/smtpctl send-mail
ln -s /usr/sbin/smtpctl mailq
ln -s /usr/sbin/smtpctl makemap
ln -s /usr/sbin/smtpctl newaliases

The OpenSMTPD project leaves it up to the package maintainers to setup the links in their packages as it is very hard for us to accommodate all systems with the preferred method in a clean way.

Configure /etc/smtpd.conf

Please have a look at the complete format description of smtpd.conf configuration file

Add OpenSMTPD users

To operate, OpenSMTPD requires at least one user, by default _smtpd; and preferably two users, by default _smtpd and _smtpq.

Using two users instead of one will increase security by a large factor so... if you want to voluntarily reduce security or you have absolute more faith in our code than we do, by all means use one.

The instructions below assume the default users however, the configure script allows overriding these using the options: --with-user-smtpd, --with-user-queue, and --with-group-queue.

NetBSD, Linux (Debian, Arch Linux, ...)

mkdir /var/empty
useradd -c "SMTP Daemon" -d /var/empty -s /sbin/nologin _smtpd
useradd -c "SMTPD Queue" -d /var/empty -s /sbin/nologin _smtpq

DragonFlyBSD, FreeBSD

pw useradd _smtpd -c "SMTP Daemon" -d /var/empty -s /sbin/nologin
pw useradd _smtpq -c "SMTPD Queue" -d /var/empty -s /sbin/nologin

macOS

First we need a group with an unused GID below 500, list the current ones used:

/usr/bin/dscl . -list /Groups PrimaryGroupID | sort -n -k2,2

Add a group - here we have picked 444:

/usr/bin/sudo /usr/bin/dscl . -create /Groups/_smtpd PrimaryGroupID 444

Then the user. Again we need an unused UID below 500, list the current ones used:

/usr/bin/dscl . -list /Users UniqueID | sort -n -k2,2

Add a user - here we have picked 444:

/usr/bin/sudo /usr/bin/dscl . -create /Users/_smtpd UniqueID 444
/usr/bin/sudo /usr/bin/dscl . -delete /Users/_smtpd AuthenticationAuthority
/usr/bin/sudo /usr/bin/dscl . -delete /Users/_smtpd PasswordPolicyOptions
/usr/bin/sudo /usr/bin/dscl . -delete /Users/_smtpd dsAttrTypeNative:KerberosKeys
/usr/bin/sudo /usr/bin/dscl . -delete /Users/_smtpd dsAttrTypeNative:ShadowHashData
/usr/bin/sudo /usr/bin/dscl . -create /Users/_smtpd RealName "SMTP Daemon"
/usr/bin/sudo /usr/bin/dscl . -create /Users/_smtpd Password "*"
/usr/bin/sudo /usr/bin/dscl . -create /Users/_smtpd PrimaryGroupID 444
/usr/bin/sudo /usr/bin/dscl . -create /Users/_smtpd NFSHomeDirectory /var/empty
/usr/bin/sudo /usr/bin/dscl . -create /Users/_smtpd UserShell /usr/bin/false

repeat for the _smtpq user.

Launch smtpd

First, kill any running sendmail/exim/qmail/postfix or other.

Then:

smtpd

or in debug and verbose mode

smtpd -dv

libasr's People

Contributors

ericfaurot avatar evadot avatar maksqwe avatar nlebedenco avatar omar-polo avatar poolporg avatar ryanakca avatar twinshadow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libasr's Issues

New release

Hello, I'm building packages for my operating system, and I could use a new release with the last modifications on the master branch.

Currently, I have an automake with version 0.16 and it's not working with the last release (but works fine with master).

Thanks!

patch: automake subdir-objects

Problem:

[...]
configure.ac:44: installing './missing'
src/Makefile.am:3: warning: source file '$(top_srcdir)/openbsd-compat/fgetln.c' is in a subdirectory,
src/Makefile.am:3: but option 'subdir-objects' is disabled
automake-1.15: warning: possible forward-incompatibility.
automake-1.15: At least a source file is in a subdirectory, but the 'subdir-objects'
automake-1.15: automake option hasn't been enabled. For now, the corresponding output
automake-1.15: object file(s) will be placed in the top-level directory. However,
automake-1.15: this behaviour will change in future Automake versions: they will
automake-1.15: unconditionally cause object files to be placed in the same subdirectory
automake-1.15: of the corresponding sources.
automake-1.15: You are advised to start using 'subdir-objects' option throughout your
automake-1.15: project, to avoid future incompatibilities.
src/Makefile.am:3: warning: source file '$(top_srcdir)/openbsd-compat/res_hnok.c' is in a subdirectory,
src/Makefile.am:3: but option 'subdir-objects' is disabled
src/Makefile.am:3: warning: source file '$(top_srcdir)/openbsd-compat/strlcat.c' is in a subdirectory,
src/Makefile.am:3: but option 'subdir-objects' is disabled
src/Makefile.am:3: warning: source file '$(top_srcdir)/openbsd-compat/strlcpy.c' is in a subdirectory,
src/Makefile.am:3: but option 'subdir-objects' is disabled
src/Makefile.am:3: warning: source file '$(top_srcdir)/openbsd-compat/strsep.c' is in a subdirectory,
src/Makefile.am:3: but option 'subdir-objects' is disabled
src/Makefile.am:3: warning: source file '$(top_srcdir)/openbsd-compat/strtonum.c' is in a subdirectory,
src/Makefile.am:3: but option 'subdir-objects' is disabled
src/Makefile.am: installing './depcomp'
[...]

Patch:

perl -i.bak -ple 's|^AM_INIT_AUTOMAKE$|AM_INIT_AUTOMAKE([subdir-objects])|' configure.ac;

Result:

[...]
configure.ac:44: installing './missing'
src/Makefile.am: installing './depcomp'

  • rm -Rf autom4te.cache
    [...]

Comments:
no comment

Using AI_CANONNAME on systems that do not defined AI_FQDN causes BADFLAGS error

Executing the following test code in Alpine Linux will result in a BADFLAGS error.

#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <asr.h>

int main() {
    struct asr_query *query;
    struct asr_result result;
    struct addrinfo hints;
    const char *hostname = "www.yahoo.co.jp";

    memset(&hints, 0, sizeof(hints));
    hints.ai_flags = AI_CANONNAME;
    query = getaddrinfo_async(hostname, NULL, &hints, NULL);
    asr_run_sync(query, &result);
    if (errno != 0) {
        printf("asr run error: %s\n", strerror(errno));
        return 1;
    } else if (result.ar_gai_errno) {
        printf("gataddrinfo error: %s\n", gai_strerror(result.ar_gai_errno));
        return 1;
    }
    return 0;
}
$ cc test.c -lasr
$ ./a.out 
gataddrinfo error: Invalid flags

Only of the AI_CANONNAME and AI_FQDN bits can be set, Only the AI_CANONNAME and AI_FQDN bits can be set, and are verified in getaddrinfo_async_run() as follows:

if (ai->ai_flags & ~AI_MASK ||
(ai->ai_flags & AI_CANONNAME && ai->ai_flags & AI_FQDN)) {
ar->ar_gai_errno = EAI_BADFLAGS;
async_set_state(as, ASR_STATE_HALT);
break;
}

However, on systems such as Linux with musl that do not define AI_FQDN, it is defined as AI_CANONNAME at build time:

libasr/src/asr_compat.h

Lines 42 to 44 in 15fdb71

#ifndef AI_FQDN
#define AI_FQDN AI_CANONNAME
#endif

Add res_randomid

libasr has copied many resolver functions from OpenBSD. However the function res_randomid(), which is used in res_send_async() and res_mkquery() seems to have been forgotten.

Because of this libasr currently only works with glibc and uclibc>=0.9.33 as these libc's provide the function. It however seems to be a non-standard function with no real documentation.

Could res_randomid() be provided, inclusion possibly depending on a configure test?

Build fails on Slackware 14.2

Hi

I'm trying to build libasr master, which fails, unlike when building version 1.0.2.

The goal is to be able to build OpenSMTPD with all the latest tweaks and features for testing, rather than working with stable and then having to change things when the next stable is out.

Is it absolutely necessary to be using master for libasr in order to build master for OpenSMTPD at this point?

$ git clone git://github.com/OpenSMTPD/libasr.git
$ cd libasr
$ ./bootstrap
$ CFLAGS="-O2 -fPIC -fstack-protector" CXXFLAGS="-O2 -fPIC -fstack-protector" ./configure --prefix=/pkg/libasr/20180820 --enable-static=no --build=x86_64-slackware-linux
$ make
make  all-recursive
make[1]: Entering directory `/home/admin/src/opensmtpd/libasr/libasr'
Making all in src
make[2]: Entering directory `/home/admin/src/opensmtpd/libasr/libasr/src'
Makefile:414: ../openbsd-compat/.deps/libasr_la-clock_gettime.Plo: No such file or directory
Makefile:415: ../openbsd-compat/.deps/libasr_la-fgetln.Plo: No such file or directory
Makefile:416: ../openbsd-compat/.deps/libasr_la-reallocarray.Plo: No such file or directory
Makefile:417: ../openbsd-compat/.deps/libasr_la-res_hnok.Plo: No such file or directory
Makefile:418: ../openbsd-compat/.deps/libasr_la-strlcat.Plo: No such file or directory
Makefile:419: ../openbsd-compat/.deps/libasr_la-strlcpy.Plo: No such file or directory
Makefile:420: ../openbsd-compat/.deps/libasr_la-strsep.Plo: No such file or directory
Makefile:421: ../openbsd-compat/.deps/libasr_la-strtonum.Plo: No such file or directory
make[2]: *** No rule to make target `../openbsd-compat/.deps/libasr_la-strtonum.Plo'.  Stop.
make[2]: Leaving directory `/home/admin/src/opensmtpd/libasr/libasr/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/admin/src/opensmtpd/libasr/libasr'
make: *** [all] Error 2

I'm unfamiliar with building Makefiles, so unsure where to begin looking for this issue.

Could someone take a peek at this or point me in the right direction?

Thanks

Incorrect compat definition of NETDB_SUCCESS

On systems such as Linux with musl that do not define NETDB_SUCCESS, the definition from openbsd-compat/defines.h is used. This definition uses the wrong number, -1, which is defined immediately above to signify an internal error. OpenSMTPD expects the value to be zero on success, which matches the glibc definition. As it is now, this causes all DNS lookups in OpenSMTPD to hit the failure case here, and so mail fails to relay with smtp-out: Failed to resolve MX for [relay:domain.tld]: Temporary failure in MX lookup.

There is an appropriate patch here in #10

libasr 1.0.3 lacks an explicit_bzero replacement function if it's missing

I tried to built opensmtpd 6.6.1p1 on CentOS 7, but it exited with the following error:

...
checking for asr.h... yes
checking for asr_run in -lasr... no
configure: error: *** libasr missing - please install first or check config.log ***

I had already successfuly built libasr 1.0.3 from git OpenSMTPD/libasr and added it to ldconfig by writing a config file /etc/ld.so.conf.d/libasr.conf with the following content: /usr/local/lib/; and then running $ sudo ldconfig.

$ ldconfig -p | grep libasr shows:
libasr.so.0 (libc6,x86-64) => /usr/local/lib/libasr.so.0
libasr.so (libc6,x86-64) => /usr/local/lib/libasr.so

Here is the config.log from attempting the OpenSMTPd ./configure step.

The error in there is: .../builds/opensmtpd/conftest.c:133: undefined reference to explicit_bzero'` on line 10988.

1.0.4: gcc 10 comile time warnings

It would be good to clean those warnings.

asr.c: In function '_asr_strdname':
asr.c:789:31: warning: pointer targets in initialization of 'const unsigned char *' from 'const char *' differ in signedness [-Wpointer-sign]
  789 |  const unsigned char *dname = _dname;
      |                               ^~~~~~
In file included from asr_private.h:20,
                 from asr.c:39:
At top level:
asr_compat.h:22:26: warning: '__thread_name__asr' defined but not used [-Wunused-variable]
   22 | #define __THREAD_NAME(x) __thread_name_ ## x
      |                          ^~~~~~~~~~~~~~
asr.c:61:14: note: in expansion of macro '__THREAD_NAME'
   61 | static void *__THREAD_NAME(_asr);
      |              ^~~~~~~~~~~~~
res_send_async.c: In function 'res_send_async':
res_send_async.c:80:23: warning: pointer targets in passing argument 2 of '_asr_unpack_init' differ in signedness [-Wpointer-sign]
   80 |  _asr_unpack_init(&p, buf, buflen);
      |                       ^~~
      |                       |
      |                       const unsigned char *
In file included from res_send_async.c:39:
asr_private.h:296:44: note: expected 'const char *' but argument is of type 'const unsigned char *'
  296 | void _asr_unpack_init(struct asr_unpack *, const char *, size_t);
      |                                            ^~~~~~~~~~~~
res_send_async.c: In function 'setup_query':
res_send_async.c:399:31: warning: pointer targets in passing argument 2 of '_asr_pack_init' differ in signedness [-Wpointer-sign]
  399 |  _asr_pack_init(&p, as->as.dns.obuf, as->as.dns.obufsize);
      |                     ~~~~~~~~~~^~~~~
      |                               |
      |                               unsigned char *
In file included from res_send_async.c:39:
asr_private.h:292:40: note: expected 'char *' but argument is of type 'unsigned char *'
  292 | void _asr_pack_init(struct asr_pack *, char *, size_t);
      |                                        ^~~~~~
res_send_async.c: In function 'tcp_read':
res_send_async.c:643:6: warning: pointer targets in assignment from 'unsigned char *' to 'char *' differ in signedness [-Wpointer-sign]
  643 |  pos = as->as.dns.ibuf + offset;
      |      ^
res_send_async.c: In function 'ensure_ibuf':
res_send_async.c:692:18: warning: pointer targets in assignment from 'char *' to 'unsigned char *' differ in signedness [-Wpointer-sign]
  692 |  as->as.dns.ibuf = t;
      |                  ^
res_send_async.c: In function 'validate_packet':
res_send_async.c:711:33: warning: pointer targets in passing argument 2 of '_asr_unpack_init' differ in signedness [-Wpointer-sign]
  711 |  _asr_unpack_init(&p, as->as.dns.ibuf, as->as.dns.ibuflen);
      |                       ~~~~~~~~~~^~~~~
      |                                 |
      |                                 unsigned char *
In file included from res_send_async.c:39:
asr_private.h:296:44: note: expected 'const char *' but argument is of type 'unsigned char *'
  296 | void _asr_unpack_init(struct asr_unpack *, const char *, size_t);
      |                                            ^~~~~~~~~~~~
asr_utils.c: In function 'dname_expand':
asr_utils.c:144:39: warning: pointer targets in passing argument 1 of 'dname_check_label' differ in signedness [-Wpointer-sign]
  144 |   if (dname_check_label(data + offset + 1, n) == -1)
      |                         ~~~~~~~~~~~~~~^~~
      |                                       |
      |                                       const unsigned char *
asr_utils.c:58:31: note: expected 'const char *' but argument is of type 'const unsigned char *'
   58 | dname_check_label(const char *s, size_t l)
      |                   ~~~~~~~~~~~~^
asr_utils.c: In function 'unpack_dname':
asr_utils.c:246:20: warning: pointer targets in passing argument 1 of 'dname_expand' differ in signedness [-Wpointer-sign]
  246 |  e = dname_expand(p->buf, p->len, p->offset, &p->offset, dst, max);
      |                   ~^~~~~
      |                    |
      |                    const char *
asr_utils.c:117:35: note: expected 'const unsigned char *' but argument is of type 'const char *'
  117 | dname_expand(const unsigned char *data, size_t len, size_t offset,
      |              ~~~~~~~~~~~~~~~~~~~~~^~~~
getaddrinfo_async.c: In function 'get_port':
getaddrinfo_async.c:479:18: warning: unused variable 'se' [-Wunused-variable]
  479 |  struct servent  se;
      |                  ^~

build error on OS X: conflicting types for 'snprintf'

so far I used only OpenBSD version

today, Iโ€™m trying to compile OpenSMTPD cloned from git on OS X

Darwin Kernel Version 14.4.0: Thu May 28 11:35:04 PDT 2015; root:xnu-2782.30.5~1/RELEASE_X86_64 x86_64

instructions from README.md

during make, I ended with

Making all in openbsd-compat
gcc -DHAVE_CONFIG_H -I. -I.. -I../smtpd -I../openbsd-compat -I/opt/local -I/opt/local -g -O2 -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 arc4random.o arc4random.c
In file included from arc4random.c:27:
In file included from ./includes.h:77:
./openbsd-compat.h:152:5: warning: incompatible redeclaration of library function 'snprintf' [-Wincompatible-library-redeclaration]
int snprintf(char , size_t, SNPRINTF_CONST char *, ...);
^
./openbsd-compat.h:152:5: note: 'snprintf' is a builtin with type 'int (char *, unsigned long, const char *, ...)'
1 warning generated.
gcc -DHAVE_CONFIG_H -I. -I.. -I../smtpd -I../openbsd-compat -I/opt/local -I/opt/local -g -O2 -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 base64.o base64.c
In file included from base64.c:47:
In file included from ./includes.h:77:
./openbsd-compat.h:152:5: warning: incompatible redeclaration of library function 'snprintf' [-Wincompatible-library-redeclaration]
int snprintf(char *, size_t, SNPRINTF_CONST char *, ...);
^
./openbsd-compat.h:152:5: note: 'snprintf' is a builtin with type 'int (char *, unsigned long, const char *, ...)'
In file included from base64.c:58:
/usr/include/stdio.h:421:6: error: conflicting types for 'snprintf'
int snprintf(char * __restrict, size_t, const char * __restrict, ...) __printflike(3, 4);
^
./openbsd-compat.h:152:5: note: previous declaration is here
int snprintf(char *, size_t, SNPRINTF_CONST char *, ...);
^
1 warning and 1 error generated.
make[2]: *
* [base64.o] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.