]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - nis/nss_nisplus/nisplus-network.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / nis / nss_nisplus / nisplus-network.c
index 468520c937e73d1303edff49d15cede93b1d04f8..f13880d2ded1a109b72a9b0d14654ee73231bb25 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997,1998,2000-2003,2005,2006 Free Software Foundation, Inc.
+/* Copyright (C) 1997-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
 
@@ -13,9 +13,8 @@
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
 
 #include <atomic.h>
 #include <ctype.h>
@@ -26,7 +25,7 @@
 #include <string.h>
 #include <arpa/inet.h>
 #include <rpcsvc/nis.h>
-#include <bits/libc-lock.h>
+#include <libc-lock.h>
 
 #include "nss-nisplus.h"
 
@@ -232,6 +231,11 @@ internal_nisplus_getnetent_r (struct netent *network, char *buffer,
            }
 
          result = nis_first_entry (tablename_val);
+         if (result == NULL)
+           {
+             *errnop = errno;
+             return NSS_STATUS_TRYAGAIN;
+           }
          if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
            {
              int retval = niserr2nss (result->status);
@@ -249,9 +253,13 @@ internal_nisplus_getnetent_r (struct netent *network, char *buffer,
        }
       else
        {
-         nis_result *res = nis_next_entry (tablename_val, &result->cookie);
          saved_res = result;
-         result = res;
+         result = nis_next_entry (tablename_val, &result->cookie);
+         if (result == NULL)
+           {
+             *errnop = errno;
+             return NSS_STATUS_TRYAGAIN;
+           }
          if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
            {
              int retval = niserr2nss (result->status);
@@ -329,7 +337,7 @@ _nss_nisplus_getnetbyname_r (const char *name, struct netent *network,
   /* Search at first in the alias list, and use the correct name
      for the next search */
   snprintf (buf, sizeof (buf), "[name=%s],%s", name, tablename_val);
-  result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
+  result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH | USE_DGRAM, NULL, NULL);
 
   if (result != NULL)
     {
@@ -357,7 +365,8 @@ _nss_nisplus_getnetbyname_r (const char *name, struct netent *network,
        }
 
       nis_freeresult (result);
-      result = nis_list (bufptr, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
+      result = nis_list (bufptr, FOLLOW_LINKS | FOLLOW_PATH | USE_DGRAM,
+                        NULL, NULL);
     }
 
   if (result == NULL)
@@ -367,7 +376,7 @@ _nss_nisplus_getnetbyname_r (const char *name, struct netent *network,
     }
 
   retval = niserr2nss (result->status);
-  if (__builtin_expect (retval != NSS_STATUS_SUCCESS, 0))
+  if (__glibc_unlikely (retval != NSS_STATUS_SUCCESS))
     {
       if (retval == NSS_STATUS_TRYAGAIN)
        {
@@ -422,14 +431,15 @@ _nss_nisplus_getnetbyaddr_r (uint32_t addr, const int type,
     char buf2[18];
     int olderr = errno;
 
-    struct in_addr in = inet_makeaddr (addr, 0);
+    struct in_addr in = { .s_addr = htonl (addr) };
     strcpy (buf2, inet_ntoa (in));
     size_t b2len = strlen (buf2);
 
     while (1)
       {
        snprintf (buf, sizeof (buf), "[addr=%s],%s", buf2, tablename_val);
-       nis_result *result = nis_list (buf, EXPAND_NAME, NULL, NULL);
+       nis_result *result = nis_list (buf, EXPAND_NAME | USE_DGRAM,
+                                      NULL, NULL);
 
        if (result == NULL)
          {
@@ -437,7 +447,7 @@ _nss_nisplus_getnetbyaddr_r (uint32_t addr, const int type,
            return NSS_STATUS_TRYAGAIN;
          }
        enum nss_status retval = niserr2nss (result->status);
-       if (__builtin_expect (retval != NSS_STATUS_SUCCESS, 0))
+       if (__glibc_unlikely (retval != NSS_STATUS_SUCCESS))
          {
            if (b2len > 2 && buf2[b2len - 2] == '.' && buf2[b2len - 1] == '0')
              {