/*
- * Copyright (c) 2000-2004 Apple Computer, Inc. All Rights Reserved.
+ * Copyright (c) 2000-2004,2009 Apple Inc. All Rights Reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
namespace Authorization {
// default credential: invalid for everything, needed as a default session credential
-CredentialImpl::CredentialImpl() : mUid(0), mShared(false), mName(""), mRealname(""), mCreationTime(CFAbsoluteTimeGetCurrent()), mValid(false), mRight(false)
+CredentialImpl::CredentialImpl() : mShared(false), mRight(false), mUid(0), mName(""), mCreationTime(CFAbsoluteTimeGetCurrent()), mValid(false)
{
}
// only for testing whether this credential is usable
-CredentialImpl::CredentialImpl(const uid_t uid, const string &username, const string &realname, bool shared) : mUid(uid), mShared(shared), mName(username), mRealname(realname), mCreationTime(CFAbsoluteTimeGetCurrent()), mValid(true), mRight(false)
+CredentialImpl::CredentialImpl(const uid_t uid, const string &username, const string &realname, bool shared) : mShared(shared), mRight(false), mUid(uid), mName(username), mRealName(realname), mCreationTime(CFAbsoluteTimeGetCurrent()), mValid(true)
{
}
-CredentialImpl::CredentialImpl(const string &username, const string &password, bool shared) : mShared(shared), mName(username), mCreationTime(CFAbsoluteTimeGetCurrent()), mValid(false), mRight(false)
+CredentialImpl::CredentialImpl(const string &username, const string &password, bool shared) : mShared(shared), mRight(false), mName(username), mCreationTime(CFAbsoluteTimeGetCurrent()), mValid(false)
{
Server::active().longTermActivity();
const char *user = username.c_str();
mUid = pw->pw_uid;
mName = pw->pw_name;
- mRealname = pw->pw_gecos;
+ mRealName = pw->pw_gecos;
const char *passwd = password.c_str();
int checkpw_status = checkpw_internal(pw, passwd);
} while (0);
}
-CredentialImpl::CredentialImpl(const string &right, bool shared) : mUid(-2), mShared(shared), mName(right), mCreationTime(CFAbsoluteTimeGetCurrent()), mValid(true), mRight(true)
+// least-privilege
+ // @@@ arguably we don't care about the UID any more and should not
+ // require it in this ctor
+CredentialImpl::CredentialImpl(const string &right, bool shared) : mShared(shared), mRight(true), mUid(-2), mName(right), mRealName(""), mCreationTime(CFAbsoluteTimeGetCurrent()), mValid(true)
{
}
bool
CredentialImpl::operator < (const CredentialImpl &other) const
{
- if (!mShared && other.mShared)
- return true;
- if (!other.mShared && mShared)
- return false;
-
+ // all shared creds are placed into mSessionCreds
+ // all non shared creds are placed into AuthorizationToken
+ //
+ // There are 2 types of credentials UID and Right
+ // UID = Authenticated Identity
+ // Right = Rights which were previously authenticated by a uid credential
+
+ // Right Credentials are only used during kAuthorizationFlagLeastPrivileged
+ // operations and should not have a valid uid set
+
+ // this allows shared and none shared co-exist in the same container
+ // used when processing multiple rights shared vs non-shared during evaluation
+ if (!mShared && other.mShared)
+ return true;
+ if (!other.mShared && mShared)
+ return false;
+
+ // this allows uids and rights co-exist in the same container
+ // used when holding onto Rights inside of the AuthorizationToken
+ if (mRight && !other.mRight)
+ return true;
+ if (!mRight && other.mRight)
+ return false;
+
+ // this is the actual comparision
+ if (mRight) {
+ return mName < other.mName;
+ } else {
return mUid < other.mUid;
+ }
}
// Returns true if this CredentialImpl should be shared.
void
CredentialImpl::merge(const CredentialImpl &other)
{
+ // try to ensure that the credentials are the same type
+ assert(mRight == other.mRight);
+ if (mRight)
+ assert(mName == other.mName);
+ else
assert(mUid == other.mUid);
- if (other.mValid && (!mValid || mCreationTime < other.mCreationTime))
- {
- mCreationTime = other.mCreationTime;
- mValid = true;
- }
+ if (other.mValid && (!mValid || mCreationTime < other.mCreationTime))
+ {
+ mCreationTime = other.mCreationTime;
+ mValid = true;
+ }
}
// The time at which this credential was obtained.