summaryrefslogtreecommitdiff
path: root/src/libnsss/nsss_unix_pwd_getbyuid.c
blob: 4964cdda5f3e085e54cbc074f3e509fc44ce7a39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* ISC license. */

#include <sys/types.h>
#include <nsss/pwd-def.h>
#include <nsss/nsss-unix.h>

int nsss_unix_pwd_getbyuid (nsss_unix_t *a, struct passwd *pw, stralloc *sa, uid_t uid)
{
  struct passwd pw2 ;
  for (;;)
  {
    size_t base = sa->len ;
    if (!nsss_unix_pwd_get(a, &pw2, sa)) return 0 ;
    if (uid == pw2.pw_uid) break ;
    sa->len = base ;
  }
  *pw = pw2 ;
  return 1 ;
}