2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
23 * Copyright: (c) 2000 by Apple Computer, Inc., all rights reserved
27 #ifndef _H_AUTHORIZATIONDATA
28 #define _H_AUTHORIZATIONDATA 1
30 #include <Security/Authorization.h>
31 #include <Security/AuthorizationPlugin.h>
33 #include <Security/refcount.h>
34 #include <Security/cssmalloc.h>
40 // ptrdiff_t needed, so including STL type closest
43 namespace Authorization
46 class AuthValueOverlay
: public AuthorizationValue
49 AuthValueOverlay(const string
& stringValue
) { length
= stringValue
.length(); data
= const_cast<char *>(stringValue
.c_str()); }
50 AuthValueOverlay(UInt32 inLength
, void *inData
) { length
= inLength
; data
= inData
; }
55 class AuthValue
: public RefCount
57 friend class AuthValueRef
;
59 AuthValue(const AuthValue
& value
) {}
61 AuthValue(const AuthorizationValue
&value
);
62 AuthValue(UInt32 length
, void *data
);
64 AuthValue
&operator = (const AuthValue
&other
);
66 void fillInAuthorizationValue(AuthorizationValue
&value
);
67 const AuthorizationValue
& value() const { return mValue
; }
69 AuthorizationValue mValue
;
70 mutable bool mOwnsValue
;
74 class AuthValueRef
: public RefPointer
<AuthValue
>
77 AuthValueRef(const AuthValue
&value
);
78 AuthValueRef(const AuthorizationValue
&value
);
79 AuthValueRef(UInt32 length
, void *data
);
83 // vector should become a member with accessors
84 class AuthValueVector
: public vector
<AuthValueRef
>
86 NOCOPY(AuthValueVector
)
91 AuthValueVector
&operator = (const AuthorizationValueVector
& valueVector
);
93 void copy(AuthorizationValueVector
**data
, size_t *length
) const;
100 class AuthItem
: public RefCount
102 friend class AuthItemRef
;
104 AuthItem(const AuthItem
& item
);
106 AuthItem(const AuthorizationItem
&item
);
107 AuthItem(AuthorizationString name
);
108 AuthItem(AuthorizationString name
, AuthorizationValue value
);
109 AuthItem(AuthorizationString name
, AuthorizationValue value
, AuthorizationFlags flags
);
111 bool operator < (const AuthItem
&other
) const;
114 AuthItem
&operator = (const AuthItem
&other
);
117 void fillInAuthorizationItem(AuthorizationItem
&item
);
119 AuthorizationString
name() const { return mName
; }
120 const AuthorizationValue
& value() const { return mValue
; }
121 string
stringValue() const { return string(static_cast<char *>(mValue
.data
), mValue
.length
); }
122 AuthorizationFlags
flags() const { return mFlags
; }
123 void setFlags(AuthorizationFlags inFlags
) { mFlags
= inFlags
; };
126 AuthorizationString mName
;
127 AuthorizationValue mValue
;
128 AuthorizationFlags mFlags
;
129 mutable bool mOwnsName
;
130 mutable bool mOwnsValue
;
133 class AuthItemRef
: public RefPointer
<AuthItem
>
136 AuthItemRef(const AuthorizationItem
&item
);
137 AuthItemRef(AuthorizationString name
);
138 AuthItemRef(AuthorizationString name
, AuthorizationValue value
, AuthorizationFlags flags
= 0);
140 bool operator < (const AuthItemRef
&other
) const
142 return **this < *other
;
146 // set should become a member with accessors
147 class AuthItemSet
: public set
<AuthItemRef
>
152 AuthItemSet(const AuthorizationItemSet
*item
);
154 AuthItemSet
&operator = (const AuthorizationItemSet
& itemSet
);
156 void copy(AuthorizationItemSet
*&data
, size_t &length
, CssmAllocator
&alloc
= CssmAllocator::standard()) const;
159 class FindAuthItemByRightName
162 FindAuthItemByRightName(const char *find_name
) : name(find_name
) { }
164 bool operator()( const AuthItemRef
& authitem
)
166 return (!strcmp(name
, authitem
->name()));
168 bool operator()( const AuthorizationItem
* authitem
)
170 return (!strcmp(name
, authitem
->name
));
179 /* Credentials are less than comparable so they can be put in sets or maps. */
180 class CredentialImpl
: public RefCount
183 CredentialImpl(const string
&username
, const uid_t uid
, gid_t gid
, bool shared
);
184 CredentialImpl(const string
&username
, const string
&password
, bool shared
);
187 bool operator < (const CredentialImpl
&other
) const;
189 // Returns true if this credential should be shared.
190 bool isShared() const;
193 void merge(const CredentialImpl
&other
);
195 // The time at which this credential was obtained.
196 CFAbsoluteTime
creationTime() const;
198 // Return true iff this credential is valid.
199 bool isValid() const;
201 // Make this credential invalid.
204 // We could make Rule a friend but instead we just expose this for now
205 inline const string
& username() const { return mUsername
; }
206 inline const uid_t
uid() const { return mUid
; }
207 inline const gid_t
gid() const { return mGid
; }
211 // The username of the user that provided his password.
212 // This and mShared are what make this credential unique.
213 // @@@ We do not deal with the domain as of yet.
216 // True iff this credential is shared.
219 // Fields below are not used by less than operator
221 // cached pw-data as returned by getpwnam(mUsername)
225 CFAbsoluteTime mCreationTime
;
230 /* Credentials are less than comparable so they can be put in sets or maps. */
231 class Credential
: public RefPointer
<CredentialImpl
>
235 Credential(CredentialImpl
*impl
);
236 Credential(const string
&username
, const uid_t uid
, gid_t gid
, bool shared
);
237 Credential(const string
&username
, const string
&password
, bool shared
);
240 bool operator < (const Credential
&other
) const;
244 typedef set
<Credential
> CredentialSet
;
249 }; // namespace Authorization
251 #endif /* ! _H_AUTHORIZATIONDATA */