]> sourceware.org Git - newlib-cygwin.git/blobdiff - winsup/cygwin/passwd.cc
* cygheap.cc (init_cygheap::etc_changed): New method to signal
[newlib-cygwin.git] / winsup / cygwin / passwd.cc
index f29eb2018fe0b6d319fcb0258c93e5b05547e2e4..f6943cda8a592202f23c9178d212674e21123c44 100644 (file)
@@ -1,6 +1,6 @@
 /* passwd.cc: getpwnam () and friends
 
-   Copyright 1996, 1997, 1998 Cygnus Solutions.
+   Copyright 1996, 1997, 1998, 2001 Cygnus Solutions.
 
 This file is part of Cygwin.
 
@@ -17,30 +17,23 @@ details. */
 #include "security.h"
 #include "fhandler.h"
 #include "dtable.h"
+#include "path.h"
 #include "sync.h"
 #include "sigproc.h"
 #include "pinfo.h"
 #include "cygheap.h"
 #include <sys/termios.h>
+#include "pwdgrp.h"
 
 /* Read /etc/passwd only once for better performance.  This is done
    on the first call that needs information from it. */
 
-static struct passwd *passwd_buf = NULL;       /* passwd contents in memory */
-static int curr_lines = 0;
-static int max_lines = 0;
-
-/* Set to loaded when /etc/passwd has been read in by read_etc_passwd ().
-   Set to emulated if passwd is emulated. */
-/* Functions in this file need to check the value of passwd_state
-   and read in the password file if it isn't set. */
-enum pwd_state {
-  uninitialized = 0,
-  initializing,
-  emulated,
-  loaded
-};
-static pwd_state passwd_state = uninitialized;
+static struct passwd *passwd_buf;      /* passwd contents in memory */
+static int curr_lines;
+static int max_lines;
+
+static pwdgrp_check passwd_state;
+
 
 /* Position in the passwd cache */
 #ifdef _MT_SAFE
@@ -140,6 +133,13 @@ read_etc_passwd ()
     if (passwd_state != initializing)
       {
        passwd_state = initializing;
+       if (max_lines) /* When rereading, free allocated memory first. */
+         {
+           for (int i = 0; i < curr_lines; ++i)
+             free (passwd_buf[i].pw_name);
+           free (passwd_buf);
+           curr_lines = max_lines = 0;
+         }
 
        FILE *f = fopen ("/etc/passwd", "rt");
 
@@ -151,6 +151,7 @@ read_etc_passwd ()
                  add_pwd_line (linebuf);
              }
 
+           passwd_state.set_last_modified (f);
            fclose (f);
            passwd_state = loaded;
          }
@@ -327,36 +328,24 @@ getpwent (void)
 extern "C" struct passwd *
 getpwduid (uid_t)
 {
-  if (passwd_state  <= initializing)
-    read_etc_passwd ();
-
   return NULL;
 }
 
 extern "C" void
 setpwent (void)
 {
-  if (passwd_state  <= initializing)
-    read_etc_passwd ();
-
   pw_pos = 0;
 }
 
 extern "C" void
 endpwent (void)
 {
-  if (passwd_state  <= initializing)
-    read_etc_passwd ();
-
   pw_pos = 0;
 }
 
 extern "C" int
 setpassent ()
 {
-  if (passwd_state  <= initializing)
-    read_etc_passwd ();
-
   return 0;
 }
 
This page took 0.024014 seconds and 5 git commands to generate.