lib/misc/pwentry_table.cc
changeset 0 6f7a81934006
equal deleted inserted replaced
-1:000000000000 0:6f7a81934006
       
     1 // Copyright (C) 1999,2000 Bruce Guenter <bruceg@em.ca>
       
     2 //
       
     3 // This program is free software; you can redistribute it and/or modify
       
     4 // it under the terms of the GNU General Public License as published by
       
     5 // the Free Software Foundation; either version 2 of the License, or
       
     6 // (at your option) any later version.
       
     7 //
       
     8 // This program is distributed in the hope that it will be useful,
       
     9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    11 // GNU General Public License for more details.
       
    12 //
       
    13 // You should have received a copy of the GNU General Public License
       
    14 // along with this program; if not, write to the Free Software
       
    15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
    16 
       
    17 #include <config.h>
       
    18 #include "pwentry_table.h"
       
    19 #include <pwd.h>
       
    20 #include <ctype.h>
       
    21 #include "config/configrc.h"
       
    22 #ifdef HAVE_SHADOW_H
       
    23 #include <shadow.h>
       
    24 #endif
       
    25 
       
    26 #if 0
       
    27 
       
    28 pwentry_table::pwentry_table()
       
    29   : valid(false)
       
    30 {
       
    31   setpwent();
       
    32   const passwd* pw;
       
    33   while((pw = getpwent()) != 0) {
       
    34     for(char* ptr = pw->pw_name; *ptr != 0; ptr++)
       
    35       if(isupper(*ptr))
       
    36 	*ptr = tolower(*ptr);
       
    37     insert(pw->pw_name, new pwentry(pw->pw_name, pw->pw_passwd,
       
    38 				    pw->pw_uid, pw->pw_gid, pw->pw_dir));
       
    39   }
       
    40   endpwent();
       
    41 #ifdef HAVE_SHADOW_H
       
    42   // Adjust all the users that have a shadow password
       
    43   const spwd* spw;
       
    44   setspent();
       
    45   while((spw = getspent()) != 0) {
       
    46     pwentry* pw = (*this)[spw->sp_namp];
       
    47     if(pw)
       
    48       pw->pass = spw->sp_pwdp;
       
    49   }
       
    50   endspent();
       
    51 #endif
       
    52   valid = true;
       
    53 }
       
    54 
       
    55 pwentry_table::~pwentry_table()
       
    56 {
       
    57 }
       
    58 
       
    59 #else
       
    60 
       
    61 pwentry* pwentry_table::operator[](const mystring& name) const
       
    62 {
       
    63   struct passwd* pw = getpwnam(name.c_str());
       
    64   if(!pw)
       
    65     return 0;
       
    66 #ifdef HAVE_SHADOW_H
       
    67   struct spwd* spw = getspnam(name.c_str());
       
    68   if(spw)
       
    69     pw->pw_passwd = spw->sp_pwdp;
       
    70 #endif
       
    71   return new pwentry(*pw);
       
    72 }
       
    73 
       
    74 #endif