Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <grp.h>
  6.  
  7. static int init = 0;
  8. static char *grp = 0;
  9. static struct group g;
  10. static char *mem[2];
  11. static char def_name[] = "user";
  12. static char def_grp[] = "dos";
  13.  
  14. static void
  15. grp_init(void)
  16. {
  17.   char *p;
  18.   p = getenv("USER");
  19.   if (p == 0)
  20.     p = getenv("LOGNAME");
  21.   if (p)
  22.   {
  23.     mem[0] = (char *)malloc(strlen(p) + 1);
  24.     if (mem[0] == 0)
  25.       mem[0] = def_name;
  26.     else
  27.       strcpy(mem[0], p);
  28.   }
  29.   else
  30.     mem[0] = def_name;
  31.   mem[1] = 0;
  32.  
  33.   p = getenv("GROUP");
  34.   if (p)
  35.   {
  36.     grp = (char *)malloc(strlen(p)+1);
  37.     if (grp == 0)
  38.       grp = def_grp;
  39.     else
  40.       strcpy(grp, p);
  41.   }
  42.   else
  43.     grp = def_grp;
  44.  
  45.   g.gr_gid = getgid();
  46.   g.gr_mem = mem;
  47.   g.gr_name = grp;
  48. }
  49.  
  50. struct group *
  51. getgrgid(gid_t gid)
  52. {
  53.   if (gid != getgid())
  54.     return 0;
  55.   if (init == 0)
  56.     grp_init();
  57.   return &g;
  58. }
  59.  
  60. struct group *
  61. getgrnam(const char *name)
  62. {
  63.   if (init == 0)
  64.     grp_init();
  65.   if (strcmp(name, grp))
  66.     return 0;
  67.   return &g;
  68. }
  69.