NIS+ enumeration of all database entries

Benny Holmgren bigfoot at
Mon May 18 13:16:58 GMT 1998

On Mon, 18 May 1998, Luke Kenneth Casson Leighton wrote:

> how, in NIS+, do you enumerate all the entries in a database table?

The nis_list() function does that. It can be used in two ways, either
passing a function pointer to a callback routine which is called for each
entry or without a callback routine which returns all the entries in one
result structure. The first way is better for large tables ofcourse.

I'll attach an example.

The synopsis for the routine is:

     #include <rpcsvc/nis.h>
     nis_result *nis_list(const nis_name  name,
          const u_long flags,
          int (*callback)(const nis_name table_name,
          const nis_object *object, const void *userdata),
          const void *userdata)

-------------- next part --------------
 * Link with -lnsl 
#include <stdio.h>
#include <rpcsvc/nis.h>

int nis_callback(char *table_name, nis_object *object, void *userdata)
	   ENTRY_VAL(object, 0),
	   ENTRY_VAL(object, 1),
	   ENTRY_VAL(object, 2),
	   ENTRY_VAL(object, 3),
	   ENTRY_VAL(object, 4),
	   ENTRY_VAL(object, 5),
	   ENTRY_VAL(object, 6));
    return(0);	/* Returning 1 stops enumeration. */

int main(int argc, char **argv)
    char *nisname = "passwd.org_dir";

    (void)nis_list(nisname, EXPAND_NAME, nis_callback, NULL);

More information about the samba-technical mailing list