Software and Services, Portable Libraries  2019.Mar.01
A library for managing digital certificates
SqlRole.hpp
1 
5 //
6 // (C) Copyright 2001-2016 Software and Services LLC, All Rights Reserved.
7 //
8 // NOTICE:
9 //
10 // THIS SOURCE CODE BELONGS TO SOFTWARE AND SERVICES LIMITED LIABILITY
11 // CORPORATION, AN IDAHO CORPORATION. THIS CODE IS CONSIDERED A
12 // TRADE SECRET AND IS NOT TO BE DIVULGED OR USED BY PARTIES WHO HAVE
13 // NOT RECEIVED WRITTEN AUTHORIZATION FROM THE OWNER.
14 //
15 // THIS SOURCE CODE IS UNPUBLISHED WORK FULLY PROTECTED BY THE UNITED
16 // STATES COPYRIGHT LAWS AND IS CONSIDERED A TRADE SECRET BELONGING
17 // TO THE COPYRIGHT HOLDER.
18 //
19 // THIS SOFTWARE AND MANUAL ARE BOTH PROTECTED BY UNITED STATES
20 // COPYRIGHT LAW (TITLE 17 UNITED STATES CODE). UNAUTHORIZED REPRODUCTION
21 // AND/OR SALE MAY RESULT IN IMPRISONMENT OF UP TO ONE YEAR AND FINES
22 // OF UP TO $100,000 (17 USC 506). COPYRIGHT INFRINGERS MAY ALSO
23 // BE SUBJECT TO CIVIL LIABILITY.
24 //
25 // ALL OF THIS CODE IS ORIGINAL WORK BY THE COPYRIGHT HOLDER.
26 //
27 #ifndef _DOUGLAS_MARK_ROYER_SQL_LIBRARY_SQLROLE_HPP
28 #define _DOUGLAS_MARK_ROYER_SQL_LIBRARY_SQLROLE_HPP
29 
30 #ifdef BUILDING_LIBRARY_SQL
31 #include "SQL.hpp"
32 #include "Types.hpp"
33 #else
34 #include <SaS/Sql/SQL.hpp>
35 #include <SaS/Sql/Types.hpp>
36 #endif
37 
38 #include <SaS/Common/StringCompareOperator.hpp>
39 #include <pthread.h>
40 #include <map>
41 
43 
44 namespace SoftwareAndServices
45 {
46  namespace Library
47  {
48  namespace Database
49  {
76  class EXPORT_SASSQL SqlRole
77  : public instance<SqlRole>
78  {
79 
80  public:
81 
105  SqlRole(SQL & Db);
106 
110  virtual ~SqlRole();
111 
118  virtual bool CreateRole() = 0;
119 
125  virtual bool DropRole() = 0;
126 
135  static SqlRole * Find(const char * ToFind);
136 
140  SqlSchema * Schema() const;
141 
146  const char * Name() const;
147 
172  virtual bool Name(const char * SName) = 0;
173 
178  const char * Description() const;
179 
190  virtual bool Description(const char * SDesc) = 0;
191 
198  std::vector<SqlRole*> * InRoles() const;
199 
207  virtual bool AddInRole(SqlRole & ToAdd) = 0;
208 
216  bool AddInRole(const char * ToAdd);
217 
225  bool IsMemberOfRole(SqlRole & ToTest) ;
226 
234  bool IsMemberOfRole(const char * ToTest);
235 
251  virtual bool RemoveUsFromRole(SqlRole & RemoveFrom,
252  bool Cascade = false) = 0;
253 
269  bool RemoveUsFromRole(const char * RemoveFrom,
270  bool Cascade = false);
271 
272 
279  std::vector<SqlRole*> * RolesInThisRole() const;
280 
288  virtual bool AddThemToUs(SqlRole & ToAdd);
289 
297  virtual bool AddThemToUs(const char * ToAdd);
298 
306  bool AreTheyOurMember(SqlRole & ToTest);
307 
315  bool AreTheyOurMember(const char * ToTest);
316 
324  virtual bool RemoveThem(SqlRole & RemoveFrom) = 0;
325 
333  bool RemoveThem(const char * RemoveFrom);
334 
342  std::vector<SqlRole*> * Admins() const;
343 
351  virtual bool AddAdministrator(SqlRole & ToAdd) = 0;
352 
360  bool AddAdministrator(const char * ToAdd);
361 
369  bool AreTheyOurAdministrator(SqlRole & ToTest);
370 
378  bool AreTheyOurAdministrator(const char * ToTest);
379 
387  virtual bool RemoveAdministrator(SqlRole & RemoveFrom) = 0;
388 
396  bool RemoveAdministrator(const char * RemoveFrom);
397 
403  bool IsSuperUser() const;
404 
416  virtual bool IsSuperUser(bool IsSu) = 0;
417 
424  bool InheritPrivileges() const;
425 
439  virtual bool InheritPrivileges(bool IsSu) = 0;
440 
441 
448  bool CanCreateRole() const;
449 
461  virtual bool CanCreateRole(bool CanCreate) = 0;
462 
469  bool CanCreateDb() const;
470 
482  virtual bool CanCreateDb(bool CanCreate) = 0;
483 
494  bool CanLogin() const;
495 
511  virtual bool CanLogin(bool AllowLogin) = 0;
512 
519  int32_t ConnectionLimit() const;
520 
531  virtual bool ConnectionLimit(int32_t Limit) = 0;
532 
541  bool CanReplicate() const;
542 
553  virtual bool CanReplicate(bool CanBackup) = 0;
554 
563  bool CanBypassRls() const;
564 
574  virtual bool CanBypassRls(bool CanBypass) = 0;
575 
585  time_t ValidUntil() const;
586 
600  virtual bool ValidUntil(time_t ExpireAt) = 0;
601 
611  static uint64_t
612  GetAll(std::map<const char*, SqlRole*, CStringCompareOperator> & Results);
613 
614  protected:
615 
619  const char * _Name;
620 
624  const char * _Description;
625 
629  std::vector<SqlRole*> * _InRole;
630 
634  std::vector<SqlRole*> * _InOurRole;
635 
639  std::vector<SqlRole*> * _Admin;
640 
645 
650 
655 
660 
664  bool _CanLogin;
665 
670 
675 
680 
684  time_t _ValidUntil;
685 
690 
694  static std::map<const char*,
695  SqlRole*,
697 
698  static pthread_mutex_t _Once;
699 
710 
711  };
712 
718  : public instance<SqlUserMapping>
719  {
720 
721  public:
722 
726  SqlUserMapping();
727 
731  virtual ~SqlUserMapping();
732 
746  virtual bool Add(const char * Server,
747  const char * LocalUser,
748  bool IsPublic,
749  std::map<const char*,const char*> & Opts) = 0;
750 
759  static const std::map<const char*,
762  GetAll();
763 
769  virtual bool Drop() = 0;
770 
777  virtual const char * Server();
778 
785  virtual const char * LocalUser() const;
786 
792  virtual bool Public() const;
793 
805  virtual bool Option(const char * OptName,
806  String & Results);
807 
808  protected:
809 
813  const char * _Server;
814 
818  const char * _LocalUser;
819 
823  bool _IsPublic;
824 
829  std::map<const char*,
830  const char*,
832 
836  static std::map<const char*,
837  SqlUserMapping*,
839 
840  static pthread_mutex_t _Once;
841  };
842 
843  }
844  }
845 }
846 
847 #endif //_DOUGLAS_MARK_ROYER_SQL_LIBRARY_SQLROLE_HPP
static std::map< const char *, SqlRole *, CStringCompareOperator > * _All
All Roles.
Definition: SqlRole.hpp:696
bool _CanReplicate
When true, ROLE can replicate.
Definition: SqlRole.hpp:669
bool _InDatabase
True when this object is really an existing SQL ROLE.
Definition: SqlRole.hpp:709
static std::map< const char *, SqlUserMapping *, CStringCompareOperator > * _All
All known mappings.
Definition: SqlRole.hpp:838
bool _InheritPrivileges
When true, ROLE can inherit.
Definition: SqlRole.hpp:659
SQL & _Sql
The controling SQL object.
Definition: SqlRole.hpp:689
bool _IsSuperUser
When true, ROLE is superuser.
Definition: SqlRole.hpp:644
The SQL class is a pure virtual interface class for SQL access.
Definition: SQL.hpp:128
int32_t _ConnectionLimit
Connection limit (number of connections).
Definition: SqlRole.hpp:679
std::vector< SqlRole * > * _Admin
ADMIN.
Definition: SqlRole.hpp:639
bool _CanLogin
When true, ROLE can login.
Definition: SqlRole.hpp:664
Map a user from a foreign server.
Definition: SqlRole.hpp:717
bool _CanBypassRls
When true, ROLE can by pass RLS.
Definition: SqlRole.hpp:674
bool _CanCreateRole
When true, ROLE can create roles.
Definition: SqlRole.hpp:654
The pure virtual methods are implemented in derived objects, where vendor specific code must be writt...
Definition: SqlRole.hpp:76
std::map< const char *, const char *, CStringCompareOperator > * _Options
The list of options for the User Mapping.
Definition: SqlRole.hpp:831
bool _CanCreateDb
When true, ROLE can create databases.
Definition: SqlRole.hpp:649
time_t _ValidUntil
Expire time for role.
Definition: SqlRole.hpp:684
const char * _Server
When non-NULL, the name of the foreign server.
Definition: SqlRole.hpp:813
Instance counting and tracking.
Definition: instance.hpp:90
This is a class that allows:
Definition: String.hpp:114
Copyright Douglas Mark Royer DouglasRoyer@gmail.com.
Definition: Base.hpp:98
std::vector< SqlRole * > * _InRole
IN ROLE.
Definition: SqlRole.hpp:629
const char * _LocalUser
When non-NULL, the name of the local user.
Definition: SqlRole.hpp:818
bool _IsPublic
When true, the &#39;PUBLIC&#39; entry.
Definition: SqlRole.hpp:823
std::vector< SqlRole * > * _InOurRole
ROLE.
Definition: SqlRole.hpp:634