Back to index

glibc  2.9
db.c
Go to the documentation of this file.
00001 #include <grp.h>
00002 #include <pwd.h>
00003 #include <sys/types.h>
00004 #include <unistd.h>
00005 #include <stdlib.h>
00006 
00007 int
00008 main (void)
00009 {
00010   uid_t me;
00011   struct passwd *my_passwd;
00012   struct group *my_group;
00013   char **members;
00014 
00015   /* Get information about the user ID. */
00016   me = getuid ();
00017   my_passwd = getpwuid (me);
00018   if (!my_passwd)
00019     {
00020       printf ("Couldn't find out about user %d.\n", (int) me);
00021       exit (EXIT_FAILURE);
00022     }
00023 
00024   /* Print the information. */
00025   printf ("I am %s.\n", my_passwd->pw_gecos);
00026   printf ("My login name is %s.\n", my_passwd->pw_name);
00027   printf ("My uid is %d.\n", (int) (my_passwd->pw_uid));
00028   printf ("My home directory is %s.\n", my_passwd->pw_dir);
00029   printf ("My default shell is %s.\n", my_passwd->pw_shell);
00030 
00031   /* Get information about the default group ID. */
00032   my_group = getgrgid (my_passwd->pw_gid);
00033   if (!my_group)
00034     {
00035       printf ("Couldn't find out about group %d.\n",
00036              (int) my_passwd->pw_gid);
00037       exit (EXIT_FAILURE);
00038     }
00039 
00040   /* Print the information. */
00041   printf ("My default group is %s (%d).\n",
00042          my_group->gr_name, (int) (my_passwd->pw_gid));
00043   printf ("The members of this group are:\n");
00044   members = my_group->gr_mem;
00045   while (*members)
00046     {
00047       printf ("  %s\n", *(members));
00048       members++;
00049     }
00050 
00051   return EXIT_SUCCESS;
00052 }