about summary refs log tree commit diff
path: root/src/tests/test-all-fallback.c
blob: 3278254622411dba4f68fb765ce2898e94c52a8b (plain) (blame)
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
/* ISC license. */

#include <errno.h>
#include <skalibs/buffer.h>
#include <skalibs/strerr.h>
#include <skalibs/lolstdio.h>
#include <nsss/pwd-def.h>
#include <nsss/grp-def.h>
#include <nsss/nsss-all.h>

int main (void)
{
  PROG = "test-all-fallback" ;
  for (;;)
  {
    struct passwd *pw ;
    errno = 0 ;
    pw = nsss_all_getpwent() ;
    if (!pw) break ;
    lolprintf("%s:%s:%d:%d:%s:%s:%s\n", pw->pw_name, pw->pw_passwd, (int)pw->pw_uid, (int)pw->pw_gid, pw->pw_gecos, pw->pw_dir, pw->pw_shell) ;
  }
  if (errno)
    strerr_diefu1sys(111, "nsss_all_getpwent") ;
  nsss_all_endpwent() ;
  lolprintf("\n") ;

  {
    struct passwd *pw = nsss_all_getpwnam("root") ;
    lolprintf("%u\n\n", (unsigned int)pw->pw_uid) ;
  }

  for (;;)
  {
    struct group *gr ;
    char **p ;
    errno = 0 ;
    gr = nsss_all_getgrent() ;
    if (!gr) break ;
    p = gr->gr_mem ;
    lolprintf("%s:%s:%d:", gr->gr_name, gr->gr_passwd, (int)gr->gr_gid) ;
    if (*p)
    {
      while (*p) lolprintf("%s,", *p++) ;
      buffer_unput(buffer_1, 1) ;
    }
    buffer_put(buffer_1, "\n", 1) ;
  }
  if (errno)
    strerr_diefu1sys(111, "nsss_all_getgrent") ;
  nsss_all_endgrent() ;
  buffer_flush(buffer_1) ;  
  return 0 ;
}