source: main/trunk/greenstone2/runtime-src/src/recpt/userdb.h@ 25234

Last change on this file since 25234 was 22067, checked in by ak19, 14 years ago
  1. More changes to makefiles: rm JDBMWrapper.jar and jdbm.jar on clean. 2. DB files (argdb, users, key, history) now not only for gdbm but to work with other db types like jdbm, sqlite and mssql.
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 KB
Line 
1/**********************************************************************
2 *
3 * userdb.h -- functions to handle a user database
4 * Copyright (C) 1999 DigiLib Systems Limited, New Zealand
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 *********************************************************************/
25
26
27#ifndef USERDB_H
28#define USERDB_H
29
30#define ERRNO_SUCCEED 0
31#define ERRNO_CONNECTIONFAILED -1
32#define ERRNO_USERNOTFOUND -2
33#define ERRNO_EXISTINGUSERNAME -3
34#define ERRNO_MISSINGPASSWORD -4
35#define ERRNO_PASSWORDMISMATCH -5
36#define ERRNO_DBACTIONFAILED -6
37
38
39#include "dbclass.h"
40
41// The user information object and it provides basic functions for the information object, such as clear and copy (=) functions;
42class userinfo_t
43{
44 public:
45 text_t username;
46 text_t password;
47 bool enabled;
48 text_t groups; // comma separated list
49 text_t comment;
50
51 userinfo_t ();
52 virtual ~userinfo_t();
53 userinfo_t &operator=(const userinfo_t &x);
54 void clear ();
55};
56
57typedef vector<userinfo_t> userinfo_tarray; // more space efficient than text_tlist
58
59class userdbclass
60{
61 protected:
62 // The internal storage for the userdbfilename and the userdb object
63 dbclass* userdb;
64 bool external_db;
65 bool activated;
66 text_t storeduserdbfilename;
67
68 public:
69 userdbclass (const text_t &gsdlhome);
70 virtual ~userdbclass();
71
72 //======== the static methods========//
73 // the password line in the userinfo_t must be encrypted using
74 // this function
75 static text_t crypt_text (const text_t &text);
76 // username_ok tests to make sure a username is ok. a username
77 // must be at least 2 characters long, but no longer than 30
78 // characters long. it can contain the characters a-z A-Z 0-9
79 // . and _
80 static bool username_ok (const text_t &username);
81 // password_ok tests to make sure a password is ok. a password
82 // must be at least 3 characters long but no longer than 8 characters
83 // long. it can contain any character in the range 0x20-0x7e
84 static bool password_ok (const text_t &password);
85 // removes spaces from user groups
86 static text_t format_user_groups(const text_t user_groups);
87
88 //======== functions dealing with single user in the user databases ========//
89 // returns true on success (in which case userinfo will contain
90 // the information for this user)
91 int get_user_info (const text_t &username, userinfo_t &userinfo);
92
93 // returns true on success
94 int set_user_info (const text_t &username, const userinfo_t &userinfo);
95
96 // returns true if the user's password is correct.
97 int check_passwd (const text_t &username, const text_t &password);
98
99 // adds a user from the user database -- forever
100 int add_user (const userinfo_t &userinfo);
101
102 // edits a user from the user database -- forever
103 int edit_user (const userinfo_t &userinfo);
104
105 // removes a user from the user database -- forever
106 int delete_user (const text_t &username);
107
108 //======== functions dealing with multiple users in the user databases ========//
109 // gets all the users' information in the database. returns true
110 // on success
111 int get_all_users(userinfo_tarray &userinfo_array);
112
113 // gets a list of all the users in the database. returns true
114 // on success
115 int get_user_list (text_tarray &userlist);
116};
117
118class keydbclass
119{
120 protected:
121 // The internal storage for the userdbfilename and the userdb object
122 dbclass* keydb;
123 bool external_db;
124 bool activated;
125 text_t storedkeydbfilename;
126
127 public:
128 keydbclass (const text_t &gsdlhome);
129 virtual ~keydbclass();
130 // functions dealing with databases of temporary keys
131
132 // generates a random key for the user, stores it in the database and
133 // returns it so that it can be used in page generation
134 // returns "" on failure
135 text_t generate_key (const text_t &username);
136
137 // checks to see if there is a key for this particular user in the
138 // database that hasn't decayed. a short decay is used when group
139 // is set to administrator
140 bool check_key (const userinfo_t &thisuser, const text_t &key, const text_t &group, int keydecay);
141
142 // remove_old_keys will remove all keys created more than keydecay ago.
143 // use sparingly, it can be quite an expensive function
144 void remove_old_keys (int keydecay);
145};
146
147#endif
Note: See TracBrowser for help on using the repository browser.