2 * Copyright (c) 1998 Denis Perchine <dyp@perchine.com>
3 * Copyright (c) 2004 Szombathelyi GyĂśrgy <gyurco@freemail.hu>
4 * Maintained by 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 version 2 as published by the Free Software Foundation.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
24 #include <sys/types.h>
27 #include <QSharedDataPointer>
35 class KU_User_Private
: public QSharedData
101 KU_User(const KU_User
*user
);
104 void copy(const KU_User
*user
);
105 bool operator ==(const KU_User
&other
) const;
108 KU_PROPERTY(int,Caps
);
109 KU_PROPERTY(QString
,Name
);
110 KU_PROPERTY(QString
,Surname
);
111 KU_PROPERTY(QString
,Email
);
112 KU_PROPERTY(QString
,Pwd
);
113 KU_PROPERTY(QString
,HomeDir
);
114 KU_PROPERTY(QString
,Shell
);
115 KU_PROPERTY(QString
,FullName
);
116 KU_PROPERTY(uid_t
,UID
);
117 KU_PROPERTY(uid_t
,GID
);
118 KU_PROPERTY(bool,Disabled
);
122 KU_PROPERTY(QString
,Office
);
123 KU_PROPERTY(QString
,WorkPhone
);
124 KU_PROPERTY(QString
,HomePhone
);
125 KU_PROPERTY(QString
,Class
);
127 KU_PROPERTY(QString
,Office1
);
128 KU_PROPERTY(QString
,Office2
);
129 KU_PROPERTY(QString
,Address
);
132 KU_PROPERTY(QString
,SPwd
);
133 KU_PROPERTY(time_t,Expire
);
134 KU_PROPERTY(time_t,LastChange
);
135 KU_PROPERTY(int,Min
);
136 KU_PROPERTY(int,Max
);
137 KU_PROPERTY(int,Warn
);
138 KU_PROPERTY(int,Inactive
);
139 KU_PROPERTY(int,Flag
);
142 KU_PROPERTY(QString
, LMPwd
);
143 KU_PROPERTY(QString
, NTPwd
);
144 KU_PROPERTY(QString
, LoginScript
);
145 KU_PROPERTY(QString
, ProfilePath
);
146 KU_PROPERTY(QString
, HomeDrive
);
147 KU_PROPERTY(QString
, HomePath
);
148 KU_PROPERTY(QString
, Workstations
);
149 KU_PROPERTY(QString
, Domain
);
150 KU_PROPERTY(SID
, SID
);
151 KU_PROPERTY(SID
, PGSID
);
154 KU_PROPERTY(bool, CreateHome
);
155 KU_PROPERTY(bool, CreateMailBox
);
156 KU_PROPERTY(bool, CopySkel
);
157 KU_PROPERTY(bool, DeleteHome
);
158 KU_PROPERTY(bool, DeleteMailBox
);
161 friend class KU_Users
;
164 int tryCreate(const QString
&dir
);
169 int removeCrontabs();
171 int removeProcesses();
173 QSharedDataPointer
<KU_User_Private
> d
;
176 class KU_Users
: public QList
<KU_User
> {
184 Cap_Disable_POSIX
= 32,
187 typedef QList
<KU_User
> AddList
;
188 typedef QList
<int> DelList
;
189 typedef QMap
<int, KU_User
> ModList
;
195 KU_Users(KU_PrefsBase
*cfg
);
198 int getCaps() const { return caps
; }
199 const QString
&getDOMSID() const;
201 int lookup(const QString
& name
) const;
202 int lookup(uid_t uid
) const;
203 int lookup_sam( const SID
&sid
) const;
204 int lookup_sam( const QString
&sid
) const;
205 int lookup_sam( uint rid
) const;
207 void add( const KU_User
&user
);
208 void del( int index
);
209 void mod( int index
, const KU_User
&newuser
);
219 * May be reimplemented in descendant classes.
220 * It should return the first available UID, or KU_Users::NO_FREE if no more UID.
222 virtual uid_t
first_free() const;
224 * May be reimplemented in descendant classes.
225 * It should return the first available user RID, or 0 if no more RID.
227 virtual uint
first_free_sam() const;
229 * Must be reimplemented in various backends. It should encode @param password
230 * into the appropriate fields in @param user.
232 virtual void createPassword( KU_User
&user
, const QString
&password
) = 0;
234 * Must load the users from the storage backend.
236 virtual bool reload() = 0;
238 * Must write changes (in mDel, mAdd and mMod) to the storage backend. It must
239 * write successful modifications into mDelSucc, mAddSucc and mModSucc.
241 virtual bool dbcommit() = 0;
243 const QString
&errorString() const { return mErrorString
; }
244 const QString
&errorDetails() const { return mErrorDetails
; }
245 bool doCreate( KU_User
*user
);
246 bool doDelete( KU_User
*user
);
256 QString mErrorString
, mErrorDetails
;
258 void parseGecos( const char *gecos
, QString
&name
,
259 QString
&field1
, QString
&field2
, QString
&field3
);
260 void fillGecos( KU_User
&user
, const char *gecos
);
263 #endif // _KU_USER_H_