Proof-reading - fixed one usage of the i18n plural form (it wasn't doing before,...
[kdeadmin.git] / kuser / ku_user.h
blobb94bd63671aec39a234b40bbb374e2ef51705157
1 /*
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.
19 **/
21 #ifndef _KU_USER_H_
22 #define _KU_USER_H_
24 #include <sys/types.h>
27 #include <QSharedDataPointer>
29 #include "globals.h"
30 #include "ku_prefs.h"
31 #include "sid.h"
33 class KU_Users;
35 class KU_User_Private: public QSharedData
37 public:
38 KU_User_Private();
40 int Caps;
41 QString Name;
42 QString Surname;
43 QString Email;
44 QString Pwd;
45 QString HomeDir;
46 QString Shell;
47 QString FullName;
48 uid_t UID;
49 uid_t GID;
50 bool Disabled;
52 //gecos
53 //--BSD gecos
54 QString Office;
55 QString WorkPhone;
56 QString HomePhone;
57 QString Class;
58 //--BSD end
59 QString Office1;
60 QString Office2;
61 QString Address;
63 //shadow
64 QString SPwd;
65 time_t Expire;
66 time_t LastChange;
67 int Min;
68 int Max;
69 int Warn;
70 int Inactive;
71 int Flag;
73 //samba
74 QString LMPwd;
75 QString NTPwd;
76 QString LoginScript;
77 QString ProfilePath;
78 QString HomeDrive;
79 QString HomePath;
80 QString Workstations;
81 QString Domain;
82 class SID SID;
83 class SID PGSID;
85 //Administrative
86 bool CreateHome;
87 bool CreateMailBox;
88 bool CopySkel;
89 bool DeleteHome;
90 bool DeleteMailBox;
93 class KU_User {
94 public:
96 enum Cap {
97 Cap_POSIX = 1,
98 Cap_Samba = 2
100 KU_User();
101 KU_User(const KU_User *user);
102 ~KU_User();
104 void copy(const KU_User *user);
105 bool operator ==(const KU_User &other) const;
107 //General
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);
120 //gecos
121 //--BSD gecos
122 KU_PROPERTY(QString,Office);
123 KU_PROPERTY(QString,WorkPhone);
124 KU_PROPERTY(QString,HomePhone);
125 KU_PROPERTY(QString,Class);
126 //--BSD end
127 KU_PROPERTY(QString,Office1);
128 KU_PROPERTY(QString,Office2);
129 KU_PROPERTY(QString,Address);
131 //shadow
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);
141 //samba
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);
153 //Administrative
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);
160 protected:
161 friend class KU_Users;
163 int createHome();
164 int tryCreate(const QString &dir);
165 int createMailBox();
166 int copySkel();
168 int removeHome();
169 int removeCrontabs();
170 int removeMailBox();
171 int removeProcesses();
172 private:
173 QSharedDataPointer<KU_User_Private> d;
176 class KU_Users : public QList<KU_User> {
177 public:
178 enum Cap {
179 Cap_ReadOnly = 1,
180 Cap_Passwd = 2,
181 Cap_Shadow = 4,
182 Cap_InetOrg = 8,
183 Cap_Samba = 16,
184 Cap_Disable_POSIX = 32,
185 Cap_BSD = 64
187 typedef QList<KU_User> AddList;
188 typedef QList<int> DelList;
189 typedef QMap<int, KU_User> ModList;
191 AddList mAddSucc;
192 DelList mDelSucc;
193 ModList mModSucc;
195 KU_Users(KU_PrefsBase *cfg);
196 virtual ~KU_Users();
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 );
210 void commit();
212 void cancelMods();
214 enum {
215 NO_FREE = (uid_t) -1
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 );
247 protected:
248 int caps;
249 KU_PrefsBase *mCfg;
251 AddList mAdd;
252 DelList mDel;
253 ModList mMod;
255 QString domsid;
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_