#ifndef _H_TOKENCACHE
#define _H_TOKENCACHE
#include <security_utilities/refcount.h>
#include <Security/cssm.h>
class Rooted {
public:
Rooted() { }
Rooted(const char *root) : mRoot(root) { }
Rooted(const string &root) : mRoot(root) { }
string root() const { return mRoot; }
string path(const char *sub) const;
string path(const string &sub) const { return path(sub.c_str()); }
protected:
void root(const string &s);
private:
string mRoot; };
class TokenCache : public Rooted {
public:
TokenCache(const char *root);
~TokenCache();
uid_t tokendUid() const { return mTokendUid; }
gid_t tokendGid() const { return mTokendGid; }
public:
class Token : public RefCount, public Rooted {
public:
friend class TokenCache;
Token(TokenCache &cache, const std::string &uid);
Token(TokenCache &cache);
~Token();
enum Type { existing, created, temporary };
Type type() const { return mType; }
TokenCache &cache;
uint32 subservice() const { return mSubservice; }
string workPath() const;
string cachePath() const;
string printName() const;
void printName(const string &name);
uid_t tokendUid() const { return cache.tokendUid(); }
gid_t tokendGid() const { return cache.tokendGid(); }
protected:
void init(Type type);
private:
uint32 mSubservice; Type mType; };
public:
uint32 allocateSubservice();
private:
enum Owner { securityd, tokend };
void makedir(const char *path, int flags, mode_t mode, Owner owner);
void makedir(const string &path, int flags, mode_t mode, Owner owner)
{ return makedir(path.c_str(), flags, mode, owner); }
private:
uint32 mLastSubservice;
uid_t mTokendUid; gid_t mTokendGid; };
#endif //_H_TOKENCACHE