"Fossies" - the Fresh Open Source Software Archive

Member "nss_ldap-265/tests/testpw4.c" (6 Nov 2009, 1560 Bytes) of package /linux/privat/old/nss_ldap-265.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* test IRS, independently of getpwnam et al. */
    2 
    3 #include <stdio.h>
    4 #include <pwd.h>
    5 #include <bsd/netdb.h>
    6 #include <netinet/in.h>
    7 #include <sys/socket.h>
    8 #include "irs-nss.h"
    9 
   10 static const char *testhost = "davinci.eng.sun.com";
   11 static char rcsid[] = "$Id: testpw4.c,v 1.2 2001/01/09 00:21:22 lukeh Exp $";
   12 
   13 void
   14 main (void)
   15 {
   16 
   17   struct irs_pw *irs;
   18   struct irs_ho *irs2;
   19   struct passwd *pwd;
   20   struct hostent *h;
   21 
   22   int i;
   23 
   24   i = 0;
   25 
   26   printf ("Testing irs_pw enumeration...\n");
   27 
   28   /* test users */
   29   irs = irs_ldap_pw (NULL);
   30 
   31   (irs->rewind) (irs);
   32   while ((pwd = (irs->next) (irs)))
   33     {
   34       printf ("%s:%s:%d:%d:%s:%s:%s\n",
   35           pwd->pw_name,
   36           pwd->pw_passwd,
   37           pwd->pw_uid,
   38           pwd->pw_gid, pwd->pw_gecos, pwd->pw_dir, pwd->pw_shell);
   39       i++;
   40     }
   41   (irs->close) (irs);
   42   free (irs);
   43 
   44   fprintf (stderr, ">>>>>>> %d entries\n", i);
   45 
   46   /* test hosts */
   47 
   48   printf ("Testing irs_ho enumeration...\n");
   49 
   50   irs2 = irs_ldap_ho (NULL);
   51   i = 0;
   52 
   53   (irs2->rewind) (irs2);
   54   while ((h = (irs2->next) (irs2)))
   55     {
   56       struct in_addr addr;
   57       bcopy (h->h_addr, &addr.s_addr, h->h_length);
   58       printf ("%s\t%s\n", (char *) inet_ntoa (addr), h->h_name);
   59       i++;
   60     }
   61   (irs2->close) (irs2);
   62   fprintf (stderr, ">>>>>>> %d entries\n", i);
   63 
   64   printf ("Testing irs_ho byname...\n");
   65 
   66   h = (irs2->byname) (irs2, testhost);
   67   if (h != NULL)
   68     {
   69       struct in_addr addr;
   70       bcopy (h->h_addr, &addr.s_addr, h->h_length);
   71       printf ("%s\t%s\n", (char *) inet_ntoa (addr), h->h_name);
   72     }
   73 
   74   free (irs);
   75 
   76   exit (0);
   77 }