Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/tests/testpw4.c
blob: 9dba073ffd5d0054b3048dd770f7dbd556f8ceee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* test IRS, independently of getpwnam et al. */

#include <stdio.h>
#include <pwd.h>
#include <bsd/netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include "irs-nss.h"

static const char *testhost = "davinci.eng.sun.com";
static char rcsid[] = "$Id$";

void
main (void)
{

  struct irs_pw *irs;
  struct irs_ho *irs2;
  struct passwd *pwd;
  struct hostent *h;

  int i;

  i = 0;

  printf ("Testing irs_pw enumeration...\n");

  /* test users */
  irs = irs_ldap_pw (NULL);

  (irs->rewind) (irs);
  while ((pwd = (irs->next) (irs)))
    {
      printf ("%s:%s:%d:%d:%s:%s:%s\n",
	      pwd->pw_name,
	      pwd->pw_passwd,
	      pwd->pw_uid,
	      pwd->pw_gid, pwd->pw_gecos, pwd->pw_dir, pwd->pw_shell);
      i++;
    }
  (irs->close) (irs);
  free (irs);

  fprintf (stderr, ">>>>>>> %d entries\n", i);

  /* test hosts */

  printf ("Testing irs_ho enumeration...\n");

  irs2 = irs_ldap_ho (NULL);
  i = 0;

  (irs2->rewind) (irs2);
  while ((h = (irs2->next) (irs2)))
    {
      struct in_addr addr;
      bcopy (h->h_addr, &addr.s_addr, h->h_length);
      printf ("%s\t%s\n", (char *) inet_ntoa (addr), h->h_name);
      i++;
    }
  (irs2->close) (irs2);
  fprintf (stderr, ">>>>>>> %d entries\n", i);

  printf ("Testing irs_ho byname...\n");

  h = (irs2->byname) (irs2, testhost);
  if (h != NULL)
    {
      struct in_addr addr;
      bcopy (h->h_addr, &addr.s_addr, h->h_length);
      printf ("%s\t%s\n", (char *) inet_ntoa (addr), h->h_name);
    }

  free (irs);

  exit (0);
}