source: trunk/gsdl/src/recpt/userdb.h@ 13017

Last change on this file since 13017 was 2750, checked in by kjm18, 23 years ago

can now have spaces after the commas in the groups field of add user form -
these are removed before the entry is written to the db

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 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#include "infodbclass.h"
31
32
33// the password line in the userinfo_t must be encrypted using
34// this function
35text_t crypt_text (const text_t &text);
36
37// username_ok tests to make sure a username is ok. a username
38// must be at least 2 characters long, but no longer than 30
39// characters long. it can contain the characters a-z A-Z 0-9
40// . and _
41bool username_ok (const text_t &username);
42
43// password_ok tests to make sure a password is ok. a password
44// must be at least 3 characters long but no longer than 8 characters
45// long. it can contain any character in the range 0x20-0x7e
46bool password_ok (const text_t &password);
47
48
49// information about a single user
50struct userinfo_t {
51 void clear ();
52 userinfo_t () {clear();}
53 userinfo_t &operator=(const userinfo_t &x);
54
55 text_t username;
56 text_t password;
57 bool enabled;
58 text_t groups; // comma separated list
59 text_t comment;
60};
61
62
63// these functions deal with user and key databases that are already open
64// they should have been opened with gdbmclass::opendatabase
65// as soon as the databases are finished with they should be closed with
66// gdbmclass::closedatabase so that another process can access the database
67//
68// some of the functions need the databases opened with write access, an
69// appropriate call would be something like:
70//
71// success = keydb.opendatabase (keyfile, GDBM_WRCREAT, 1000);
72//
73// note: passwords and keys are encrypted, so you can't just compare passwords
74// in a userinfo_t with a password given by the user. use check_passwd
75
76
77// functions dealing with user databases
78
79// returns true on success (in which case userinfo will contain
80// the information for this user)
81bool get_user_info (gdbmclass &userdb, const text_t &username,
82 userinfo_t &userinfo);
83bool get_user_info (const text_t &userdbfile, const text_t &username,
84 userinfo_t &userinfo);
85
86// returns true on success
87bool set_user_info (gdbmclass &userdb, const text_t &username,
88 const userinfo_t &userinfo);
89bool set_user_info (const text_t &userdbfile, const text_t &username,
90 const userinfo_t &userinfo);
91
92// removes a user from the user database -- forever
93void delete_user (gdbmclass &userdb, const text_t &username);
94void delete_user (const text_t &userdbfile, const text_t &username);
95
96// gets a list of all the users in the database. returns true
97// on success
98void get_user_list (gdbmclass &userdb, text_tarray &userlist);
99
100// returns true if the user's password is correct.
101bool check_passwd (const userinfo_t &thisuser, const text_t &password);
102
103// removes spaces from user groups
104text_t format_user_groups(const text_t user_groups);
105
106// functions dealing with databases of temporary keys
107
108// generates a random key for the user, stores it in the database and
109// returns it so that it can be used in page generation
110// returns "" on failure
111text_t generate_key (gdbmclass &keydb, const text_t &username);
112text_t generate_key (const text_t &keydbfile, const text_t &username);
113
114// checks to see if there is a key for this particular user in the
115// database that hasn't decayed. a short decay is used when group
116// is set to administrator
117bool check_key (gdbmclass &keydb, const userinfo_t &thisuser,
118 const text_t &key, const text_t &group, int keydecay);
119bool check_key (const text_t &keydbfile, const userinfo_t &thisuser,
120 const text_t &key, const text_t &group, int keydecay);
121
122// remove_old_keys will remove all keys created more than keydecay ago.
123// use sparingly, it can be quite an expensive function
124void remove_old_keys (const text_t &keydbfile, int keydecay);
125
126
127#endif
Note: See TracBrowser for help on using the repository browser.