summaryrefslogtreecommitdiffstats
path: root/kuser/kgroup.cpp
blob: 77fcc91df903b686c019ba3e4177670c85e50d30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/*
 *  Copyright (c) 1998 Denis Perchine <dyp@perchine.com>
 *  Copyright (c) 2004 Szombathelyi Gy├Ârgy <gyurco@freemail.hu>
 *  Former maintainer: Adriaan de Groot <groot@kde.org>
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public
 *  License version 2 as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 **/

#include <tqstring.h>

#include <kdebug.h>

#include "kglobal_.h"
#include "kgroup.h"
#include "misc.h"

KU::KGroup::KGroup()
{
  pwd = TQString::fromLatin1("*");
  gid = 0;
  type = 2;
  caps = 0;
}

KU::KGroup::KGroup(KU::KGroup *group) 
{
  copy( group );
}

KU::KGroup::~KGroup()
{
}

void KU::KGroup::copy( const KU::KGroup *group )
{
  if ( group != this ) {
    caps    = group->caps;
    name    = group->name;
    pwd     = group->pwd;
    gid     = group->gid;
    sid     = group->sid;
    type    = group->type;
    displayname = group->displayname;
    desc    = group->desc;
    u       = group->u;
  }
}

void KU::KGroup::setCaps( int data )
{
  caps = data;
}

int KU::KGroup::getCaps()
{
  return caps;
}

const TQString &KU::KGroup::getName() const 
{
  return name;
}

const TQString &KU::KGroup::getPwd() const 
{
  return pwd;
}

gid_t KU::KGroup::getGID() const 
{
  return gid;
}

const SID &KU::KGroup::getSID() const
{
  return sid;
}

int KU::KGroup::getType() const
{
  return type;
}

const TQString &KU::KGroup::getDisplayName() const
{
  return displayname;
}

const TQString &KU::KGroup::getDesc() const
{
  return desc;
}

void KU::KGroup::setName(const TQString &data) 
{
  name = data;
}

void KU::KGroup::setPwd(const TQString &data) 
{
  pwd = data;
}

void KU::KGroup::setGID(gid_t data) 
{
  gid = data;
}

void KU::KGroup::setSID(const SID &data)
{
  sid = data;
}

void KU::KGroup::setType(int data)
{
  type = data;
}

void KU::KGroup::setDisplayName(const TQString &data)
{
  displayname = data;
}

void KU::KGroup::setDesc(const TQString &data)
{
  desc = data;
}

bool KU::KGroup::lookup_user(const TQString &name) 
{
  return (u.find(name) != u.end());
}

bool KU::KGroup::addUser(const TQString &name) 
{
  if (!lookup_user(name)) {
    u.append(name);
    return true;
  } else
    return false;
}

bool KU::KGroup::removeUser(const TQString &name) 
{
  return ( u.remove(name) > 0 );
}

uint KU::KGroup::count() const 
{
  return u.count();
}

TQString KU::KGroup::user(uint i) 
{
  return u[i];
}

void KU::KGroup::clear() 
{
  u.clear();
}

KU::KGroups::KGroups(KUserPrefsBase *cfg) 
{
  mGroups.setAutoDelete(TRUE);
  mCfg = cfg;
}

KU::KGroup *KU::KGroups::lookup(const TQString &name) 
{
  KU::KGroup *group;
  TQPtrListIterator<KU::KGroup> it( mGroups );
  
  while ( (group = it.current()) != 0 && group->getName() != name ) ++it;
  return group;
}

KU::KGroup *KU::KGroups::lookup(gid_t gid) 
{
  KU::KGroup *group;
  TQPtrListIterator<KU::KGroup> it( mGroups );
  
  while ( (group = it.current()) != 0 && group->getGID() != gid ) ++it;
  return group;
}

KU::KGroup *KU::KGroups::lookup_sam( const SID &sid )
{
  KU::KGroup *group;
  TQPtrListIterator<KU::KGroup> it( mGroups );
  
  while ( (group = it.current()) != 0 && group->getSID() != sid ) ++it;
  return group;
}

KU::KGroup *KU::KGroups::lookup_sam( const TQString &sid )
{
  KU::KGroup *group;
  TQPtrListIterator<KU::KGroup> it( mGroups );
  
  while ( (group = it.current()) != 0 && group->getSID().getSID() != sid ) ++it;
  return group;
}

KU::KGroup *KU::KGroups::lookup_sam( uint rid )
{
  KU::KGroup *group;
  TQPtrListIterator<KU::KGroup> it( mGroups );
  
  while ( (group = it.current()) != 0 && group->getSID().getRID() != rid ) ++it;
  return group;
}

gid_t KU::KGroups::first_free() 
{
  gid_t t;

  for (t = mCfg->firstGID(); t<65534; t++)
    if (lookup(t) == NULL)
      return t;

  return NO_FREE;
}

uint KU::KGroups::first_free_sam()
{
  uint t;

  for (t = 30000; t<65534; t++)
    if (lookup_sam(t) == NULL)
      return t;

  return 0;
}

KU::KGroups::~KGroups() 
{
  mGroups.clear();
}

KU::KGroup *KU::KGroups::operator[](uint num) 
{
  return mGroups.at(num);
}

KU::KGroup *KU::KGroups::first() 
{
  return mGroups.first();
}

KU::KGroup *KU::KGroups::next() 
{
  return mGroups.next();
}

uint KU::KGroups::count() const 
{
  return mGroups.count();
}

const TQString &KU::KGroups::getDOMSID() const
{
  return domsid;
}

void KU::KGroups::add(KU::KGroup *group) 
{
  kdDebug() << "adding group: " << group->getName() << " gid: " << group->getGID() << endl;
  mAdd.append( group );
}

void KU::KGroups::del(KU::KGroup *group) 
{
  kdDebug() << "deleting group: " << group->getName() << " gid: " << group->getGID() << endl;
  mDel.append( group );
}

void KU::KGroups::mod(KU::KGroup *gold, const KU::KGroup &gnew)
{
  kdDebug() << "modify group " << gnew.getName() << " gid: " << gnew.getGID() << endl;
  mMod.insert( gold, gnew );
}

void KU::KGroups::commit()
{
  kdDebug() << "KU::KGroups::commit()" << endl;
  KU::KGroup *group;
  DelIt dit( mDelSucc );
  AddIt ait( mAddSucc );
  ModIt mit = mModSucc.begin();
    
  while ( mit != mModSucc.end() ) {
    *(mit.key()) = mit.data();
    mit++;
  }
  while ( (group = dit.current()) != 0 ) {
    ++dit;
    mGroups.remove( group );
  }
  while ( (group = ait.current()) != 0 ) {
    ++ait;
    mGroups.append( group );
  }
  cancelMods();  
}

void KU::KGroups::cancelMods()
{
  KU::KGroup *group;
  while ( (group = mAdd.first()) ) {
    delete group;
    mAdd.remove();
  }
  mDel.clear();
  mMod.clear();
}