OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [initial/] [uclinux/] [uC-libc/] [getent/] [test_pwd.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
 * test_pwd.c - This file is part of the libc-8086/pwd package for ELKS,
3
 * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>.
4
 *
5
 *  This library is free software; you can redistribute it and/or
6
 *  modify it under the terms of the GNU Library General Public
7
 *  License as published by the Free Software Foundation; either
8
 *  version 2 of the License, or (at your option) any later version.
9
 *
10
 *  This library is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 *  Library General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU Library General Public
16
 *  License along with this library; if not, write to the Free
17
 *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
 *
19
 */
20
 
21
#include <unistd.h>
22
#include <stdio.h>
23
#include <fcntl.h>
24
#include <pwd.h>
25
 
26
int
27
main(int argc, char ** argv)
28
{
29
  struct passwd * passwd;
30
  int test_uid;
31
 
32
  fprintf(stderr, "Beginning test of libc/pwd...\n");
33
 
34
  fprintf(stderr, "=> Testing setpwent(), getpwent(), endpwent()...\n");
35
  fprintf(stderr, "-> setpwent()...\n");
36
  setpwent();
37
  fprintf(stderr, "-> getpwent()...\n");
38
  printf("********************************************************************************\n");
39
  while ((passwd=getpwent())!=NULL)
40
    {
41
      printf("pw_name\t\t: %s\n", passwd->pw_name);
42
      printf("pw_passwd\t: %s\n", passwd->pw_passwd);
43
      printf("pw_uid\t\t: %d\n", (int) passwd->pw_uid);
44
      printf("pw_gid\t\t: %d\n", (int) passwd->pw_gid);
45
      printf("pw_gecos\t: %s\n", passwd->pw_gecos);
46
      printf("pw_dir\t\t: %s\n", passwd->pw_dir);
47
      printf("pw_shell\t: %s\n", passwd->pw_shell);
48
      printf("********************************************************************************\n");
49
    }
50
  fprintf(stderr, "-> endpwent()...\n");
51
  endpwent();
52
  fprintf(stderr, "=> Test of setpwent(), getpwent(), endpwent() complete.\n");
53
  fprintf(stderr, "=> Testing getpwuid(), getpwnam()...\n");
54
  fprintf(stderr, "-> getpwuid()...\n");
55
  printf("********************************************************************************\n");
56
  for(test_uid=0;test_uid<1000;test_uid++)
57
    {
58
      fprintf(stderr, "-> getpwuid(%d)...\n", test_uid);
59
      passwd=getpwuid((uid_t) test_uid);
60
      if (passwd!=NULL)
61
        {
62
          printf("pw_name\t\t: %s\n", passwd->pw_name);
63
          printf("pw_passwd\t: %s\n", passwd->pw_passwd);
64
          printf("pw_uid\t\t: %d\n", (int) passwd->pw_uid);
65
          printf("pw_gid\t\t: %d\n", (int) passwd->pw_gid);
66
          printf("pw_gecos\t: %s\n", passwd->pw_gecos);
67
          printf("pw_dir\t\t: %s\n", passwd->pw_dir);
68
          printf("pw_shell\t: %s\n", passwd->pw_shell);
69
      printf("********************************************************************************\n");
70
        }
71
    }
72
  fprintf(stderr, "-> getpwnam()...\n");
73
  passwd=getpwnam("root");
74
  if (passwd==NULL)
75
    {
76
      printf(">NULL<\n");
77
    }
78
  else
79
    {
80
      printf("pw_name\t\t: %s\n", passwd->pw_name);
81
      printf("pw_passwd\t: %s\n", passwd->pw_passwd);
82
      printf("pw_uid\t\t: %d\n", (int) passwd->pw_uid);
83
      printf("pw_gid\t\t: %d\n", (int) passwd->pw_gid);
84
      printf("pw_gecos\t: %s\n", passwd->pw_gecos);
85
      printf("pw_dir\t\t: %s\n", passwd->pw_dir);
86
      printf("pw_shell\t: %s\n", passwd->pw_shell);
87
    }
88
  return 0;
89
}
90
 
91
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.