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 | * $Id: userdb.h 533 1999-09-07 04:57:01Z sjboddie $
|
---|
25 | *
|
---|
26 | *********************************************************************/
|
---|
27 |
|
---|
28 |
|
---|
29 | #ifndef USERDB_H
|
---|
30 | #define USERDB_H
|
---|
31 |
|
---|
32 | #include "infodbclass.h"
|
---|
33 |
|
---|
34 |
|
---|
35 | // the password line in the userinfo_t must be encrypted using
|
---|
36 | // this function
|
---|
37 | text_t crypt_text (const text_t &text);
|
---|
38 |
|
---|
39 | // username_ok tests to make sure a username is ok. a username
|
---|
40 | // must be at least 2 characters long, but no longer than 30
|
---|
41 | // characters long. it can contain the characters a-z A-Z 0-9
|
---|
42 | // . and _
|
---|
43 | bool username_ok (const text_t &username);
|
---|
44 |
|
---|
45 | // password_ok tests to make sure a password is ok. a password
|
---|
46 | // must be at least 3 characters long but no longer than 8 characters
|
---|
47 | // long. it can contain any character in the range 0x20-0x7e
|
---|
48 | bool password_ok (const text_t &password);
|
---|
49 |
|
---|
50 |
|
---|
51 | // information about a single user
|
---|
52 | struct userinfo_t {
|
---|
53 | void clear ();
|
---|
54 | userinfo_t () {clear();}
|
---|
55 | userinfo_t &operator=(const userinfo_t &x);
|
---|
56 |
|
---|
57 | text_t username;
|
---|
58 | text_t password;
|
---|
59 | bool enabled;
|
---|
60 | text_t groups; // comma separated list
|
---|
61 | text_t comment;
|
---|
62 | };
|
---|
63 |
|
---|
64 |
|
---|
65 | // these functions deal with user and key databases that are already open
|
---|
66 | // they should have been opened with gdbmclass::opendatabase
|
---|
67 | // as soon as the databases are finished with they should be closed with
|
---|
68 | // gdbmclass::closedatabase so that another process can access the database
|
---|
69 | //
|
---|
70 | // some of the functions need the databases opened with write access, an
|
---|
71 | // appropriate call would be something like:
|
---|
72 | //
|
---|
73 | // success = keydb.opendatabase (keyfile, GDBM_WRCREAT, 1000);
|
---|
74 | //
|
---|
75 | // note: passwords and keys are encrypted, so you can't just compare passwords
|
---|
76 | // in a userinfo_t with a password given by the user. use check_passwd
|
---|
77 |
|
---|
78 |
|
---|
79 | // functions dealing with user databases
|
---|
80 |
|
---|
81 | // returns true on success (in which case userinfo will contain
|
---|
82 | // the information for this user)
|
---|
83 | bool get_user_info (gdbmclass &userdb, const text_t &username,
|
---|
84 | userinfo_t &userinfo);
|
---|
85 | bool get_user_info (const text_t &userdbfile, const text_t &username,
|
---|
86 | userinfo_t &userinfo);
|
---|
87 |
|
---|
88 | // returns true on success
|
---|
89 | bool set_user_info (gdbmclass &userdb, const text_t &username,
|
---|
90 | const userinfo_t &userinfo);
|
---|
91 | bool set_user_info (const text_t &userdbfile, const text_t &username,
|
---|
92 | const userinfo_t &userinfo);
|
---|
93 |
|
---|
94 | // removes a user from the user database -- forever
|
---|
95 | void delete_user (gdbmclass &userdb, const text_t &username);
|
---|
96 | void delete_user (const text_t &userdbfile, const text_t &username);
|
---|
97 |
|
---|
98 | // gets a list of all the users in the database. returns true
|
---|
99 | // on success
|
---|
100 | void get_user_list (gdbmclass &userdb, text_tarray &userlist);
|
---|
101 |
|
---|
102 | // returns true if the user's password is correct.
|
---|
103 | bool check_passwd (const userinfo_t &thisuser, const text_t &password);
|
---|
104 |
|
---|
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
|
---|
111 | text_t generate_key (gdbmclass &keydb, const text_t &username);
|
---|
112 | text_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
|
---|
117 | bool check_key (gdbmclass &keydb, const userinfo_t &thisuser,
|
---|
118 | const text_t &key, const text_t &group, int keydecay);
|
---|
119 | bool 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
|
---|
124 | void remove_old_keys (const text_t &keydbfile, int keydecay);
|
---|
125 |
|
---|
126 |
|
---|
127 | #endif
|
---|