[openssl-dev] [openssl.org #4217] Fixing DJGPP port of openssl master branch.

Juan Manuel Guerrero via RT rt at openssl.org
Tue Jan 5 03:05:45 UTC 2016


Am 04.01.2016 21:22, schrieb Richard Levitte via RT:
> Hi Juan, and thanks.
>
> I'm looking at your fix, and have a couple of questions:
>
> In message<rt-4.0.19-11137-1451936568-1413.4217-21-0 at openssl.org>  on Mon, 04 Jan 2016 19:42:48 +0000, Juan Manuel Guerrero via RT<rt at openssl.org>  said:
>
> rt>  --- a/crypto/conf/conf_def.c
> rt>  +++ b/crypto/conf/conf_def.c
> rt>  @@ -87,6 +87,9 @@ static int def_load_bio(CONF *conf, BIO *bp, long *eline);
> rt>    static int def_dump(const CONF *conf, BIO *bp);
> rt>    static int def_is_number(const CONF *conf, char c);
> rt>    static int def_to_int(const CONF *conf, char c);
> rt>  +#ifdef OPENSSL_SYS_MSDOS
> rt>  +static void dosify_filename(char *filename);
> rt>  +#endif
> rt>
> rt>    static CONF_METHOD default_method = {
> rt>        "OpenSSL default",
> rt>  @@ -370,6 +373,10 @@ static int def_load_bio(CONF *conf, BIO *in, long *line)
> rt>                if (!str_copy(conf, psection,&(v->value), start))
> rt>                    goto err;
> rt>
> rt>  +#ifdef OPENSSL_SYS_MSDOS
> rt>  +            if (IS_RANDFILE(v->name) || IS_CERT_DIR(v->name))
> rt>  +                dosify_filename(v->value);
> rt>  +#endif
>
> Why only a specific file and directory?  Don't *all* file names have
> to be "dosified"?
>
> rt>  +
> rt>  +#ifdef OPENSSL_SYS_MSDOS
> rt>  +static void dosify_filename(char *filename)
> rt>  +{
> rt>  +  if (filename&&  *filename&&  !HAS_LFN_SUPPORT(filename))
> rt>  +  {
> rt>  +    char *slash;
> rt>  +    int length;
> rt>  +    for (length = 0; filename[length]; length++)
> rt>  +      ;
> rt>  +    for (slash = filename + length - 1; slash>  filename&&  *slash != '/'; slash--)
> rt>  +      ;
> rt>  +
> rt>  +    /* Leading dot not allowed on plain DOS.  */
> rt>  +    if (slash[0] == '.')
> rt>  +      slash[0] = '_';
> rt>  +    else if (slash[1] == '.')
> rt>  +      slash[1] = '_';
> rt>  +  }
> rt>  +}
> rt>  +#endif
>
> I don't know DJGPP at all, but I'd be surprised if there isn't a
> strrchr(), so what would you say about this:
>
>      #ifdef OPENSSL_SYS_MSDOS
>      static void dosify_filename(char *filename)
>      {
>          if (filename&&  *filename&&  !HAS_LFN_SUPPORT(filename)) {
>              char *filenamestart = strrchr(filename, '/');
>
>              if (filenamestart)
>                  filenamestart++;
>              else
>                  filenamestart = filename;
>
>              /* Leading dot not allowed on plain DOS.  */
>              if (filenamestart[0] == '.')
>                  slash[0] = '_';
>          }
>      }
>      #endif
>
> Cheers,
> Richard
>

Hi Richard,

the implementation only reflected my personnal taste but the changes proposed
by you are OK with me.  Please inspect the patch and tell me if there are still
some other issues that should be changed.

Regards,
Juan M. Guerrero




2016-01-04  Juan Manuel Guerrero  <juan.guerrero at gmx.de>

	* Configure:  Replaced -DTERMIO by -DTERMIOS in CFLAGS.

	* crypto/bio/bss_dgram.c [WATT32]:  Remove obsolete redefinition of
	function names: sock_write, sock_read and sock_puts.

	* crypto/bio/bss_sock.c [WATT32]:  For Watt-32 2.2.11 sock_write,
	sock_read and sock_puts are redefined to their private names so their
	names must be undefined first before they can be redefined again.

	* crypto/conf/conf_def.c (def_load_bio) [OPENSSL_SYS_MSDOS]:  Call
	dosify_filename to replace leading dot if file system does not support
	it.
	(dosify_filename):  Replace leading dot in passed file name if file
	system does not support LFN.

	* e_os.h [__DJGPP__]:  Undefine macro DEVRANDOM_EGD.  Neither MS-DOS
	nor FreeDOS provide 'egd' sockets.
	New macro HAS_LEADING_DOT defined to identify those file names starting
	with a leading dot.
	New macro RFILE that is defined either to ".rnd" or "_rnd" depending
	on if LFN support is available or not.

	* INSTALL.DJGPP:  Update URL of WATT-32 library.









diff -aprNU5 openssl-SNAP-20160101.orig/Configurations/10-main.conf openssl-SNAP-20160101/Configurations/10-main.conf
--- openssl-SNAP-20160101.orig/Configurations/10-main.conf	2015-12-19 10:12:42 +0100
+++ openssl-SNAP-20160101/Configurations/10-main.conf	2016-01-01 22:46:48 +0100
@@ -1297,11 +1297,11 @@

  #### DJGPP
      "DJGPP" => {
          inherit_from     => [ asm("x86_asm") ],
          cc               => "gcc",
-        cflags           => "-I/dev/env/WATT_ROOT/inc -DTERMIO -DL_ENDIAN -fomit-frame-pointer -O2 -Wall",
+        cflags           => "-I/dev/env/WATT_ROOT/inc -DTERMIOS -DL_ENDIAN -fomit-frame-pointer -O2 -Wall",
          sys_id           => "MSDOS",
          lflags           => "-L/dev/env/WATT_ROOT/lib -lwatt",
          bn_ops           => "BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}",
          perlasm_scheme   => "a.out",
      },
diff -aprNU5 openssl-SNAP-20160101.orig/crypto/bio/bss_dgram.c openssl-SNAP-20160101/crypto/bio/bss_dgram.c
--- openssl-SNAP-20160101.orig/crypto/bio/bss_dgram.c	2015-12-19 10:12:42 +0100
+++ openssl-SNAP-20160101/crypto/bio/bss_dgram.c	2016-01-01 22:46:48 +0100
@@ -95,16 +95,10 @@
          (((a)->s6_addr32[0] == 0) &&          \
           ((a)->s6_addr32[1] == 0) &&          \
           ((a)->s6_addr32[2] == htonl(0x0000ffff)))
  # endif

-# ifdef WATT32
-#  define sock_write SockWrite  /* Watt-32 uses same names */
-#  define sock_read  SockRead
-#  define sock_puts  SockPuts
-# endif
-
  static int dgram_write(BIO *h, const char *buf, int num);
  static int dgram_read(BIO *h, char *buf, int size);
  static int dgram_puts(BIO *h, const char *str);
  static long dgram_ctrl(BIO *h, int cmd, long arg1, void *arg2);
  static int dgram_new(BIO *h);
diff -aprNU5 openssl-SNAP-20160101.orig/crypto/bio/bss_sock.c openssl-SNAP-20160101/crypto/bio/bss_sock.c
--- openssl-SNAP-20160101.orig/crypto/bio/bss_sock.c	2015-12-19 10:12:42 +0100
+++ openssl-SNAP-20160101/crypto/bio/bss_sock.c	2016-01-01 22:46:48 +0100
@@ -64,11 +64,15 @@
  #ifndef OPENSSL_NO_SOCK

  # include <openssl/bio.h>

  # ifdef WATT32
-#  define sock_write SockWrite  /* Watt-32 uses same names */
+/* Watt-32 uses same names */
+#  undef sock_write
+#  undef sock_read
+#  undef sock_puts
+#  define sock_write SockWrite
  #  define sock_read  SockRead
  #  define sock_puts  SockPuts
  # endif

  static int sock_write(BIO *h, const char *buf, int num);
diff -aprNU5 openssl-SNAP-20160101.orig/crypto/conf/conf_def.c openssl-SNAP-20160101/crypto/conf/conf_def.c
--- openssl-SNAP-20160101.orig/crypto/conf/conf_def.c	2015-12-19 10:12:42 +0100
+++ openssl-SNAP-20160101/crypto/conf/conf_def.c	2016-01-05 00:14:24 +0100
@@ -85,10 +85,13 @@ static int def_destroy_data(CONF *conf);
  static int def_load(CONF *conf, const char *name, long *eline);
  static int def_load_bio(CONF *conf, BIO *bp, long *eline);
  static int def_dump(const CONF *conf, BIO *bp);
  static int def_is_number(const CONF *conf, char c);
  static int def_to_int(const CONF *conf, char c);
+#ifdef OPENSSL_SYS_MSDOS
+static void dosify_filename(char *filename);
+#endif

  static CONF_METHOD default_method = {
      "OpenSSL default",
      def_create,
      def_init_default,
@@ -368,10 +371,14 @@ static int def_load_bio(CONF *conf, BIO
              }
              OPENSSL_strlcpy(v->name, pname, strlen(pname) + 1);
              if (!str_copy(conf, psection, &(v->value), start))
                  goto err;

+#ifdef OPENSSL_SYS_MSDOS
+            if (HAS_LEADING_DOT(v->name))
+                dosify_filename(v->value);
+#endif
              if (strcmp(psection, section) != 0) {
                  if ((tv = _CONF_get_section(conf, psection))
                      == NULL)
                      tv = _CONF_new_section(conf, psection);
                  if (tv == NULL) {
@@ -676,5 +683,23 @@ static int def_is_number(const CONF *con

  static int def_to_int(const CONF *conf, char c)
  {
      return c - '0';
  }
+
+#ifdef OPENSSL_SYS_MSDOS
+static void dosify_filename(char *filename)
+{
+    if (filename && *filename && !HAS_LFN_SUPPORT(filename)) {
+        char *filenamestart = strrchr(filename, '/');
+
+        if (filenamestart)
+            filenamestart++;
+        else
+            filenamestart = filename;
+
+        /* Leading dot not allowed on plain DOS.  */
+        if (filenamestart[0] == '.')
+            filenamestart[0] = '_';
+    }
+}
+#endif
diff -aprNU5 openssl-SNAP-20160101.orig/e_os.h openssl-SNAP-20160101/e_os.h
--- openssl-SNAP-20160101.orig/e_os.h	2015-12-19 10:12:42 +0100
+++ openssl-SNAP-20160101/e_os.h	2016-01-05 00:28:10 +0100
@@ -139,10 +139,11 @@ extern "C" {
  #  define clear_socket_error()    WSASetLastError(0)
  #  define readsocket(s,b,n)       recv((s),(b),(n),0)
  #  define writesocket(s,b,n)      send((s),(b),(n),0)
  # elif defined(__DJGPP__)
  #  define WATT32
+#  define WATT32_NO_OLDIES
  #  define get_last_socket_error() errno
  #  define clear_socket_error()    errno=0
  #  define closesocket(s)          close_s(s)
  #  define readsocket(s,b,n)       read_s(s,b,n)
  #  define writesocket(s,b,n)      send(s,b,n,0)
@@ -192,15 +193,32 @@ extern "C" {

  #  ifdef __DJGPP__
  #   include <unistd.h>
  #   include <sys/stat.h>
  #   include <sys/socket.h>
+#   include <sys/un.h>
  #   include <tcp.h>
  #   include <netdb.h>
  #   define _setmode setmode
  #   define _O_TEXT O_TEXT
  #   define _O_BINARY O_BINARY
+#   if defined (__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
+#    define __gnuc_extension__  __extension__
+#   else
+#    define __gnuc_extension__
+#   endif
+#   define HAS_LEADING_DOT(name)  (*(name) == '.')
+#   define FILE_EXISTS(name)      (access((name), R_OK) == 0)
+#   define HAS_LFN_SUPPORT(name)  (pathconf((name), _PC_NAME_MAX) > 12)
+#   define RFILE                                                                        \
+    (__gnuc_extension__                                                                 \
+      ({                                                                                \
+         char *rnd = HAS_LFN_SUPPORT(".rnd") && FILE_EXISTS(".rnd") ? ".rnd" : "_rnd";  \
+         rnd;                                                                           \
+      })                                                                                \
+    )
+#   undef DEVRANDOM_EGD  /*  Neither MS-DOS nor FreeDOS provide 'egd' sockets.  */
  #   undef DEVRANDOM
  #   define DEVRANDOM "/dev/urandom\x24"
  #  endif                        /* __DJGPP__ */

  #  ifndef S_IFDIR
@@ -325,11 +343,13 @@ extern FILE *_imp___iob;
  #  ifndef R_OK
  #   define R_OK        4
  #  endif
  #  define OPENSSL_CONF  "openssl.cnf"
  #  define NUL_DEV       "nul"
-#  define RFILE         ".rnd"
+#  ifndef RFILE
+#   define RFILE        ".rnd"
+#  endif
  #  ifdef OPENSSL_SYS_WINCE
  #   define DEFAULT_HOME  ""
  #  else
  #   define DEFAULT_HOME  "C:"
  #  endif
diff -aprNU5 openssl-SNAP-20160101.orig/INSTALL.DJGPP openssl-SNAP-20160101/INSTALL.DJGPP
--- openssl-SNAP-20160101.orig/INSTALL.DJGPP	2015-12-19 10:12:42 +0100
+++ openssl-SNAP-20160101/INSTALL.DJGPP	2016-01-01 22:46:48 +0100
@@ -16,11 +16,11 @@
   All of these can be obtained from the usual DJGPP mirror sites or
   directly at "http://www.delorie.com/pub/djgpp". For help on which
   files to download, see the DJGPP "ZIP PICKER" page at
   "http://www.delorie.com/djgpp/zip-picker.html". You also need to have
   the WATT-32 networking package installed before you try to compile
- OpenSSL. This can be obtained from "http://www.bgnett.no/~giva/".
+ OpenSSL. This can be obtained from "http://www.watt-32.net/".
   The Makefile assumes that the WATT-32 code is in the directory
   specified by the environment variable WATT_ROOT. If you have watt-32
   in directory "watt32" under your main DJGPP directory, specify
   WATT_ROOT="/dev/env/DJDIR/watt32".






More information about the openssl-dev mailing list