source: main/tags/2.80/gsdl/src/recpt/userdb.h@ 24528

Last change on this file since 24528 was 14269, checked in by qq6, 17 years ago

Jeffrey has fixed operating records of users database on Windows

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 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_GDBMACTIONFILED -6
37
38
39#include "infodbclass.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 gdbmclass userdb;
64 bool external_db;
65 bool activated;
66 text_t storeduserdbfilename;
67
68 public:
69 userdbclass (const text_t &userdbfilename);
70 userdbclass (const gdbmclass &external_userdb);
71 virtual ~userdbclass();
72
73 //======== the static methods========//
74 // the password line in the userinfo_t must be encrypted using
75 // this function
76 static text_t crypt_text (const text_t &text);
77 // username_ok tests to make sure a username is ok. a username
78 // must be at least 2 characters long, but no longer than 30
79 // characters long. it can contain the characters a-z A-Z 0-9
80 // . and _
81 static bool username_ok (const text_t &username);
82 // password_ok tests to make sure a password is ok. a password
83 // must be at least 3 characters long but no longer than 8 characters
84 // long. it can contain any character in the range 0x20-0x7e
85 static bool password_ok (const text_t &password);
86 // removes spaces from user groups
87 static text_t format_user_groups(const text_t user_groups);
88
89 //======== functions dealing with single user in the user databases ========//
90 // returns true on success (in which case userinfo will contain
91 // the information for this user)
92 int get_user_info (const text_t &username, userinfo_t &userinfo);
93
94 // returns true on success
95 int set_user_info (const text_t &username, const userinfo_t &userinfo);
96
97 // returns true if the user's password is correct.
98 int check_passwd (const text_t &username, const text_t &password);
99
100 // adds a user from the user database -- forever
101 int add_user (const userinfo_t &userinfo);
102
103 // edits a user from the user database -- forever
104 int edit_user (const userinfo_t &userinfo);
105
106 // removes a user from the user database -- forever
107 int delete_user (const text_t &username);
108
109 //======== functions dealing with multiple users in the user databases ========//
110 // gets all the users' information in the database. returns true
111 // on success
112 int get_all_users(userinfo_tarray &userinfo_array);
113
114 // gets a list of all the users in the database. returns true
115 // on success
116 int get_user_list (text_tarray &userlist);
117};
118
119class keydbclass
120{
121 protected:
122 // The internal storage for the userdbfilename and the userdb object
123 gdbmclass keydb;
124 bool external_db;
125 bool activated;
126 text_t storedkeydbfilename;
127
128 public:
129 keydbclass (const text_t &keydbfilename);
130 keydbclass (const gdbmclass &external_keydb);
131 virtual ~keydbclass();
132 // functions dealing with databases of temporary keys
133
134 // generates a random key for the user, stores it in the database and
135 // returns it so that it can be used in page generation
136 // returns "" on failure
137 text_t generate_key (const text_t &username);
138
139 // checks to see if there is a key for this particular user in the
140 // database that hasn't decayed. a short decay is used when group
141 // is set to administrator
142 bool check_key (const userinfo_t &thisuser, const text_t &key, const text_t &group, int keydecay);
143
144 // remove_old_keys will remove all keys created more than keydecay ago.
145 // use sparingly, it can be quite an expensive function
146 void remove_old_keys (int keydecay);
147};
148
149#endif
Note: See TracBrowser for help on using the repository browser.