Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Unexpected errors if smtp support is disabled (on RHEL-9) #15472

@jeroen

Description

@jeroen

RHEL 9: dual configuration

Users of the R bindings reported weird errors when sending sending emails on RHEL/Rockylinux version 9. It turns out the folks at Redhat have packaged libcurl in a unusual way.

RHEL version 9 ships a single curl-devel package, but two different libcurl runtime builds. The default version installed on most systems is called libcurl-minimal and it disables several protocols including smtp. An alternative more complete build is available in the libcurl package, but most servers don't have this installed.

The problem

When a user of libcurl bindings has the libcurl-minimal package (which does not support smtp) installed on the server, we see the following behavior:

  • Setting CURLOPT_URL to a smtp:// url does not error
  • The curl_easyoption option API makes it seem CURLOPT_MAIL_RCPT is supported, however:
  • Setting the CURLOPT_MAIL_RCPT gives a confusing error message An unknown option was passed in to libcurl

Example program

An example test.c program to demonstrate this:

#include <stdio.h>
#include <string.h>
#include <curl/curl.h>
 
int main(void){
  curl_global_init(CURL_GLOBAL_DEFAULT);
  CURL *curl = curl_easy_init();
  CURLcode err = 0;

  // Check if SMTP supported is enabled
  int has_smtp = 0;
  const curl_version_info_data *data = curl_version_info(CURLVERSION_NOW);
  const char *const * temp = data->protocols;
  while(*++temp)
    if(strcmp(*temp, "smtp") == 0) has_smtp=1;
  printf("SMTP support: %s\n", has_smtp ? "YES" : "NO");

  // Test if CURLOPT_MAIL_RCPT exists
  const struct curl_easyoption *o = curl_easy_option_by_id(CURLOPT_MAIL_RCPT);
  printf("Found %s: type %d flags %d\n", o->name, o->type, o->flags);

  // should this not error if smtp is not supported?
  err = curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.com");
  printf("Setting CURLOPT_URL: %s\n",curl_easy_strerror(err));

  struct curl_slist *recipients = NULL;
  recipients = curl_slist_append(recipients, "<[email protected]>");
  err = curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
  printf("Setting CURLOPT_MAIL_RCPT: %s\n",curl_easy_strerror(err));
  return 0;
}

You can easily run a RHEL-9 container in docker:

docker run --rm -it rockylinux/rockylinux:9

Then in docker you need to install the compiler and curl headers:

dnf install -y gcc curl-devel
gcc test.c -lcurl
./a.out

curl/libcurl version

curl 7.76.1 (x86_64-redhat-linux-gnu) libcurl/7.76.1 OpenSSL/3.0.7 zlib/1.2.11 nghttp2/1.43.0

operating system

Redhat 9 / RockyLinux 9

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions