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

Last change on this file since 379 was 373, checked in by rjmcnab, 25 years ago

Initial revision.

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