xorp

userdb.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2001-2011 XORP, Inc and Others
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, Version 2, June
00007 // 1991 as published by the Free Software Foundation. Redistribution
00008 // and/or modification of this program under the terms of any other
00009 // version of the GNU General Public License is not permitted.
00010 // 
00011 // This program is distributed in the hope that it will be useful, but
00012 // WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00014 // see the GNU General Public License, Version 2, a copy of which can be
00015 // found in the XORP LICENSE.gpl file.
00016 // 
00017 // XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00018 // http://xorp.net
00019 
00020 // $XORP: xorp/rtrmgr/userdb.hh,v 1.16 2008/10/02 21:58:26 bms Exp $
00021 
00022 #ifndef __RTRMGR_USERDB_HH__
00023 #define __RTRMGR_USERDB_HH__
00024 
00025 
00026 
00027 
00028 
00029 
00030 class User {
00031 public:
00032     User(uid_t user_id, const string& username);
00033 
00034     const string& username() const { return _username; }
00035     uid_t user_id() const { return _user_id; }
00036     bool has_acl_capability(const string& capname, string& err_msg) const;
00037     void add_acl_capability(const string& capname);
00038 
00039 private:
00040     uid_t   _user_id;
00041     string  _username;
00042     set<string> _capabilities;
00043 };
00044 
00045 //
00046 // The same user may be logged in multiple times, so logged in users
00047 // get a UserInstance.
00048 //
00049 class UserInstance : public User {
00050 public:
00051     UserInstance(uid_t user_id, const string& username);
00052 
00053     const string& clientname() const { return _clientname; }
00054     void set_clientname(const string& clientname) { _clientname = clientname; }
00055 
00056     uint32_t clientid() const { return _clientid; }
00057     void set_clientid(uint32_t clientid) { _clientid = clientid; }
00058 
00059     const string& authtoken() const { return _authtoken; }
00060     void set_authtoken(const string& authtoken) { _authtoken = authtoken; }
00061 
00062     bool is_authenticated() const { return _authenticated; }
00063     void set_authenticated(bool authenticated) {
00064     _authenticated = authenticated;
00065     }
00066 
00067     bool is_in_config_mode() const { return _config_mode; }
00068     void set_config_mode(bool is_in_config_mode) {
00069     _config_mode = is_in_config_mode;
00070     }
00071 
00072     bool is_a_zombie() const { return _is_a_zombie; }
00073     void set_zombie(bool state) { _is_a_zombie = state; }
00074 
00075 private:
00076     string _clientname;
00077     uint32_t    _clientid;  /* client ID is a unique number for every
00078                    connected client at any moment in time,
00079                    but not guaranteed to be unique over
00080                    time */
00081     string _authtoken;
00082     bool _authenticated;
00083     bool _config_mode;
00084     bool _is_a_zombie;  // A user instance is a zombie if we suspect
00085             // the client process no longer exists
00086 };
00087 
00088 class UserDB {
00089 public:
00090     UserDB(bool verbose);
00091     ~UserDB();
00092 
00093     User* add_user(uid_t user_id, const string& username, gid_t gid);
00094     void load_password_file();
00095     const User* find_user_by_user_id(uid_t user_id);
00096     void remove_user(uid_t user_id);
00097     bool has_capability(uid_t user_id, const string& capability, string& err_msg);
00098 
00099 private:
00100     map<uid_t, User*> _users;
00101     bool _verbose;  // Set to true if output is verbose
00102 };
00103 
00104 #endif // __RTRMGR_USERDB_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations