[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: pwdb question



> 	Now, since pwdb shoud handle all accesses to the password
> databases, shouldn't all applications be linked against libpwdb?

  Perhaps.  But that may be a little much to ask for many
cross-platform apps.

> Since
> everybody speaks about the slowliness of a box with more than 2k users,
> one can think of moving the entire /etc/passwd model to a different thing
> (like gdbm or sql). Probably pwdb should do this, but a quick check showed
> me that wu-ftpd, ipop3 and all other usual servers are NOT pwdb-aware. I
> know, it would take a HUGE amount of work to do it; should somebody do it?

  Another interim solution would be to hack libpwd to be a little
faster.

 see: libpwdb-0.54preD/libpwdb/unix/passwd.c

  When looking for a user 'foo', it reads AND PARSES all of the
password entries for all of the users prior to 'foo'.  It should be
possible to hack the '__pwdb_getpwnam' function to do things a little
more efficiently.

  Hmm.. it's untested, but try something like the following patch.  It
fixes getpwnam to use a little more efficient algorithm.  Instead of
parsing every entry, it only parses the entries that have the first
two characters matching.  This should cut down on the calls to
__pwdb_sgetpwent (which does a LOT of work) by a facter of a few
hundred.

  Try it on a test system before putting into production, of course.

  Alan DeKok.


--- cut here ----
*** passwd.c	Tue May  5 12:37:37 1998
--- passwd.c.new	Tue May  5 12:38:42 1998
***************
*** 4,7 ****
--- 4,10 ----
   * Support for these extensions should go into a separate
   * source file, in separate functions
+  *
+  * PATCH test-1 by Alan DeKok.  Possibly speeds up getpwnam() when searching
+  * through large passwd files.
   */
  
***************
*** 120,123 ****
--- 123,150 ----
  
  /*
+  * fgetpwnam - get a selected password file entry from a stream.
+  *
+  * fgetpwent() reads the next line from a password file formatted
+  * stream and returns a pointer to the password structure for that
+  * line if the password entry name NEARLY matches the given name.
+  */
+ 
+ struct __pwdb_passwd * __pwdb_fgetpwnam (FILE *fp, char *name)
+ {
+     char	buf[BUFSIZ];
+ 
+     passwd_file_end = 1;
+     while (fgets (buf, BUFSIZ, fp) != (char *) 0) {
+       passwd_file_end = 0; 
+       if ((name[0] == buf[0]) && (name[1]) && (buf[1] != ':') &&
+ 	  (name[1] == buf[1])) {
+ 	buf[strlen (buf) - 1] = '\0'; /* only do this as necessary */
+ 	return (__pwdb_sgetpwent (buf));
+       }
+     }
+     return 0;
+ }
+ 
+ /*
   * endpwent - close a password file
   *
***************
*** 228,232 ****
       */
      do {
!         pwd = __pwdb_getpwent();
          if (pwd && (strcmp (pwd->pw_name, name) == 0))
              break;
--- 255,259 ----
       */
      do {
!         pwd = __pwdb_fgetpwnam(pwdfp, name);
          if (pwd && (strcmp (pwd->pw_name, name) == 0))
              break;
--- cut here ----



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index] []