Bug #18246 compilation error with tcp_wrapper
Submitted: 15 Mar 2006 2:40 Modified: 4 Oct 2006 1:24
Reporter: Rejean Lepage Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:mysql-5.0.20-nightly-20060314 OS:Solaris (Solaris 9)
Assigned to: Jim Winstead CPU Architecture:Any
Tags: libwrap, tcp_wrapper

[15 Mar 2006 2:40] Rejean Lepage
Description:
when configured with --with-libwrap= the compilation failed due to 
wrong coding in sql/mysqld.cc at line 4013, 4014, 4022.

You should remember that tcp_wrapper does not use parameter with those functions.
extern char *eval_user();               /* client user */
extern char *eval_hostname();           /* printable hostname */
extern char *eval_hostaddr();           /* printable host address */
extern char *eval_hostinfo();           /* host name or address */
extern char *eval_client();             /* whatever is available */
extern char *eval_server();             /* whatever is available */

HERE IS THE ERROR: 

/usr/local/include/tcpd.h: In function `void* handle_connections_sockets(void*)':
/usr/local/include/tcpd.h:131: error: too many arguments to function `void sock_host()'
mysqld.cc:4013: error: at this point in file
/usr/local/include/tcpd.h:69: error: too many arguments to function `int hosts_access()'
mysqld.cc:4014: error: at this point in file
/usr/local/include/tcpd.h:124: error: too many arguments to function `char* eval_client()'
mysqld.cc:4022: error: at this point in file

How to repeat:

repeat this bug just by compiling with tcp_wrapper 
--with-libwrap=path

Suggested fix:
replace this code in sql/mysqld.cc  or just remove &req from parameter on libwrap functions fromhost() hosts_access() eval_client().

#ifdef HAVE_LIBWRAP
    {
      if (sock == ip_sock)
      {
        struct request_info req;
        signal(SIGCHLD, SIG_DFL);
        request_init(&req, RQ_DAEMON, libwrapName, RQ_FILE, new_sock, NULL);
        fromhost();
        if (!hosts_access())
        {
          /*
            This may be stupid but refuse() includes an exit(0)
            which we surely don't want...
            clean_exit() - same stupid thing ...
          */
          syslog(deny_severity, "refused connect from %s",
                 eval_client());

          /*
            C++ sucks (the gibberish in front just translates the supplied
            sink function pointer in the req structure from a void (*sink)();
            to a void(*sink)(int) if you omit the cast, the C++ compiler
            will cry...
          */
          if (req.sink)
            ((void (*)(int))req.sink)(req.fd);

          (void) shutdown(new_sock,2);
          (void) closesocket(new_sock);
          continue;
        }
      }
    }
#endif /* HAVE_LIBWRAP */
[15 Mar 2006 9:31] Hartmut Holzgraefe
you are right, the tcp_wrappers distribution header file as found on
ftp://ftp.porcupine.org/pub/security/
does not declare any arguments for these functions, but in the
RedHat EL3 /usr/include/tcpd.h it looks like this:

extern char *eval_user __P((struct request_info *));    /* client user */
extern char *eval_hostname __P((struct host_info *));   /* printable hostname */
extern char *eval_hostaddr __P((struct host_info *));   /* printable host address */
extern char *eval_hostinfo __P((struct host_info *));   /* host name or address */
extern char *eval_client __P((struct request_info *));  /* whatever is available */
extern char *eval_server __P((struct request_info *));  /* whatever is available */

and on SuSE 9.3 it looks like this:

#ifdef __STDC__
extern char *eval_user(struct request_info *);
extern char *eval_hostname(struct host_info *);
extern char *eval_hostaddr(struct host_info *);
extern char *eval_hostinfo(struct host_info *);
extern char *eval_client(struct request_info *);
extern char *eval_server(struct request_info *);
#else
extern char *eval_user();               /* client user */
extern char *eval_hostname();           /* printable hostname */
extern char *eval_hostaddr();           /* printable host address */
extern char *eval_hostinfo();           /* host name or address */
extern char *eval_client();             /* whatever is available */
extern char *eval_server();             /* whatever is available */
#endif

so it looks as if a configure test is needed for this ...
[24 Apr 2006 21:25] Sergei Golubchik
See also bug#5652 and the changeset with a bugfix:

bk changes -/#5652/
[24 May 2006 23:13] Rejean Lepage
I just tryed, You seam to have the same error in version 5.0.21.
[20 Jun 2006 23:23] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/7977
[21 Jun 2006 15:37] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/8035
[16 Aug 2006 8:34] Michal Marek
There is a bug in the new mysys/my_libwrap.c file: my_hosts_access() and 
my_eval_client() are missing the return statement.

--- mysys/my_libwrap.c
+++ mysys/my_libwrap.c
@@ -31,12 +31,12 @@
 
 int my_hosts_access(struct request_info *req)
 {
-  hosts_access(req);
+  return hosts_access(req);
 }
 
 char *my_eval_client(struct request_info *req)
 {
-  eval_client(req);
+  return eval_client(req);
 }
 
 #endif /* HAVE_LIBWRAP */
[11 Sep 2006 23:08] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/11733

ChangeSet@1.2262, 2006-09-11 16:23:45-07:00, jimw@rama.(none) +1 -0
  Bug #18246: compilation error with tcp_wrapper
  
    Fix the functions in my_libwrap.c to return the results of the
    underlying call to libwrap.
[12 Sep 2006 8:18] Michal Marek
Thanks! :)
[29 Sep 2006 0:46] Jim Winstead
Pushed into 5.0-maint and 5.1-maint.
[3 Oct 2006 20:03] Chad MILLER
Available in 5.0.26.
[3 Oct 2006 20:10] Chad MILLER
Available in 5.1.12-beta.
[4 Oct 2006 1:24] Paul Dubois
Noted in 5.0.26, 5.1.12 changelogs.

The source distribution failed to compile when configured with
the --with-libwrap option.