Checking for existence of users and groups

Previous: user.c: implementation ] [ Top: The user module ] [ Next: Loading and saving users and groups ]

In this implementation, anyway, checking for the existence of a user or a group is as simple as checking the repository directory for the named file.

user_exists()
 
int user_exists(const char * user)
{
   char buf[1024];
   FILE * file;
   sprintf (buf, "%s%s", USER_REPOSITORY, user);
   file = fopen (buf, "r");
   if (file) {
      fclose (file);
      return 1;
   }
   return 0;
}


group_exists()
 
int group_exists(const char * group)
{
   char buf[1024];
   FILE * file;
   sprintf (buf, "%s%s", GROUP_REPOSITORY, group);
   file = fopen (buf, "r");
   if (file) {
      fclose (file);
      return 1;
   }
   return 0;
}
Previous: user.c: implementation ] [ Top: The user module ] [ Next: Loading and saving users and groups ]


This code and documentation are released under the terms of the GNU license. They are additionally copyright (c) 2000, Vivtek. All rights reserved except those explicitly granted under the terms of the GNU license.