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 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.
22 #include <QSharedData>
27 KU_Group_Private::KU_Group_Private()
29 Pwd
= QString::fromLatin1("*");
37 d
= new KU_Group_Private
;
40 KU_Group::KU_Group(KU_Group
*group
)
42 d
= new KU_Group_Private
;
50 void KU_Group::copy( const KU_Group
*group
)
52 if ( group
!= this ) {
57 bool KU_Group::operator ==(const KU_Group
&other
) const
59 if ( getGID() == other
.getGID() &&
60 getName() == other
.getName() )
66 KU_PROPERTY_IMPL(KU_Group
,int, Caps
)
68 KU_PROPERTY_IMPL(KU_Group
,QString
, Name
)
69 KU_PROPERTY_IMPL(KU_Group
,QString
, Pwd
)
70 KU_PROPERTY_IMPL(KU_Group
,gid_t
, GID
)
73 KU_PROPERTY_IMPL(KU_Group
,SID
, SID
)
74 KU_PROPERTY_IMPL(KU_Group
,int, Type
)
75 KU_PROPERTY_IMPL(KU_Group
,QString
, DisplayName
)
76 KU_PROPERTY_IMPL(KU_Group
,QString
, Desc
)
78 bool KU_Group::lookup_user(const QString
&name
) const
80 return d
->users
.contains(name
);
83 bool KU_Group::addUser(const QString
&name
)
85 if (!lookup_user(name
)) {
86 d
->users
.append(name
);
92 bool KU_Group::removeUser(const QString
&name
)
94 return ( d
->users
.removeAll(name
) > 0 );
97 uint
KU_Group::count() const
99 return d
->users
.count();
102 QString
KU_Group::user(uint i
) const
107 void KU_Group::clear()
112 KU_Groups::KU_Groups(KU_PrefsBase
*cfg
)
117 int KU_Groups::lookup(const QString
&name
) const
119 for ( int i
= 0; i
<count(); i
++ ) {
120 if ( at(i
).getName() == name
) return i
;
125 int KU_Groups::lookup(gid_t gid
) const
127 for ( int i
= 0; i
<count(); i
++ ) {
128 if ( at(i
).getGID() == gid
) return i
;
133 int KU_Groups::lookup_sam( const SID
&sid
) const
135 for ( int i
= 0; i
<count(); i
++ ) {
136 if ( at(i
).getSID() == sid
) return i
;
141 int KU_Groups::lookup_sam( const QString
&sid
) const
143 for ( int i
= 0; i
<count(); i
++ ) {
144 if ( at(i
).getSID().getSID() == sid
) return i
;
149 int KU_Groups::lookup_sam( uint rid
) const
151 for ( int i
= 0; i
<count(); i
++ ) {
152 if ( at(i
).getSID().getRID() == rid
) return i
;
157 gid_t
KU_Groups::first_free() const
161 for (t
= mCfg
->firstGID(); t
<65534; t
++)
168 uint
KU_Groups::first_free_sam() const
172 for (t
= 30000; t
<65534; t
++)
173 if (lookup_sam(t
) == -1)
179 KU_Groups::~KU_Groups()
183 const QString
&KU_Groups::getDOMSID() const
188 void KU_Groups::add(const KU_Group
&group
)
190 kDebug() << "adding group: " << group
.getName() << " gid: " << group
.getGID();
191 mAdd
.append( group
);
194 void KU_Groups::del(int index
)
196 kDebug() << "deleting group: " << at(index
).getName() << " gid: " << at(index
).getGID();
197 mDel
.append( index
);
200 void KU_Groups::mod(int index
, const KU_Group
&newgroup
)
202 kDebug() << "modify group " << newgroup
.getName() << " gid: " << newgroup
.getGID();
203 mMod
.insert( index
, newgroup
);
206 void KU_Groups::commit()
208 kDebug() << "KU_Groups::commit()";
210 for ( ModList::Iterator it
= mModSucc
.begin(); it
!= mModSucc
.end(); ++it
) {
211 replace(it
.key(),*it
);
213 for ( AddList::Iterator it
= mAddSucc
.begin(); it
!= mAddSucc
.end(); ++it
) {
216 for ( DelList::Iterator it
= mDelSucc
.begin(); it
!= mDelSucc
.end(); ++it
) {
222 void KU_Groups::cancelMods()