]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - nis/ypclnt.c
* nis/nss_nis/nis-hosts.c (_nss_nis_gethostbyname4_r): Fix memory
[thirdparty/glibc.git] / nis / ypclnt.c
index 5fc931c459d0ed2807df2e4b1e994144bd371b8b..aaf4eb6e5945dc7bfb5e8719f52b383f477fae72 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2001, 2002, 2003, 2004, 2005
+/* Copyright (C) 1996-2001, 2002, 2003, 2004, 2005, 2006, 2008
    Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
@@ -28,6 +28,7 @@
 #include <rpcsvc/yp.h>
 #include <rpcsvc/ypclnt.h>
 #include <rpcsvc/ypupd.h>
+#include <sys/socket.h>
 #include <sys/uio.h>
 #include <bits/libc-lock.h>
 
@@ -69,14 +70,24 @@ yp_bind_client_create (const char *domain, dom_binding *ysd,
   ysd->dom_domain[YPMAXDOMAIN] = '\0';
 
   ysd->dom_socket = RPC_ANYSOCK;
-  ysd->dom_client = clntudp_create (&ysd->dom_server_addr, YPPROG, YPVERS,
-                                   UDPTIMEOUT, &ysd->dom_socket);
+#ifdef SOCK_CLOEXEC
+# define xflags SOCK_CLOEXEC
+#else
+# define xflags 0
+#endif
+  ysd->dom_client = __libc_clntudp_bufcreate (&ysd->dom_server_addr, YPPROG,
+                                             YPVERS, UDPTIMEOUT,
+                                             &ysd->dom_socket,
+                                             UDPMSGSIZE, UDPMSGSIZE,
+                                             xflags);
 
   if (ysd->dom_client != NULL)
     {
+#ifndef SOCK_CLOEXEC
       /* If the program exits, close the socket */
       if (fcntl (ysd->dom_socket, F_SETFD, FD_CLOEXEC) == -1)
        perror ("fcntl: F_SETFD");
+#endif
     }
 }
 
@@ -634,7 +645,7 @@ yp_order (const char *indomain, const char *inmap, unsigned int *outorder)
                         (caddr_t) &req, (xdrproc_t) xdr_ypresp_order,
                         (caddr_t) &resp);
 
-  if (result == YPERR_SUCCESS)
+  if (result != YPERR_SUCCESS)
     return result;
 
   *outorder = resp.ordernum;
@@ -686,10 +697,10 @@ __xdr_ypresp_all (XDR *xdrs, struct ypresp_all_data *objp)
               if we don't modify the length. So add an extra NUL
               character to avoid trouble with broken code. */
            objp->status = YP_TRUE;
-           memcpy (key, resp.ypresp_all_u.val.key.keydat_val, keylen);
-           key[keylen] = '\0';
-           memcpy (val, resp.ypresp_all_u.val.val.valdat_val, vallen);
-           val[vallen] = '\0';
+           *((char *) __mempcpy (key, resp.ypresp_all_u.val.key.keydat_val,
+                                 keylen)) = '\0';
+           *((char *) __mempcpy (val, resp.ypresp_all_u.val.val.valdat_val,
+                                 vallen)) = '\0';
            xdr_free ((xdrproc_t) xdr_ypresp_all, (char *) &resp);
            if ((*objp->foreach) (objp->status, key, keylen,
                                  val, vallen, objp->data))
@@ -700,7 +711,7 @@ __xdr_ypresp_all (XDR *xdrs, struct ypresp_all_data *objp)
          objp->status = resp.ypresp_all_u.val.stat;
          xdr_free ((xdrproc_t) xdr_ypresp_all, (char *) &resp);
          /* Sun says we don't need to make this call, but must return
-            immediatly. Since Solaris makes this call, we will call
+            immediately. Since Solaris makes this call, we will call
             the callback function, too. */
          (*objp->foreach) (objp->status, NULL, 0, NULL, 0, objp->data);
          return TRUE;
@@ -819,58 +830,58 @@ yperr_string (const int error)
   switch (error)
     {
     case YPERR_SUCCESS:
-      str = "Success";
+      str = N_("Success");
       break;
     case YPERR_BADARGS:
-      str = "Request arguments bad";
+      str = N_("Request arguments bad");
       break;
     case YPERR_RPC:
-      str = "RPC failure on NIS operation";
+      str = N_("RPC failure on NIS operation");
       break;
     case YPERR_DOMAIN:
-      str = "Can't bind to server which serves this domain";
+      str = N_("Can't bind to server which serves this domain");
       break;
     case YPERR_MAP:
-      str = "No such map in server's domain";
+      str = N_("No such map in server's domain");
       break;
     case YPERR_KEY:
-      str = "No such key in map";
+      str = N_("No such key in map");
       break;
     case YPERR_YPERR:
-      str = "Internal NIS error";
+      str = N_("Internal NIS error");
       break;
     case YPERR_RESRC:
-      str = "Local resource allocation failure";
+      str = N_("Local resource allocation failure");
       break;
     case YPERR_NOMORE:
-      str = "No more records in map database";
+      str = N_("No more records in map database");
       break;
     case YPERR_PMAP:
-      str = "Can't communicate with portmapper";
+      str = N_("Can't communicate with portmapper");
       break;
     case YPERR_YPBIND:
-      str = "Can't communicate with ypbind";
+      str = N_("Can't communicate with ypbind");
       break;
     case YPERR_YPSERV:
-      str = "Can't communicate with ypserv";
+      str = N_("Can't communicate with ypserv");
       break;
     case YPERR_NODOM:
-      str = "Local domain name not set";
+      str = N_("Local domain name not set");
       break;
     case YPERR_BADDB:
-      str = "NIS map database is bad";
+      str = N_("NIS map database is bad");
       break;
     case YPERR_VERS:
-      str = "NIS client/server version mismatch - can't supply service";
+      str = N_("NIS client/server version mismatch - can't supply service");
       break;
     case YPERR_ACCESS:
-      str = "Permission denied";
+      str = N_("Permission denied");
       break;
     case YPERR_BUSY:
-      str = "Database is busy";
+      str = N_("Database is busy");
       break;
     default:
-      str = "Unknown NIS error code";
+      str = N_("Unknown NIS error code");
       break;
     }
   return _(str);
@@ -907,19 +918,19 @@ ypbinderr_string (const int error)
   switch (error)
     {
     case 0:
-      str = "Success";
+      str = N_("Success");
       break;
     case YPBIND_ERR_ERR:
-      str = "Internal ypbind error";
+      str = N_("Internal ypbind error");
       break;
     case YPBIND_ERR_NOSERV:
-      str = "Domain not bound";
+      str = N_("Domain not bound");
       break;
     case YPBIND_ERR_RESC:
-      str = "System resource allocation failure";
+      str = N_("System resource allocation failure");
       break;
     default:
-      str = "Unknown ypbind error";
+      str = N_("Unknown ypbind error");
       break;
     }
   return _(str);
@@ -955,16 +966,22 @@ yp_update (char *domain, char *map, unsigned ypop,
   args.update_args.datum.yp_buf_len = datalen;
   args.update_args.datum.yp_buf_val = data;
 
-  if ((r = yp_master (domain, map, &master)) != 0)
+  if ((r = yp_master (domain, map, &master)) != YPERR_SUCCESS)
     return r;
 
   if (!host2netname (servername, master, domain))
     {
       fputs (_("yp_update: cannot convert host to netname\n"), stderr);
+      free (master);
       return YPERR_YPERR;
     }
 
-  if ((clnt = clnt_create (master, YPU_PROG, YPU_VERS, "tcp")) == NULL)
+  clnt = clnt_create (master, YPU_PROG, YPU_VERS, "tcp");
+
+  /* We do not need the string anymore.  */
+  free (master);
+
+  if (clnt == NULL)
     {
       clnt_pcreateerror ("yp_update: clnt_create");
       return YPERR_RPC;
@@ -1004,6 +1021,7 @@ again:
     {
       if (clnt->cl_auth->ah_cred.oa_flavor == AUTH_DES)
        {
+         auth_destroy (clnt->cl_auth);
          clnt->cl_auth = authunix_create_default ();
          goto again;
        }