00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _AccessControl
00024 #define _AccessControl 1
00025
00026 #include "Basics.H"
00027 #include "VestaAttribs.H"
00028 #include "VestaConfig.H"
00029 #include "CharsSeq.H"
00030 #include <PwGrp.H>
00031 #include <chars_seq.H>
00032 #include <sys/types.h>
00033 #include <rpc/types.h>
00034 #include <rpc/xdr.h>
00035 #include <rpc/auth.h>
00036 #include <rpc/auth_unix.h>
00037
00038
00039
00040 extern "C"
00041 {
00042 void AccessControl_commonInit_inner() throw();
00043 void AccessControl_selfInit_inner() throw();
00044 }
00045
00046
00047
00048
00049 class AccessControl {
00050 public:
00051
00052
00053
00054 class IdentityRep {
00055 protected:
00056 CharsSeq *users_cache, *groups_cache;
00057 virtual void fill_caches() throw() = 0;
00058
00059 IdentityRep() : users_cache(0), groups_cache(0) { }
00060 public:
00061
00062
00063
00064
00065
00066 enum Flavor { unix_flavor, global, gssapi,
00067 nflavors=3, unspecified=255 };
00068 Flavor flavor;
00069
00070
00071 sockaddr_in origin;
00072
00073
00074
00075 virtual const char* user(int n = 0) throw ();
00076
00077
00078
00079 virtual const char* group(int n = 0) throw ();
00080
00081
00082 bool readOnly;
00083
00084
00085 virtual uid_t toUnixUser() throw () = 0;
00086 virtual gid_t toUnixGroup() throw () = 0;
00087
00088
00089
00090
00091
00092
00093 bool userMatch(const char* name) throw ();
00094
00095
00096 bool groupMatch(const char* name) throw ();
00097
00098
00099 bool userMatch(const char* aname, VestaAttribs attribs) throw ();
00100
00101
00102 bool groupMatch(const char* aname, VestaAttribs attribs) throw ();
00103
00104 virtual bool operator==(const IdentityRep &other) const throw() = 0;
00105 bool operator !=(const IdentityRep &other) const throw()
00106 {
00107 return !(*this == other);
00108 }
00109
00110 virtual void send(SRPC *srpc) const throw(SRPC::failure) = 0;
00111 virtual ~IdentityRep();
00112 };
00113 typedef IdentityRep* Identity;
00114
00115 class GlobalIdentityRep : public IdentityRep {
00116 protected:
00117 const char* user_;
00118 void fill_caches() throw();
00119 public:
00120
00121
00122
00123 GlobalIdentityRep(const char* u =NULL, const sockaddr_in* o =NULL) throw();
00124 const char* user(int n = 0) throw ();
00125 const char* group(int n = 0) throw ();
00126 uid_t toUnixUser() throw () { return globalToUnixUser(user(0)); };
00127 gid_t toUnixGroup() throw () { return globalToUnixGroup(group(0)); };
00128
00129 bool operator==(const IdentityRep &other) const throw();
00130 void send(SRPC *srpc) const throw(SRPC::failure);
00131 ~GlobalIdentityRep();
00132 };
00133
00134 #if 0
00135
00136 class GssapiIdentityRep : public GlobalIdentityRep {
00137 private:
00138 gss_cred_id_t* creds_;
00139 public:
00140
00141
00142
00143 GssapiIdentityRep(const char* u =NULL, const sockaddr_in* o =NULL)
00144 throw(failure);
00145 GssapiIdentityRep(const gss_name_t u, const sockaddr_in* o =NULL)
00146 throw(failure);
00147 GssapiIdentityRep(const gss_cred_id_t c, const sockaddr_in* o =NULL)
00148 throw(failure);
00149
00150 ~GssapiIdentityRep();
00151
00152 class failure {
00153 public:
00154 Bit32 generic, minor;
00155 Text where;
00156 failure(Bit32 g, Bit32 m, Text w) : generic(g), minor(m), where(w) {};
00157 };
00158 };
00159 #endif
00160
00161 class UnixIdentityRep : public IdentityRep {
00162 protected:
00163 virtual void fill_caches() throw();
00164 private:
00165 authunix_parms* aup_;
00166 bool free_aup_;
00167 public:
00168
00169 UnixIdentityRep(authunix_parms* aup =NULL, const sockaddr_in* o =NULL, bool own_aup=true)
00170 throw ();
00171 const char* user(int n = 0) throw ();
00172 const char* group(int n = 0) throw ();
00173 uid_t toUnixUser() throw () { return aup_->aup_uid; };
00174 gid_t toUnixGroup() throw () { return aup_->aup_gid; };
00175
00176
00177
00178
00179 void validate() throw();
00180
00181 bool operator==(const IdentityRep &other) const throw();
00182 void send(SRPC *srpc) const throw(SRPC::failure);
00183 ~UnixIdentityRep();
00184 };
00185
00186
00187 class IdInfo {
00188 public:
00189 chars_seq names;
00190 chars_seq groups;
00191
00192 uid_t unix_uid;
00193
00194 uid_t unix_gid;
00195
00196
00197 bool is_root;
00198 bool is_admin;
00199 bool is_wizard;
00200 bool is_runtool;
00201
00202
00203 IdInfo() : names(), groups(), unix_uid(0), unix_gid(0),
00204 is_root(false), is_admin(false),
00205 is_wizard(false), is_runtool(false)
00206 { }
00207 };
00208
00209 class ParseError {
00210 public:
00211 ParseError(Text m) : message(m) { };
00212 Text message;
00213
00214
00215 Text fname;
00216
00217
00218 Text fkind;
00219 };
00220
00221
00222
00223
00224
00225 static const char* realm;
00226 static unsigned int realmlen;
00227 static IdentityRep::Flavor defaultFlavor;
00228 static uid_t globalToUnixUser(const char* user) throw ();
00229 static gid_t globalToUnixGroup(const char* group) throw ();
00230 static const char* unixToGlobalUser(uid_t uid) throw ();
00231 static const char* unixToGlobalGroup(gid_t gid) throw ();
00232 static void refreshAccessTables() throw(ParseError);
00233
00234 uid_t toUnixUser() throw ();
00235 gid_t toUnixGroup() throw ();
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 static bool restrictDelete;
00248
00249
00250
00251
00252 static uid_t vforeignUser;
00253 static gid_t vforeignGroup;
00254 static const char* vadminUser;
00255 static const char* vadminGroup;
00256 static const char* rootUser;
00257 static const char* runtoolUser;
00258 static const char* vwizardUser;
00259
00260
00261
00262
00263
00264
00265
00266
00267 enum Class { unrestricted, administrative, ownership, read, write,
00268 search, del, setuid, setgid, agreement };
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279 bool check(Identity who, Class cls, const char* value =NULL) throw ();
00280
00281
00282
00283 static bool admit(Identity who) throw ();
00284
00285
00286
00287
00288
00289
00290 static Identity self()
00291 throw ();
00292
00293
00294
00295
00296 typedef Bit32 ModeBits;
00297 static ModeBits parseModeBits(const char* char_mode) throw ();
00298 static const char* formatModeBits(ModeBits mode) throw ();
00299
00300 ModeBits mode;
00301 VestaAttribs owner;
00302 VestaAttribs group;
00303
00304
00305
00306
00307 public:
00308
00309 static void serverInit()
00310 throw (VestaConfig::failure );
00311
00312
00313 static void commonInit() throw ();
00314 private:
00315
00316 friend void AccessControl_commonInit_inner() throw();
00317
00318 static void selfInit() throw ();
00319 friend void AccessControl_selfInit_inner() throw();
00320
00321 static Identity self_;
00322 };
00323
00324 #endif