On Sun, Dec 20, 2020 at 07:58:56PM +0100, Martijn van Duren wrote:
> Playing around with the filter API I want an easier way to send mail
> with authentication instead of doing the transaction manually via
> openssl or via bloated mailclients. Turns out we already have all the
> plumbing in place and just need to hook it up.
> 
> OK?

ok eric@

> martijn@
> 
> Index: smtpc.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/smtpd/smtpc.c,v
> retrieving revision 1.11
> diff -u -p -r1.11 smtpc.c
> --- smtpc.c   14 Sep 2020 18:32:11 -0000      1.11
> +++ smtpc.c   20 Dec 2020 18:57:13 -0000
> @@ -56,9 +56,8 @@ usage(void)
>  {
>       extern char *__progname;
>  
> -     fprintf(stderr,
> -         "usage: %s [-Chnv] [-F from] [-H helo] [-s server] [-S name] rcpt 
> ...\n",
> -         __progname);
> +     fprintf(stderr, "usage: %s [-Chnv] [-F from] [-H helo] [-a authfile] "
> +         "[-s server] [-S name] rcpt ...\n", __progname);
>       exit(1);
>  }
>  
> @@ -66,8 +65,12 @@ int
>  main(int argc, char **argv)
>  {
>       char hostname[256];
> +     FILE *authfile;
>       int ch, i;
>       char *server = "localhost";
> +     char *authstr = NULL;
> +     size_t alloc = 0;
> +     ssize_t len;
>       struct passwd *pw;
>  
>       log_init(1, 0);
> @@ -91,7 +94,7 @@ main(int argc, char **argv)
>       memset(&mail, 0, sizeof(mail));
>       mail.from = pw->pw_name;
>  
> -     while ((ch = getopt(argc, argv, "CF:H:S:hns:v")) != -1) {
> +     while ((ch = getopt(argc, argv, "CF:H:S:a:hns:v")) != -1) {
>               switch (ch) {
>               case 'C':
>                       params.tls_verify = 0;
> @@ -107,6 +110,23 @@ main(int argc, char **argv)
>                       break;
>               case 'h':
>                       usage();
> +                     break;
> +             case 'a':
> +                     if ((authfile = fopen(optarg, "r")) == NULL)
> +                             fatal("%s: open", optarg);
> +                     if ((len = getline(&authstr, &alloc, authfile)) == -1)
> +                             fatal("%s: Failed to read username", optarg);
> +                     if (authstr[len - 1] == '\n')
> +                             authstr[len - 1] = '\0';
> +                     params.auth_user = authstr;
> +                     authstr = NULL;
> +                     len = 0;
> +                     if ((len = getline(&authstr, &alloc, authfile)) == -1)
> +                             fatal("%s: Failed to read password", optarg);
> +                     if (authstr[len - 1] == '\n')
> +                             authstr[len - 1] = '\0';
> +                     params.auth_pass = authstr;
> +                     fclose(authfile);
>                       break;
>               case 'n':
>                       noaction = 1;
> Index: smtp.1
> ===================================================================
> RCS file: /cvs/src/usr.sbin/smtpd/smtp.1,v
> retrieving revision 1.7
> diff -u -p -r1.7 smtp.1
> --- smtp.1    4 Jul 2018 08:23:43 -0000       1.7
> +++ smtp.1    20 Dec 2020 18:57:13 -0000
> @@ -25,6 +25,7 @@
>  .Op Fl Chnv
>  .Op Fl F Ar from
>  .Op Fl H Ar helo
> +.Op Fl a Ar authfile
>  .Op Fl s Ar server
>  .Op Ar recipient ...
>  .Sh DESCRIPTION
> @@ -49,6 +50,13 @@ Set the return-path (MAIL FROM) for the 
>  Default to the current username.
>  .It Fl H Ar helo
>  Define the hostname to advertise (HELO) when establishing the SMTP session.
> +.It Fl a Ar authfile
> +Perform a login before sending the message.
> +The username and password are read from
> +.Ar authfile
> +and need to be on the first and second line respectively.
> +This option requires a TLS or STARTTLS
> +.Ar server .
>  .It Fl h
>  Display version and usage.
>  .It Fl n
> 
> 
> 

Reply via email to