]> git.saurik.com Git - apple/securityd.git/blobdiff - src/credential.h
securityd-32661.tar.gz
[apple/securityd.git] / src / credential.h
diff --git a/src/credential.h b/src/credential.h
new file mode 100644 (file)
index 0000000..78363ee
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2000-2004 Apple Computer, Inc. All Rights Reserved.
+ * 
+ * @APPLE_LICENSE_HEADER_START@
+ * 
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ * 
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#ifndef _H_CREDENTIAL
+#define _H_CREDENTIAL
+
+#include <security_utilities/refcount.h>
+#include <CoreFoundation/CFDate.h>
+#include <set>
+
+namespace Authorization {
+
+/* Credentials are less than comparable so they can be put in sets or maps. */
+class CredentialImpl : public RefCount
+{
+public:
+               CredentialImpl();
+        CredentialImpl(const uid_t uid, const string &username, const string &realname, bool shared);
+        CredentialImpl(const string &username, const string &password, bool shared);
+               CredentialImpl(const string &right, bool shared);
+        ~CredentialImpl();
+
+        bool operator < (const CredentialImpl &other) const;
+
+        // Returns true if this credential should be shared.
+        bool isShared() const;
+
+        // Merge with other
+        void merge(const CredentialImpl &other);
+
+        // The time at which this credential was obtained.
+        CFAbsoluteTime creationTime() const;
+
+        // Return true iff this credential is valid.
+        bool isValid() const;
+
+        // Make this credential invalid.
+        void invalidate();
+
+        // We could make Rule a friend but instead we just expose this for now
+        inline const uid_t uid() const { return mUid; }
+        inline const string& name() const { return mName; }
+        inline const string& realname() const { return mRealname; }
+               inline const bool isRight() const { return mRight; }
+private:
+        // Key
+        uid_t mUid;
+
+        // True iff this credential is shared.
+        bool mShared;
+
+        // Fields below are not used by less than operator
+
+        // The username of the user that provided his password.
+        string mName;
+        string mRealname;
+
+        CFAbsoluteTime mCreationTime;
+        bool mValid;
+               bool mRight;
+};
+
+/* Credentials are less than comparable so they can be put in sets or maps. */
+class Credential : public RefPointer<CredentialImpl>
+{
+public:
+        Credential();
+        Credential(CredentialImpl *impl);
+        Credential(const uid_t uid, const string &username, const string &realname, bool shared);
+        Credential(const string &username, const string &password, bool shared);
+               Credential(const string &right, bool shared);           
+        ~Credential();
+
+        bool operator < (const Credential &other) const;
+};
+
+typedef set<Credential> CredentialSet;
+
+} // namespace Authorization
+
+#endif // _H_CREDENTIAL