rasdaman complete source
Main Page
Modules
Namespaces
Classes
Files
File List
File Members
rasmgr
rasmgr_users.hh
Go to the documentation of this file.
1
/*
2
* This file is part of rasdaman community.
3
*
4
* Rasdaman community is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
8
*
9
* Rasdaman community is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
16
*
17
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
18
rasdaman GmbH.
19
*
20
* For more information please see <http://www.rasdaman.org>
21
* or contact Peter Baumann via <baumann@rasdaman.com>.
22
/
37
#ifndef RASMGR_USERS_HH
38
#define RASMGR_USERS_HH
39
40
#include "rasmgr.hh"
41
#include "rasmgr_config.hh"
42
#include "rasmgr_dbm.hh"
43
44
enum AdminRight
45
{
46
admR_none = 0,
47
admR_config= 1, // C
48
admR_acctrl= 2, // A
49
admR_sysup = 4, // S - up-down
50
admR_info = 8, // I
51
admR_full =255
52
};
53
54
enum DatabRight // maybe we'll put them together one day
55
{
56
dbR_none = 0<<8,
57
dbR_read = 1<<8, // R
58
dbR_write = 2<<8 // W
59
};
60
61
struct UserDBRight
62
{
63
Database *ptrDatabase;
64
int databRight;
65
};
66
67
// For persistency
68
#define AUTHFILEID 26012001
69
#define AUTHFILEVERS 2;
70
71
struct AuthFileHeader
72
{
73
long fileID;
74
long fileVersion;
75
long headerLength;
76
long lastUserID;
77
char hostName[100];
78
long countUsers;
79
unsigned char messageDigest[35];
80
int globalInitAdmR;
81
int globalInitDbsR;
82
char _unused[100];
83
};
84
85
struct AuthUserRec
86
{
87
long userID;
88
char userName[100];
89
char passWord[50];
90
91
int adminRight;
92
int databRight;
93
long countRights;
94
char _unused[32];
95
};
96
97
struct AuthDbRRec
98
{
99
char dbName[100];
100
int right;
101
};
102
//++++++++++++++++++++++++++++++++++++++++++++++++
103
107
class User
108
{
109
public:
110
User();
111
void init(long userID, const char *name);
112
void changeName(const char *name);
113
void changePassword(const char *encrPass);
114
void changePTPassword(const char *plainTextPass);
115
116
const char* getName();
117
118
long getUserID();
119
120
bool isThisMe(const char *name,const char *encrPass);
121
122
void setAdminRights(int rights);
123
bool hasAdminRights(int rights);
124
int getAdminRights();
125
126
127
void setDefaultDBRights(int);
128
int getDefaultDBRights();
129
130
int getEffectiveDatabaseRights(const char *databName);
131
bool setDatabaseRights(const char *databName,int rights);
132
bool removeDatabaseRights(const char *databName);
133
bool isTrusteeOn(const char *databName);
134
135
void loadToRec(AuthUserRec&);
136
void loadFromRec(AuthUserRec&);
137
138
long countRights();
139
bool loadRightToRec(int,AuthDbRRec&);
140
bool loadRightFromRec(AuthDbRRec&);
141
bool isValid();
142
private:
143
long userID;
144
char userName[100];
145
char passWord[50];
146
147
int adminRight;
148
int databRight;
149
150
list<UserDBRight> dbRList;
151
bool valid;
152
};
153
157
class UserManager
158
{
159
public:
160
UserManager();
161
~UserManager();
162
void loadDefaults();
163
bool insertNewUser(const char *userName);
164
bool removeUser(const char *userName);
165
int countUsers();
166
User& operator[](int);
167
User& operator[](const char* userName);
168
169
User* acceptEntry(const char *name,const char *encrPass);
170
void removeDatabaseRights(const char *databName);
171
// for loading only
172
User& loadUser(AuthUserRec&);
173
long getLastUserID();
174
void setLastUserID(long);
175
bool reset();
176
bool acceptChangeName(const char *oldName,const char *newName);
177
private:
178
bool testUniqueness(const char* userName);
179
list<User> userList;
180
User protElem;
181
182
long lastUserID;
183
};
184
185
extern UserManager userManager;
186
190
class Authorization
191
{
192
public:
193
Authorization();
194
bool acceptEntry(const char*message);
195
const char *getUserName();
196
bool hasFullAdmin();
197
//bool hasConfigAdmin();
198
const char* getSyncroString();
199
const char* getCapability(const char *serverName,const char *databaseName, bool readonly);
200
void startConfigFile();
201
void endConfigFile();
202
int readAuthFile();
203
bool saveOrigAuthFile();
204
bool saveAltAuthFile();
205
const char* getAltAuthFileName();
206
207
void setGlobalInitAdminRights(int rights);
208
void setGlobalInitDatabRights(int rights);
209
int getGlobalInitAdminRights();
210
int getGlobalInitDatabRights();
211
const char * convertGlobalInitAdminRights();
212
const char * convertGlobalInitDatabRights();
213
const char * convertAdminRights(int);
214
const char * convertDatabRights(int);
215
int convertAdminRights(const char *);
216
int convertDatabRights(const char *);
217
218
bool hasAdminRights(int);
219
bool isInConfigFile();
220
private:
221
int verifyAuthFile(std::ifstream&);
222
const char* getFormatedTime(long int);
223
224
bool saveAuthFile();
225
226
void initcrypt(int);
227
void crypt(void*,int);
228
void decrypt(void*,int);
229
230
231
User *curUser;
232
bool inConfigFile;
233
char authFileName[ FILENAME_MAX ];
234
char altAuthFileName[ FILENAME_MAX ];
235
236
int globalInitAdminRight;
237
int globalInitDatabRight;
238
};
239
240
extern Authorization authorization;
241
245
class RandomGenerator
246
{
247
public:
248
RandomGenerator();
249
250
bool setFileVersion(long); // false, if not supported encr. method
251
252
void init(unsigned int);
253
unsigned char operator()();
254
bool insideTest();
255
private:
256
static unsigned char randomTable[1000];
257
unsigned int seed;
258
int fileVersion;
259
};
260
extern RandomGenerator randomGenerator;
261
262
// return codes:
263
#define RC_OK 0
264
#define ERRAUTHFNOTF -1
265
#define ERRAUTHFCORR -2
266
#define ERRAUTHFWRHOST -3
267
#define ERRAUTHFVERS -4
268
269
#endif
Generated on Mon Jun 9 2014 03:00:30 for rasdaman complete source by
1.8.6