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.
20 // acl_process - Process-attribute ACL subject type.
22 #include <Security/acl_process.h>
23 #include <Security/endian.h>
28 // Validate a credential set against this subject.
29 // No credential is required for this match.
31 bool ProcessAclSubject::validate(const AclValidationContext
&context
) const
33 // reality check (internal structure was validated when created)
34 assert(select
.uses(CSSM_ACL_MATCH_BITS
));
36 // access the environment
37 Environment
*env
= context
.environment
<Environment
>();
39 static Environment localEnvironment
;
40 env
= &localEnvironment
;
44 if (select
.uses(CSSM_ACL_MATCH_UID
)) {
45 uid_t uid
= env
->getuid();
46 if (!(uid
== select
.uid
|| (select
.uses(CSSM_ACL_MATCH_HONOR_ROOT
) && uid
== 0)))
51 if (select
.uses(CSSM_ACL_MATCH_GID
) && select
.gid
!= env
->getgid())
59 // Make a copy of this subject in CSSM_LIST form
61 CssmList
ProcessAclSubject::toList(CssmAllocator
&alloc
) const
63 // all associated data is public (no secrets)
64 //@@@ ownership of selector data is murky; revisit after leak-plugging pass
65 CssmData
sData(memcpy(alloc
.alloc
<CSSM_ACL_PROCESS_SUBJECT_SELECTOR
>(),
66 &select
, sizeof(select
)), sizeof(select
));
67 return TypedList(alloc
, CSSM_ACL_SUBJECT_TYPE_PROCESS
,
68 new(alloc
) ListElement(sData
));
73 // Create a ProcessAclSubject
75 ProcessAclSubject
*ProcessAclSubject::Maker::make(const TypedList
&list
) const
78 ListElement
*selectorData
;
79 crack(list
, 1, &selectorData
, CSSM_LIST_ELEMENT_DATUM
);
80 AclProcessSubjectSelector selector
;
81 selectorData
->extract(selector
);
84 if (selector
.version
!= CSSM_ACL_PROCESS_SELECTOR_CURRENT_VERSION
)
85 CssmError::throwMe(CSSM_ERRCODE_INVALID_ACL_SUBJECT_VALUE
);
86 if (!selector
.uses(CSSM_ACL_MATCH_BITS
))
87 CssmError::throwMe(CSSM_ERRCODE_INVALID_ACL_SUBJECT_VALUE
);
90 return new ProcessAclSubject(selector
);
93 ProcessAclSubject
*ProcessAclSubject::Maker::make(Version
, Reader
&pub
, Reader
&priv
) const
95 AclProcessSubjectSelector selector
; pub(selector
);
96 n2hi(selector
.version
);
100 return new ProcessAclSubject(selector
);
105 // Export the subject to a memory blob
107 void ProcessAclSubject::exportBlob(Writer::Counter
&pub
, Writer::Counter
&priv
)
112 void ProcessAclSubject::exportBlob(Writer
&pub
, Writer
&priv
)
114 AclProcessSubjectSelector temp
;
115 temp
.version
= h2n (select
.version
);
116 temp
.mask
= h2n (select
.mask
);
117 temp
.uid
= h2n (select
.uid
);
118 temp
.gid
= h2n (select
.gid
);
124 // Implement the default methods of a ProcessEnvironment
126 uid_t
ProcessAclSubject::Environment::getuid() const
131 gid_t
ProcessAclSubject::Environment::getgid() const
139 void ProcessAclSubject::debugDump() const
141 Debug::dump("Process ");
142 if (select
.uses(CSSM_ACL_MATCH_UID
)) {
143 Debug::dump("uid=%d", int(select
.uid
));
144 if (select
.uses(CSSM_ACL_MATCH_HONOR_ROOT
))
145 Debug::dump("+root");
147 if (select
.uses(CSSM_ACL_MATCH_GID
))
148 Debug::dump("gid=%d", int(select
.gid
));