]> git.saurik.com Git - apple/securityd.git/blob - src/credential.h
securityd-36489.tar.gz
[apple/securityd.git] / src / credential.h
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #ifndef _H_CREDENTIAL
25 #define _H_CREDENTIAL
26
27 #include <security_utilities/refcount.h>
28 #include <CoreFoundation/CFDate.h>
29 #include <set>
30
31 namespace Authorization {
32
33 /* Credentials are less than comparable so they can be put in sets or maps. */
34 class CredentialImpl : public RefCount
35 {
36 public:
37 CredentialImpl();
38 CredentialImpl(const uid_t uid, const string &username, const string &realname, bool shared);
39 CredentialImpl(const string &username, const string &password, bool shared);
40 CredentialImpl(const string &right, bool shared);
41 ~CredentialImpl();
42
43 bool operator < (const CredentialImpl &other) const;
44
45 // Returns true if this credential should be shared.
46 bool isShared() const;
47
48 // Merge with other
49 void merge(const CredentialImpl &other);
50
51 // The time at which this credential was obtained.
52 CFAbsoluteTime creationTime() const;
53
54 // Return true iff this credential is valid.
55 bool isValid() const;
56
57 // Make this credential invalid.
58 void invalidate();
59
60 // We could make Rule a friend but instead we just expose this for now
61 inline const uid_t uid() const { return mUid; }
62 inline const string& name() const { return mName; }
63 inline const string& realname() const { return mRealname; }
64 inline const bool isRight() const { return mRight; }
65 private:
66 // Key
67 uid_t mUid;
68
69 // True iff this credential is shared.
70 bool mShared;
71
72 // Fields below are not used by less than operator
73
74 // The username of the user that provided his password.
75 string mName;
76 string mRealname;
77
78 CFAbsoluteTime mCreationTime;
79 bool mValid;
80 bool mRight;
81 };
82
83 /* Credentials are less than comparable so they can be put in sets or maps. */
84 class Credential : public RefPointer<CredentialImpl>
85 {
86 public:
87 Credential();
88 Credential(CredentialImpl *impl);
89 Credential(const uid_t uid, const string &username, const string &realname, bool shared);
90 Credential(const string &username, const string &password, bool shared);
91 Credential(const string &right, bool shared);
92 ~Credential();
93
94 bool operator < (const Credential &other) const;
95 };
96
97 typedef set<Credential> CredentialSet;
98
99 } // namespace Authorization
100
101 #endif // _H_CREDENTIAL