about summary refs log tree commit diff
path: root/nis/nis_table.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2006-05-20 19:22:30 +0000
committerUlrich Drepper <drepper@redhat.com>2006-05-20 19:22:30 +0000
commita17fa6100dd400cd0c64aab1803c2047c95bfd5b (patch)
tree3f1c005d18d338defaeaa489fd34c2c6e4fd7690 /nis/nis_table.c
parent1d4f062ab84f24cab893a9211e3e72b2f1f470ce (diff)
downloadglibc-a17fa6100dd400cd0c64aab1803c2047c95bfd5b.tar.gz
glibc-a17fa6100dd400cd0c64aab1803c2047c95bfd5b.tar.xz
glibc-a17fa6100dd400cd0c64aab1803c2047c95bfd5b.zip
* nis/nis_call.c (__prepare_niscall): New function. Split out cvs/fedora-glibc-20060521T2153
	from __do_niscall.
	* nis/nis_table.c (__create_ib_request): Renamed from create_ib_request
	and exported.
	(__follow_path): New function.  Split out from nis_list.
	* nis/nis_xdr.h: Add libnsl_hidden_proto for _xdr_ib_request and
	_xdr_nis_result.
	* nis/nis_xdr.c: Add libnsl_hidden_def for _xdr_ib_request and
	_xdr_nis_result.
	* nis/libnsl.h: Declare __prepare_niscall, __create_ib_request,
	and __follow_path.
	* nis/Versions: Export __prepare_niscall, __create_ib_request,
	__follow_path, __do_niscall3, _xdr_ib_request, and _xdr_nis_result
	from libnsl for version GLIBC_PRIVATE.
	* nis/nisplus-parser.h: Remove _nss_nisplus_parse_pwent_chk.
	Remove entry parameter from _nss_nisplus_parse_pwent and
	_nss_nisplus_parse_grent.
	* nis/nss_nisplus/nisplus-parser.c: Likewise.
	* nis/nss_nisplus/nisplus-pwd.c: Remove support for SETENT_BATCH_READ
	again.  Rewrite getpwent handling to not use nis_first_entry and
	nis_next_entry.  Roll out own niscall handling.
	* nis/nss_nisplus/nisplus-grp.c: Likewise.

	* sunrpc/xdr_rec.c: Fix typo in comment.

2006-05-18  David Woodhouse  <dwmw2@redhat.com>
Diffstat (limited to 'nis/nis_table.c')
-rw-r--r--nis/nis_table.c129
1 files changed, 53 insertions, 76 deletions
diff --git a/nis/nis_table.c b/nis/nis_table.c
index eddba67dda..3213035067 100644
--- a/nis/nis_table.c
+++ b/nis/nis_table.c
@@ -17,15 +17,17 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
+#include <assert.h>
 #include <string.h>
 #include <rpcsvc/nis.h>
 
 #include "nis_xdr.h"
 #include "nis_intern.h"
+#include "libnsl.h"
 
 
-static struct ib_request *
-create_ib_request (const_nis_name name, unsigned int flags)
+struct ib_request *
+__create_ib_request (const_nis_name name, unsigned int flags)
 {
   struct ib_request *ibreq = calloc (1, sizeof (struct ib_request));
   nis_attr *search_val = NULL;
@@ -125,6 +127,7 @@ create_ib_request (const_nis_name name, unsigned int flags)
 
   return ibreq;
 }
+libnsl_hidden_def (__create_ib_request)
 
 static const struct timeval RPCTIMEOUT = {10, 0};
 
@@ -160,6 +163,38 @@ get_tablepath (char *name, dir_binding *bptr)
   return str;
 }
 
+
+nis_error
+__follow_path (char **tablepath, char **tableptr, struct ib_request *ibreq,
+	       dir_binding *bptr)
+{
+  if (*tablepath == NULL)
+    {
+      *tablepath = get_tablepath (ibreq->ibr_name, bptr);
+      if (*tablepath == NULL)
+	return NIS_NOMEMORY;
+
+      *tableptr = *tablepath;
+    }
+  if (*tableptr == NULL)
+    return NIS_NOTFOUND;
+
+  char *newname = strsep (tableptr, ":");
+  if (newname[0] == '\0')
+    return NIS_NOTFOUND;
+
+  newname = strdup (newname);
+  if (newname == NULL)
+    return NIS_NOMEMORY;
+
+  free (ibreq->ibr_name);
+  ibreq->ibr_name = newname;
+
+  return NIS_SUCCESS;
+}
+libnsl_hidden_def (__follow_path)
+
+
 nis_result *
 nis_list (const_nis_name name, unsigned int flags,
 	  int (*callback) (const_nis_name name,
@@ -193,7 +228,7 @@ nis_list (const_nis_name name, unsigned int flags,
       return res;
     }
 
-  ibreq = create_ib_request (name, flags);
+  ibreq = __create_ib_request (name, flags);
   if (ibreq == NULL)
     {
       status = NIS_BADNAME;
@@ -260,6 +295,7 @@ nis_list (const_nis_name name, unsigned int flags,
 
       if (callback != NULL)
 	{
+	  assert (cb == NULL);
 	  cb = __nis_create_callback (callback, userdata, flags);
 	  ibreq->ibr_cbhost.ibr_cbhost_len = 1;
 	  ibreq->ibr_cbhost.ibr_cbhost_val = cb->serv;
@@ -327,69 +363,30 @@ nis_list (const_nis_name name, unsigned int flags,
 		   following code.  But it also would unnecessarily
 		   free the result structure.  We avoid this here
 		   along with the necessary tests.  */
-#if 1
 		xdr_free ((xdrproc_t) _xdr_nis_result, (char *)res);
 		memset (res, '\0', sizeof (*res));
-#else
-		nis_freeresult (res);
-		res = calloc (1, sizeof (nis_result));
-		if (res == NULL)
-		  goto fail;
-#endif
 		first_try = 1; /* Try at first the old binding */
 		goto again;
 	      }
 	    else if ((flags & FOLLOW_PATH)
 		     && NIS_RES_STATUS (res) == NIS_PARTIAL)
 	      {
-		if (tablepath == NULL)
-		  {
-		    tablepath = get_tablepath (ibreq->ibr_name, &bptr);
-		    tableptr = tablepath;
-		  }
-		if (tableptr == NULL)
+		clnt_status = __follow_path (&tablepath, &tableptr, ibreq,
+					     &bptr);
+		if (clnt_status != NIS_SUCCESS)
 		  {
-		    ++done;
-		    break;
-		  }
-		free (ibreq->ibr_name);
-		ibreq->ibr_name = strsep (&tableptr, ":");
-		if (ibreq->ibr_name == NULL || ibreq->ibr_name[0] == '\0')
-		  {
-		    ibreq->ibr_name = strdup ("");
-		    if (ibreq->ibr_name == NULL)
-		      {
-			NIS_RES_STATUS (res) = NIS_NOMEMORY;
-			goto fail;
-		      }
+		    NIS_RES_STATUS (res) = clnt_status;
 		    ++done;
 		  }
 		else
 		  {
-		    ibreq->ibr_name = strdup (ibreq->ibr_name);
 		    /* The following is a non-obvious optimization.  A
 		       nis_freeresult call would call xdr_free as the
 		       following code.  But it also would unnecessarily
 		       free the result structure.  We avoid this here
 		       along with the necessary tests.  */
-#if 1
-		    xdr_free ((xdrproc_t) _xdr_nis_result, (char *)res);
+		    xdr_free ((xdrproc_t) _xdr_nis_result, (char *) res);
 		    memset (res, '\0', sizeof (*res));
-		    if (ibreq->ibr_name == NULL)
-		      {
-			NIS_RES_STATUS (res) = NIS_NOMEMORY;
-			goto fail;
-		      }
-#else
-		    nis_freeresult (res);
-		    res = calloc (1, sizeof (nis_result));
-		    if (res == NULL || ibreq->ibr_name == NULL)
-		      {
-			free (res);
-			res = NULL;
-			goto fail;
-		      }
-#endif
 		    first_try = 1;
 		    goto again;
 		  }
@@ -407,30 +404,10 @@ nis_list (const_nis_name name, unsigned int flags,
 		  ++done;
 		else
 		  {
-		    if (tablepath == NULL)
-		      {
-			tablepath = get_tablepath (ibreq->ibr_name, &bptr);
-			tableptr = tablepath;
-		      }
-		    if (tableptr == NULL)
-		      {
-			++done;
-			break;
-		      }
-		    free (ibreq->ibr_name);
-		    ibreq->ibr_name = strsep (&tableptr, ":");
-		    if (ibreq->ibr_name == NULL || ibreq->ibr_name[0] == '\0')
-		      {
-			ibreq->ibr_name = strdup ("");
-			++done;
-		      }
-		    else
-		      ibreq->ibr_name = strdup (ibreq->ibr_name);
-		    if (ibreq->ibr_name == NULL)
-		      {
-			NIS_RES_STATUS (res) = NIS_NOMEMORY;
-			goto fail;
-		      }
+		    NIS_RES_STATUS (res)
+		      = __follow_path (&tablepath, &tableptr, ibreq, &bptr);
+		    if (NIS_RES_STATUS (res) != NIS_SUCCESS)
+		      ++done;
 		  }
 	      }
 	    break;
@@ -524,7 +501,7 @@ nis_add_entry (const_nis_name name, const nis_object *obj2, unsigned int flags)
       return res;
     }
 
-  ib_request *ibreq = create_ib_request (name, flags);
+  ib_request *ibreq = __create_ib_request (name, flags);
   if (ibreq == NULL)
     {
       NIS_RES_STATUS (res) = NIS_BADNAME;
@@ -587,7 +564,7 @@ nis_modify_entry (const_nis_name name, const nis_object *obj2,
   if (res == NULL)
     return NULL;
 
-  ibreq = create_ib_request (name, flags);
+  ibreq = __create_ib_request (name, flags);
   if (ibreq == NULL)
     {
       NIS_RES_STATUS (res) = NIS_BADNAME;
@@ -646,7 +623,7 @@ nis_remove_entry (const_nis_name name, const nis_object *obj,
       return res;
     }
 
-  ibreq = create_ib_request (name, flags);
+  ibreq = __create_ib_request (name, flags);
   if (ibreq == NULL)
     {
       NIS_RES_STATUS (res) = NIS_BADNAME;
@@ -693,7 +670,7 @@ nis_first_entry (const_nis_name name)
       return res;
     }
 
-  ibreq = create_ib_request (name, 0);
+  ibreq = __create_ib_request (name, 0);
   if (ibreq == NULL)
     {
       NIS_RES_STATUS (res) = NIS_BADNAME;
@@ -730,7 +707,7 @@ nis_next_entry (const_nis_name name, const netobj *cookie)
       return res;
     }
 
-  ibreq = create_ib_request (name, 0);
+  ibreq = __create_ib_request (name, 0);
   if (ibreq == NULL)
     {
       NIS_RES_STATUS (res) = NIS_BADNAME;