2 * Copyright (c) 1998 Denis Perchine <dyp@perchine.com>
3 * Copyright (c) 2004 Szombathelyi György <gyurco@freemail.hu>
4 * Former maintainer: Adriaan de Groot <groot@kde.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
32 #include "ku_usersystem.h"
34 KU_UserSystem::KU_UserSystem(KU_PrefsBase
*cfg
) : KU_Users( cfg
)
36 caps
= Cap_ReadOnly
| Cap_Passwd
;
38 if ( !mCfg
->shadowsrc().isEmpty() ) caps
|= Cap_Shadow
;
40 #if defined(__FreeBSD__) || defined(__bsdi__)
46 KU_UserSystem::~KU_UserSystem()
50 bool KU_UserSystem::reload()
52 mErrorString
= mErrorDetails
= QString();
64 bool KU_UserSystem::loadpwd()
70 setpwent(); //This should be enough for BSDs
71 while ((p
= getpwent()) != NULL
) {
73 user
.setCaps( KU_User::Cap_POSIX
);
74 user
.setUID(p
->pw_uid
);
75 user
.setGID(p
->pw_gid
);
76 user
.setName(QString::fromLocal8Bit(p
->pw_name
));
77 tmp
= QString::fromLocal8Bit( p
->pw_passwd
);
78 if ( tmp
!= "x" && tmp
!= "*" && !tmp
.startsWith('!') )
79 user
.setDisabled( false );
81 user
.setDisabled( true );
82 if ( tmp
.startsWith('!') ) tmp
.remove(0, 1);
84 user
.setHomeDir(QString::fromLocal8Bit(p
->pw_dir
));
85 user
.setShell(QString::fromLocal8Bit(p
->pw_shell
));
86 #if defined(__FreeBSD__) || defined(__bsdi__)
87 user
.setClass(QString::fromLatin1(p
->pw_class
));
88 user
.setLastChange(p
->pw_change
);
89 user
.setExpire(p
->pw_expire
);
92 if ((p
->pw_gecos
!= 0) && (p
->pw_gecos
[0] != 0))
93 fillGecos(user
, p
->pw_gecos
);
101 // Load shadow passwords
103 bool KU_UserSystem::loadsdw()
112 while ((spw
= getspent())) { // read a shadow password structure
115 if ((index
= lookup(QString::fromLocal8Bit(spw
->sp_namp
))) == -1) {
120 tmp
= QString::fromLocal8Bit( spw
->sp_pwdp
);
121 if ( tmp
.startsWith("!!") || tmp
== "*" ) {
122 user
.setDisabled( true );
125 user
.setDisabled( false );
127 user
.setSPwd( tmp
); // cp the encrypted pwd
128 user
.setLastChange( daysToTime( spw
->sp_lstchg
) );
129 user
.setMin(spw
->sp_min
);
130 user
.setMax(spw
->sp_max
);
132 user
.setWarn(spw
->sp_warn
);
133 user
.setInactive(spw
->sp_inact
);
134 user
.setExpire( daysToTime( spw
->sp_expire
) );
135 user
.setFlag(spw
->sp_flag
);
137 replace( index
, user
);
141 #endif //HAVE_SHADOW_H