summaryrefslogtreecommitdiffstats
path: root/kuser/sid.cpp
blob: 01cdf0e7d93fbe9e2183164e44397edf9bcd9d4d (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
/*
 *  Copyright (c) 2004 Szombathelyi György <gyurco@freemail.hu>
 *
 *  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 "sid.h"
#include <kdebug.h> 
//From Samba
/* Take the bottom bit. */
#define RID_MULTIPLIER 2

/* The two common types. */
#define USER_RID_TYPE 0
#define GROUP_RID_TYPE 1

uint SID::mAlgRidBase = 1000;

SID::SID()
{
  mRid = 0; mSid = TQString::null; mDom = TQString::null;
}

SID::SID( const SID &sid )
{
  setSID( sid.getSID() );
}

SID::SID( const TQString &sid )
{
  setSID( sid );
}

SID::~SID()
{
}

uint SID::uid2rid( uint uid )
{
  return( (( uid*RID_MULTIPLIER ) + mAlgRidBase ) | USER_RID_TYPE );
}

uint SID::gid2rid( uint gid )
{
  return( (( gid*RID_MULTIPLIER ) + mAlgRidBase ) | GROUP_RID_TYPE );
}

bool SID::operator == ( const SID &sid ) const
{
  return ( mSid  == sid.mSid && mDom == sid.mDom );
}

bool SID::operator != ( const SID&sid ) const
{
  return ( mSid  != sid.mSid || mDom != sid.mDom );
}

bool SID::isEmpty() const
{
  return ( ( mSid.isEmpty() || mRid == 0 ) && mDom.isEmpty() );
}

void SID::updateSID()
{
  mSid = mDom + TQString::fromLatin1("-") + TQString::number( mRid );
}

void SID::setSID( const TQString &sid )
{
  int pos;
  TQString rid;
  
  mSid = sid;
  pos = sid.findRev( '-' );
  mDom = sid.left( pos );
  rid = sid.right( sid.length() - pos - 1 );
  mRid = rid.toUInt();
}

void SID::setRID( const TQString &rid )
{
  mRid = rid.toUInt();
  updateSID();
}

void SID::setRID( uint rid )
{
  mRid = rid;
  updateSID();
}

void SID::setDOM( const TQString &dom )
{
  mDom = dom;
  updateSID();
}

const TQString& SID::getSID() const
{
  return mSid;
}

uint SID::getRID() const
{
  return mRid;
}

const TQString& SID::getDOM() const
{
  return mDom;
}