FXACL.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                           An Access Control List                              *
00004 *                                                                               *
00005 *********************************************************************************
00006 *        Copyright (C) 2003 by Niall Douglas.   All Rights Reserved.            *
00007 *       NOTE THAT I DO NOT PERMIT ANY OF MY CODE TO BE PROMOTED TO THE GPL      *
00008 *********************************************************************************
00009 * This code is free software; you can redistribute it and/or modify it under    *
00010 * the terms of the GNU Library General Public License v2.1 as published by the  *
00011 * Free Software Foundation EXCEPT that clause 3 does not apply ie; you may not  *
00012 * "upgrade" this code to the GPL without my prior written permission.           *
00013 * Please consult the file "License_Addendum2.txt" accompanying this file.       *
00014 *                                                                               *
00015 * This code is distributed in the hope that it will be useful,                  *
00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                          *
00018 *********************************************************************************
00019 * $Id:                                                                          *
00020 ********************************************************************************/
00021 
00022 #ifndef FXACL_H
00023 #define FXACL_H
00024 
00025 #include "FXString.h"
00026 
00027 namespace FX {
00028 
00033 class FXACLIterator;
00034 struct FXACLPrivate;
00035 
00064 struct FXACLEntityPrivate;
00065 class FXAPIR FXACLEntity
00066 {
00067     friend class FXACL;
00068     friend struct FXACLPrivate;
00069     FXACLEntityPrivate *p;
00070 public:
00071     FXACLEntity();
00072     FXACLEntity(const FXACLEntity &o);
00073     FXACLEntity &operator=(const FXACLEntity &o);
00074     ~FXACLEntity();
00075     bool operator==(const FXACLEntity &o) const;
00076     bool operator!=(const FXACLEntity &o) const { return !(*this==o); }
00078     bool isGroup() const;
00080     FXACLEntity group() const;
00086     FXString asString(bool withId=true, bool withMachine=true) const;
00095     bool isLoginPassword(const FXchar *password) const;
00101     FXString homeDirectory(bool filesdir=false) const;
00104     static const FXACLEntity &currentUser();
00106     static const FXACLEntity &everything();
00108     static const FXACLEntity &root();
00110     static const FXACLEntity &owner();
00113     static FXACLEntity lookupUser(const FXString &username, const FXString &machine=FXString::nullStr());
00115     //static QValueList<FXACLEntity> localEntities();
00116 };
00117 
00238 class FXAPIR FXACL
00239 {
00240     friend class FXACLIterator;
00241     FXACLPrivate *p;
00242 public:
00244     enum EntityType
00245     {
00246         Unknown=0,
00247         File,           
00248         Directory,      
00249         Pipe,           
00250         MemMap          
00251     };
00253     typedef FXuint Perms;
00255     struct FXAPI Permissions
00256     {
00257         Perms read:1;               
00258         Perms write:1;              
00259         Perms execute:1;            
00260         Perms append:1;             
00261         Perms copyonwrite:1;        
00262         Perms reserved2:3;
00263 
00264         Perms list:1;               
00265         Perms createfiles:1;        
00266         Perms createdirs:1;         
00267         Perms traverse:1;           
00268         Perms deletefiles:1;        
00269         Perms deletedirs:1;         
00270         Perms reserved1:2;
00271 
00272         Perms readattrs:1;          
00273         Perms writeattrs:1;         
00274         Perms readperms:1;          
00275         Perms writeperms:1;         
00276         Perms takeownership:1;      
00277         Perms reserved3:3;
00278 
00279         Perms amTn:1;               
00280         Perms custom:7;             
00281 
00282         Permissions(Perms v=0) { *((Perms *) this)=v; }
00283         //bool operator==(const Permissions &o) const { return *((Perms *) this)==*((Perms *) &o); }
00284         //bool operator!=(const Permissions &o) const { return *((Perms *) this)!=*((Perms *) &o); }
00285         operator Perms() const { return *((Perms *) this); }
00286         Perms asUInt() const { return *((Perms *) this); }
00287         Permissions &operator=(Perms v) { *((Perms *) this)=v; return *this; }
00288         Permissions &setRead   (bool v=true) { read=v;    return *this; }
00289         Permissions &setWrite  (bool v=true) { write=v;   return *this; }
00290         Permissions &setExecute(bool v=true) { execute=v; return *this; }
00291         Permissions &setAppend (bool v=true) { append=v;  return *this; }
00292         Permissions &setCopyOnWrite(bool v=true) { copyonwrite=v;  return *this; }
00293         Permissions &setList       (bool v=true) { list=v;        return *this; }
00294         Permissions &setCreateFiles(bool v=true) { createfiles=v; return *this; }
00295         Permissions &setCreateDirs (bool v=true) { createdirs=v;  return *this; }
00296         Permissions &setTraverse   (bool v=true) { traverse=v;    return *this; }
00297         Permissions &setDeleteFiles(bool v=true) { deletefiles=v; return *this; }
00298         Permissions &setDeleteDirs (bool v=true) { deletedirs=v;  return *this; }
00299         Permissions &setReadAttrs (bool v=true) { readattrs=v;   return *this; }
00300         Permissions &setWriteAttrs(bool v=true) { writeattrs=v;  return *this; }
00301         Permissions &setReadPerms (bool v=true) { readperms=v;  return *this; }
00302         Permissions &setWritePerms(bool v=true) { writeperms=v; return *this; }
00303         Permissions &setTakeOwnership(bool v=true) { takeownership=v;  return *this; }
00305         Permissions &setGenRead(bool v=true)
00306         {
00307             read=list=readattrs=readperms=v;
00308             return *this;
00309         }
00311         Permissions &setGenWrite(bool v=true)
00312         {
00313             write=append=createfiles=createdirs=deletefiles=deletedirs=writeattrs=writeperms=v;
00314             return *this;
00315         }
00317         Permissions &setGenExecute(bool v=true)
00318         {
00319             execute=traverse=v;
00320             return *this;
00321         }
00323         Permissions &setAll(bool plusExecute=false)
00324         {
00325             setGenRead().setGenWrite(); if(plusExecute) setGenExecute();
00326             setCopyOnWrite().setTakeOwnership();
00327             return *this;
00328         }
00331         FXString asString(EntityType type) const;
00332     };
00334     struct Entry
00335     {
00336         bool inherited;             
00337         bool inheritable;           
00338         FXACLEntity entity;         
00339         Permissions deny, grant;    
00340         Entry(const FXACLEntity &_entity, Perms _deny, Perms _grant, bool _inheritable=false) : inherited(false), inheritable(_inheritable), entity(_entity), deny(_deny), grant(_grant) { }
00341         bool operator==(const Entry &o) const { return entity==o.entity && deny==o.deny && grant==o.grant; } 
00342     };
00343 private:
00344     FXDLLLOCAL void init(void *, EntityType);
00345 public:
00347     FXACL(EntityType type=Unknown, const FXACLEntity &owner=FXACLEntity::currentUser());
00351     FXACL(const FXString &path, EntityType type);
00353     FXACL(void *h, EntityType type);
00355     FXACL(int fd, EntityType type);
00356     FXACL(const FXACL &o);
00357     FXACL &operator=(const FXACL &o);
00358     ~FXACL();
00359     bool operator==(const FXACL &o) const;
00360     bool operator!=(const FXACL &o) const;
00362     EntityType type() const;
00364     void setType(EntityType type);
00366     bool hasInherited() const;
00368     void setHasInherited(bool newval);
00370     FXuint count() const;
00372     void insert(const FXACLIterator &it, const Entry &entry);
00374     void remove(const FXACLIterator &it);
00376     FXACLIterator begin() const;
00378     FXACLIterator end() const;
00380     void prepend(const Entry &entry);
00382     void append(const Entry &entry);
00384     const FXACLEntity &owner() const;
00386     void setOwner(const FXACLEntity &entity);
00388     bool check(Perms what) const;
00390     void checkE(Perms what) const;
00392     FXString report() const;
00394     FXString asString() const { return report(); }
00395 
00397     void writeTo(const FXString &path) const;
00399     void writeTo(void *h) const;
00401     void writeTo(int fd) const;
00402 
00408     static FXACL default_(EntityType type, bool readOnly, int flags=0);
00410     struct ACLSupport
00411     {
00412         FXuint perOwnerGroup    : 1; 
00413         FXuint perEntity        : 1; 
00414         FXuint hasInheritance   : 1; 
00415         ACLSupport() { *((FXuint *) this)=0; }
00416         FXuint asUInt() const { return *((FXuint *) this); }
00417     };
00419     static ACLSupport hostOSACLSupport();
00422     static void resetPath(const FXString &path, const FXACL &dirs, const FXACL &files);
00423 public:
00424     FXDLLLOCAL void *int_toWin32SecurityDescriptor() const;
00425 };
00426 
00427 #define FXACL_READ (1<<0)
00428 #define FXACL_WRITE (1<<1)
00429 #define FXACL_EXECUTE (1<<2)
00430 #define FXACL_APPEND (1<<3)
00431 #define FXACL_COPYONWRITE (1<<4)
00432 #define FXACL_LIST (1<<8)
00433 #define FXACL_CREATEFILES (1<<9)
00434 #define FXACL_CREATEDIRS (1<<10)
00435 #define FXACL_TRAVERSE (1<<11)
00436 #define FXACL_DELETEFILES (1<<12)
00437 #define FXACL_DELETEDIRS (1<<13)
00438 #define FXACL_READATTRS (1<<16)
00439 #define FXACL_WRITEATTRS (1<<17)
00440 #define FXACL_READPERMS (1<<18)
00441 #define FXACL_WRITEPERMS (1<<19)
00442 #define FXACL_TAKEOWNERSHIP (1<<20)
00444 #define FXACL_GENREAD ((0x1<<0)|(0x1<<8)|(0x5<<16))
00446 #define FXACL_GENWRITE ((0xa<<0)|(0x36<<8)|(0xa<<16))
00448 #define FXACL_GENEXECUTE ((1<<2)|(1<<11))
00449 
00450 
00457 struct FXACLIteratorPrivate;
00458 class FXACL;
00459 class FXAPIR FXACLIterator
00460 {
00461     friend class FXACL;
00462     FXACLIteratorPrivate *p;
00463 public:
00464     FXACLIterator(const FXACL &acl, bool end=false);
00465     FXACLIterator(const FXACLIterator &o);
00466     ~FXACLIterator();
00467     FXACLIterator &operator=(const FXACLIterator &o);
00468     bool operator==(const FXACLIterator &o) const;
00469     bool operator!=(const FXACLIterator &o) const;
00470     bool atEnd() const;
00471     const FXACL::Entry &operator *() const;
00472     const FXACL::Entry *operator->() const;
00473     FXACLIterator &operator++();
00474     FXACLIterator &operator+=(FXuint i);
00475     FXACLIterator &operator--();
00476     FXACLIterator &operator-=(FXuint i);
00477 };
00478 
00479 } // namespace
00480 
00481 #endif

(C) 2002-2009 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Nov 20 18:31:19 2009 for TnFOX by doxygen v1.4.7