]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#9348 Stop using plain strerror()
authorOndřej Kuzník <ondra@mistotebe.net>
Fri, 25 Sep 2020 11:29:14 +0000 (12:29 +0100)
committerOndřej Kuzník <ondra@mistotebe.net>
Fri, 25 Sep 2020 11:47:46 +0000 (12:47 +0100)
contrib/slapd-modules/dsaschema/dsaschema.c
contrib/slapd-modules/nssov/nss-pam-ldapd/nslcd-prot.h
contrib/slapd-modules/nssov/nssov.c
servers/slapd/ad.c
servers/slapd/back-mdb/config.c
servers/slapd/config.c
servers/slapd/main.c
servers/slapd/slaptest.c

index bef7b21f843afaf0f7699a3e3565a01b69e3cf16..5c787b33c3e4f9a575e6006eb2a1031e69a55976 100644 (file)
@@ -168,8 +168,10 @@ static int dsaschema_read_config(const char *fname, int depth)
 
        fp = fopen(fname, "r");
        if (fp == NULL) {
+               char ebuf[128];
+               int saved_errno = errno;
                fprintf(stderr, "could not open config file \"%s\": %s (%d)\n",
-                       fname, strerror(errno), errno);
+                       fname, AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)), saved_errno);
                return 1;
        }
        fp_getline_init(&lineno);
index 06d8959fd47a183b932a1663879797bbba867bca..c68ffa20a31db34727c8850ee6919c1ea464145d 100644 (file)
@@ -86,8 +86,10 @@ static void debug_dump(const void *ptr, size_t size)
   DEBUG_DUMP(ptr, size);                                                    \
   if (tio_write(fp, ptr, (size_t)size))                                     \
   {                                                                         \
+    char ebuf[128];                                                         \
+    int saved_errno = errno;                                                \
     DEBUG_PRINT("WRITE       : var="__STRING(ptr)" error: %s",              \
-                strerror(errno));                                           \
+                AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)));            \
     ERROR_OUT_WRITEERROR(fp);                                               \
   }
 
@@ -161,8 +163,10 @@ static void debug_dump(const void *ptr, size_t size)
 #define READ(fp, ptr, size)                                                 \
   if (tio_read(fp, ptr, (size_t)size))                                      \
   {                                                                         \
+    char ebuf[128];                                                         \
+    int saved_errno = errno;                                                \
     DEBUG_PRINT("READ       : var="__STRING(ptr)" error: %s",               \
-                strerror(errno));                                           \
+                AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)));            \
     ERROR_OUT_READERROR(fp);                                                \
   }                                                                         \
   DEBUG_PRINT("READ       : var="__STRING(ptr)" size=%d", (int)(size));     \
@@ -301,7 +305,10 @@ static void debug_dump(const void *ptr, size_t size)
   /* read (skip) the specified number of bytes */                           \
   if (tio_skip(fp, sz))                                                     \
   {                                                                         \
-    DEBUG_PRINT("READ       : skip error: %s", strerror(errno));            \
+    char ebuf[128];                                                         \
+    int saved_errno = errno;                                                \
+    DEBUG_PRINT("READ       : skip error: %s",                              \
+                AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)));            \
     ERROR_OUT_READERROR(fp);                                                \
   }
 
@@ -350,7 +357,10 @@ TFILE *nslcd_client_open(void)
   /* flush the stream */                                                    \
   if (tio_flush(fp) < 0)                                                    \
   {                                                                         \
-    DEBUG_PRINT("WRITE_FLUSH : error: %s", strerror(errno));                \
+    char ebuf[128];                                                         \
+    int saved_errno = errno;                                                \
+    DEBUG_PRINT("WRITE_FLUSH : error: %s",                                  \
+                AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)));            \
     ERROR_OUT_WRITEERROR(fp);                                               \
   }                                                                         \
   /* read and check response version number */                              \
index c48be67ae5795dc7df05c463da6c4e9699aec326..a21f2477cf7d16b68437fde4d395ac10a25cbf44 100644 (file)
@@ -298,11 +298,15 @@ static void handleconnection(nssov_info *ni,int sock,Operation *op)
   struct berval peerbv = { sizeof(peerbuf), peerbuf };
 
   /* log connection */
-  if (LUTIL_GETPEEREID(sock,&uid,&gid,&peerbv))
-    Debug( LDAP_DEBUG_TRACE,"nssov: connection from unknown client: %s\n",strerror(errno) );
-  else
+  if (LUTIL_GETPEEREID(sock,&uid,&gid,&peerbv)) {
+    char ebuf[128];
+    int saved_errno = errno;
+    Debug( LDAP_DEBUG_TRACE,"nssov: connection from unknown client: %s\n",
+                      AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
+  } else {
     Debug( LDAP_DEBUG_TRACE,"nssov: connection from uid=%d gid=%d\n",
                       (int)uid,(int)gid );
+  }
 
   /* Should do authid mapping too */
   op->o_dn.bv_len = sprintf(authid,"gidNumber=%d+uidNumber=%d,cn=peercred,cn=external,cn=auth",
@@ -322,7 +326,10 @@ static void handleconnection(nssov_info *ni,int sock,Operation *op)
                      READBUFFER_MINSIZE,READBUFFER_MAXSIZE,
                      WRITEBUFFER_MINSIZE,WRITEBUFFER_MAXSIZE))==NULL)
   {
-    Debug( LDAP_DEBUG_ANY,"nssov: cannot create stream for writing: %s",strerror(errno) );
+    char ebuf[128];
+    int saved_errno = errno;
+    Debug( LDAP_DEBUG_ANY,"nssov: cannot create stream for writing: %s",
+                      AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
     (void)close(sock);
     return;
   }
@@ -403,27 +410,43 @@ static void *acceptconn(void *ctx, void *arg)
                connection_client_enable(ni->ni_conn);
                if (csock<0)
                {
+                       char ebuf[128];
+                       int saved_errno = errno;
                        if ((errno==EINTR)||(errno==EAGAIN)||(errno==EWOULDBLOCK))
                        {
-                               Debug( LDAP_DEBUG_TRACE,"nssov: accept() failed (ignored): %s",strerror(errno) );
+                               Debug( LDAP_DEBUG_TRACE,"nssov: accept() failed (ignored): %s",
+                                       AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
                                return NULL;
                        }
-                       Debug( LDAP_DEBUG_ANY,"nssov: accept() failed: %s",strerror(errno) );
+                       Debug( LDAP_DEBUG_ANY,"nssov: accept() failed: %s",
+                               AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
                        return NULL;
                }
                /* make sure O_NONBLOCK is not inherited */
                if ((j=fcntl(csock,F_GETFL,0))<0)
                {
-                       Debug( LDAP_DEBUG_ANY,"nssov: fcntl(F_GETFL) failed: %s",strerror(errno) );
-                       if (close(csock))
-                               Debug( LDAP_DEBUG_ANY,"nssov: problem closing socket: %s",strerror(errno) );
+                       char ebuf[128];
+                       int saved_errno = errno;
+                       Debug( LDAP_DEBUG_ANY,"nssov: fcntl(F_GETFL) failed: %s",
+                               AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
+                       if (close(csock)) {
+                               saved_errno = errno;
+                               Debug( LDAP_DEBUG_ANY,"nssov: problem closing socket: %s",
+                                       AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
+                       }
                        return NULL;
                }
                if (fcntl(csock,F_SETFL,j&~O_NONBLOCK)<0)
                {
-                       Debug( LDAP_DEBUG_ANY,"nssov: fcntl(F_SETFL,~O_NONBLOCK) failed: %s",strerror(errno) );
-                       if (close(csock))
-                               Debug( LDAP_DEBUG_ANY,"nssov: problem closing socket: %s",strerror(errno) );
+                       char ebuf[128];
+                       int saved_errno = errno;
+                       Debug( LDAP_DEBUG_ANY,"nssov: fcntl(F_SETFL,~O_NONBLOCK) failed: %s",
+                               AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
+                       if (close(csock)) {
+                               saved_errno = errno;
+                               Debug( LDAP_DEBUG_ANY,"nssov: problem closing socket: %s",
+                                       AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
+                       }
                        return NULL;
                }
        }
@@ -868,10 +891,12 @@ nssov_db_open(
                }
        }
        if ( slapMode & SLAP_SERVER_MODE ) {
+               char ebuf[128];
                /* make sure /var/run/nslcd exists */
                if (mkdir(NSLCD_PATH, (mode_t) 0555)) {
+                       int saved_errno = errno;
                        Debug(LDAP_DEBUG_TRACE,"nssov: mkdir(%s) failed (ignored): %s\n",
-                                       NSLCD_PATH,strerror(errno) );
+                                       NSLCD_PATH, AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
                } else {
                        Debug(LDAP_DEBUG_TRACE,"nssov: created %s\n",NSLCD_PATH );
                }
@@ -879,14 +904,17 @@ nssov_db_open(
                /* create a socket */
                if ( (sock=socket(PF_UNIX,SOCK_STREAM,0))<0 )
                {
-                       Debug(LDAP_DEBUG_ANY,"nssov: cannot create socket: %s\n",strerror(errno) );
+                       int saved_errno = errno;
+                       Debug(LDAP_DEBUG_ANY,"nssov: cannot create socket: %s\n",
+                                       AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
                        return -1;
                }
                /* remove existing named socket */
                if (unlink(NSLCD_SOCKET)<0)
                {
+                       int saved_errno = errno;
                        Debug( LDAP_DEBUG_TRACE,"nssov: unlink() of "NSLCD_SOCKET" failed (ignored): %s\n",
-                                                       strerror(errno) );
+                                                       AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
                }
                /* create socket address structure */
                memset(&addr,0,sizeof(struct sockaddr_un));
@@ -896,18 +924,27 @@ nssov_db_open(
                /* bind to the named socket */
                if (bind(sock,(struct sockaddr *)&addr,sizeof(struct sockaddr_un)))
                {
+                       int saved_errno = errno;
                        Debug( LDAP_DEBUG_ANY,"nssov: bind() to "NSLCD_SOCKET" failed: %s",
-                                                       strerror(errno) );
-                       if (close(sock))
-                               Debug( LDAP_DEBUG_ANY,"nssov: problem closing socket: %s",strerror(errno) );
+                               AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
+                       if (close(sock)) {
+                               saved_errno = errno
+                               Debug( LDAP_DEBUG_ANY,"nssov: problem closing socket: %s",
+                                       AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
+                       }
                        return -1;
                }
                /* close the file descriptor on exit */
                if (fcntl(sock,F_SETFD,FD_CLOEXEC)<0)
                {
-                       Debug( LDAP_DEBUG_ANY,"nssov: fcntl(F_SETFL,O_NONBLOCK) failed: %s",strerror(errno) );
-                       if (close(sock))
-                               Debug( LDAP_DEBUG_ANY,"nssov: problem closing socket: %s",strerror(errno) );
+                       int saved_errno = errno;
+                       Debug( LDAP_DEBUG_ANY,"nssov: fcntl(F_SETFL,O_NONBLOCK) failed: %s",
+                               AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
+                       if (close(sock)) {
+                               saved_errno = errno
+                               Debug( LDAP_DEBUG_ANY,"nssov: problem closing socket: %s",
+                                       AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
+                       }
                        return -1;
                }
                /* set permissions of socket so anybody can do requests */
@@ -917,17 +954,27 @@ nssov_db_open(
                         http://lkml.org/lkml/2005/5/16/11 */
                if (chmod(NSLCD_SOCKET,(mode_t)0666))
                {
-                       Debug( LDAP_DEBUG_ANY,"nssov: chmod(0666) failed: %s",strerror(errno) );
-                       if (close(sock))
-                               Debug( LDAP_DEBUG_ANY,"nssov: problem closing socket: %s",strerror(errno) );
+                       int saved_errno = errno;
+                       Debug( LDAP_DEBUG_ANY,"nssov: chmod(0666) failed: %s",
+                               AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
+                       if (close(sock)) {
+                               saved_errno = errno
+                               Debug( LDAP_DEBUG_ANY,"nssov: problem closing socket: %s",
+                                       AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
+                       }
                        return -1;
                }
                /* start listening for connections */
                if (listen(sock,SOMAXCONN)<0)
                {
-                       Debug( LDAP_DEBUG_ANY,"nssov: listen() failed: %s",strerror(errno) );
-                       if (close(sock))
-                               Debug( LDAP_DEBUG_ANY,"nssov: problem closing socket: %s",strerror(errno) );
+                       int saved_errno = errno;
+                       Debug( LDAP_DEBUG_ANY,"nssov: listen() failed: %s",
+                               AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
+                       if (close(sock)) {
+                               saved_errno = errno
+                               Debug( LDAP_DEBUG_ANY,"nssov: problem closing socket: %s",
+                                       AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
+                       }
                        return -1;
                }
                ni->ni_socket = sock;
@@ -946,18 +993,23 @@ nssov_db_close(
        nssov_info *ni = on->on_bi.bi_private;
 
        if ( slapMode & SLAP_SERVER_MODE ) {
+               char ebuf[128];
                /* close socket if it's still in use */
                if (ni->ni_socket >= 0)
                {
-                       if (close(ni->ni_socket))
-                               Debug( LDAP_DEBUG_ANY,"problem closing server socket (ignored): %s",strerror(errno) );
+                       if (close(ni->ni_socket)) {
+                               int saved_errno = errno;
+                               Debug( LDAP_DEBUG_ANY,"problem closing server socket (ignored): %s",
+                                       AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
+                       }
                        ni->ni_socket = -1;
                }
                /* remove existing named socket */
                if (unlink(NSLCD_SOCKET)<0)
                {
+                       int saved_errno = errno;
                        Debug( LDAP_DEBUG_TRACE,"unlink() of "NSLCD_SOCKET" failed (ignored): %s",
-                               strerror(errno) );
+                               AC_STRERROR_R(saved_errno, ebuf, sizeof(ebuf)) );
                }
        }
        return 0;
index 7d1e5fd93ec5df2954f6690442d3844972e361b7..fa198b011dd592e6e4be3672c07e4608f77221c4 100644 (file)
@@ -1143,9 +1143,11 @@ file2anlist( AttributeName *an, const char *fname, const char *brkstr )
 
        fp = fopen( fname, "r" );
        if ( fp == NULL ) {
+               char ebuf[128];
+               int saved_errno = errno;
                Debug( LDAP_DEBUG_ANY,
                        "get_attrs_from_file: failed to open attribute list file "
-                       "\"%s\": %s\n", fname, strerror(errno) );
+                       "\"%s\": %s\n", fname, AC_STRERROR_R( saved_errno, ebuf, sizeof(ebuf) ) );
                return NULL;
        }
 
index 160445aa75d911248dcc7b7afe7bf5b3c46f5ea9..06af74ef374cefe8e4c7620cd9b890150a67cc94 100644 (file)
@@ -700,8 +700,10 @@ mdb_cf_gen( ConfigArgs *c )
                }
                ch_free( testpath );
                if ( !f ) {
+                       char ebuf[128];
+                       int saved_errno = errno;
                        snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s: invalid path: %s",
-                               c->log, strerror( errno ));
+                               c->log, AC_STRERROR_R( saved_errno, ebuf, sizeof(ebuf) ) );
                        Debug( LDAP_DEBUG_ANY, "%s\n", c->cr_msg );
                        return -1;
                }
index c6fac264d2cf1deee2b571a1aab16744af5dbb82..9ea7d39d9044fa84b27c44cab25e2851ca99b8a8 100644 (file)
@@ -787,11 +787,12 @@ read_config_file(const char *fname, int depth, ConfigArgs *cf, ConfigTable *cft)
        init_config_argv( c );
 
        if ( stat( fname, &s ) != 0 ) {
+               char ebuf[128];
                int saved_errno = errno;
                ldap_syslog = 1;
                Debug(LDAP_DEBUG_ANY,
                    "could not stat config file \"%s\": %s (%d)\n",
-                   fname, strerror(saved_errno), saved_errno);
+                   fname, AC_STRERROR_R( saved_errno, ebuf, sizeof(ebuf) ), saved_errno);
                ch_free( c->argv );
                ch_free( c );
                return(1);
@@ -809,11 +810,12 @@ read_config_file(const char *fname, int depth, ConfigArgs *cf, ConfigTable *cft)
 
        fp = fopen( fname, "r" );
        if ( fp == NULL ) {
+               char ebuf[128];
                int saved_errno = errno;
                ldap_syslog = 1;
                Debug(LDAP_DEBUG_ANY,
                    "could not open config file \"%s\": %s (%d)\n",
-                   fname, strerror(saved_errno), saved_errno);
+                   fname, AC_STRERROR_R( saved_errno, ebuf, sizeof(ebuf) ), saved_errno);
                ch_free( c->argv );
                ch_free( c );
                return(1);
index 42894f2b241d34f331d93bfdff2df6f5aa320a5f..739c32e6d9f44deb5ff45d1e5700d7522c5f232a 100644 (file)
@@ -945,12 +945,13 @@ unhandled_option:;
                FILE *fp = fopen( slapd_pid_file, "w" );
 
                if ( fp == NULL ) {
+                       char ebuf[128];
                        int save_errno = errno;
 
                        Debug( LDAP_DEBUG_ANY, "unable to open pid file "
                                "\"%s\": %d (%s)\n",
                                slapd_pid_file,
-                               save_errno, strerror( save_errno ) );
+                               save_errno, AC_STRERROR_R( save_errno, ebuf, sizeof(ebuf) ) );
 
                        free( slapd_pid_file );
                        slapd_pid_file = NULL;
@@ -967,12 +968,13 @@ unhandled_option:;
                FILE *fp = fopen( slapd_args_file, "w" );
 
                if ( fp == NULL ) {
+                       char ebuf[128];
                        int save_errno = errno;
 
                        Debug( LDAP_DEBUG_ANY, "unable to open args file "
                                "\"%s\": %d (%s)\n",
                                slapd_args_file,
-                               save_errno, strerror( save_errno ) );
+                               save_errno, AC_STRERROR_R( save_errno, ebuf, sizeof(ebuf) ) );
 
                        free( slapd_args_file );
                        slapd_args_file = NULL;
index 8736d4bf8f80ff07497eca09964fa2f5e92a63dd..44c1dd0e468571d5387d0fa1d63329fd4c0aaf85 100644 (file)
@@ -46,6 +46,7 @@ static int
 test_file( const char *fname, const char *ftype )
 {
        struct stat     st;
+       char ebuf[128];
        int             save_errno;
 
        switch ( stat( fname, &st ) ) {
@@ -70,7 +71,7 @@ test_file( const char *fname, const char *ftype )
                                Debug( LDAP_DEBUG_ANY, "unable to open file "
                                        "\"%s\": %d (%s)\n",
                                        fname,
-                                       save_errno, strerror( save_errno ) );
+                                       save_errno, AC_STRERROR_R( save_errno, ebuf, sizeof(ebuf) ) );
 
                                return -1;
                        }
@@ -82,7 +83,7 @@ test_file( const char *fname, const char *ftype )
                Debug( LDAP_DEBUG_ANY, "unable to stat file "
                        "\"%s\": %d (%s)\n",
                        slapd_pid_file,
-                       save_errno, strerror( save_errno ) );
+                       save_errno, AC_STRERROR_R( save_errno, ebuf, sizeof(ebuf) ) );
                return -1;
        }