WvStreams
unipermgen.h
1 /* -*- Mode: C++ -*-
2  * Worldvisions Weaver Software:
3  * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4  *
5  */
6 #ifndef __UNIPERMGEN_H
7 #define __UNIPERMGEN_H
8 
9 #include "unifiltergen.h"
10 #include "wvstringtable.h"
11 
26 class UniPermGen : public UniFilterGen
27 {
28 public:
29  UniPermGen(IUniConfGen *_gen);
30  UniPermGen(WvStringParm moniker);
31 
32  enum Level { USER = 0, GROUP, WORLD };
33  static WvString level2str(Level l);
34 
35  enum Type { READ = 0, WRITE, EXEC };
36  static WvString type2str(Type t);
37 
38  struct Credentials
39  {
40  WvString user;
41  mutable WvStringTable groups;
42  // mutable because stupid WvHashTable has no const lookup methods
43 
44  Credentials() : groups(7) { }
45  };
46 
48  void setowner(const UniConfKey &path, WvStringParm owner);
49  WvString getowner(const UniConfKey &path);
50 
52  void setgroup(const UniConfKey &path, WvStringParm group);
53  WvString getgroup(const UniConfKey &path);
54 
59  bool getread(const UniConfKey &path, const Credentials &cred)
60  { return getperm(path, cred, READ); }
61  bool getwrite(const UniConfKey &path, const Credentials &cred)
62  { return getperm(path, cred, WRITE); }
63  bool getexec(const UniConfKey &path, const Credentials &cred)
64  { return getperm(path, cred, EXEC); }
65 
66  bool getperm(const UniConfKey &path, const Credentials &cred, Type type);
67 
68  void setread(const UniConfKey &path, Level level, bool read)
69  { setperm(path, level, READ, read); }
70  void setwrite(const UniConfKey &path, Level level, bool write)
71  { setperm(path, level, WRITE, write); }
72  void setexec(const UniConfKey &path, Level level, bool exec)
73  { setperm(path, level, EXEC, exec); }
74 
75  void setperm(const UniConfKey &path, Level level, Type type, bool val);
76 
81  void chmod(const UniConfKey &path, unsigned int owner, unsigned int group,
82  unsigned int world);
83  void chmod(const UniConfKey &path, unsigned int mode);
84 
85  virtual void flush_buffers() { }
86 
87 private:
88  bool getoneperm(const UniConfKey &path, Level level, Type type);
89 };
90 
91 
92 #endif // __UNIPERMGEN_H
UniPermGen::Credentials
Definition: unipermgen.h:38
UniPermGen::setowner
void setowner(const UniConfKey &path, WvStringParm owner)
get and set the owner for a path
Definition: unipermgen.cc:35
UniPermGen::flush_buffers
virtual void flush_buffers()
Flushes any commitment/notification buffers .
Definition: unipermgen.h:85
UniPermGen::setgroup
void setgroup(const UniConfKey &path, WvStringParm group)
get and set the group for a path
Definition: unipermgen.cc:51
UniPermGen::chmod
void chmod(const UniConfKey &path, unsigned int owner, unsigned int group, unsigned int world)
Set permissions for path using Unix style chmod (with the second form, be sure to use octal)
Definition: unipermgen.cc:119
WvStringTable
Definition: wvstringtable.h:17
WvString
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:329
IUniConfGen
An abstract data container that backs a UniConf tree.
Definition: uniconfgen.h:39
group
Definition: argp-parse.c:204
UniPermGen
UniPermGen wraps a tree encoding Unix-style permissions, and provides an API for setting and checking...
Definition: unipermgen.h:26
UniConfKey
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
Definition: uniconfkey.h:38
UniPermGen::getread
bool getread(const UniConfKey &path, const Credentials &cred)
Return true if a user with the given credentials is allowed to read/write/exec the given path.
Definition: unipermgen.h:59
UniFilterGen
A UniConfGen that delegates all requests to an inner generator.
Definition: unifiltergen.h:17