-//
-// Authorization subsystem support
-//
-kern_return_t ucsp_server_authorizationCreate(UCSP_ARGS,
- void *inRights, mach_msg_type_number_t inRightsLength,
- uint32 flags,
- void *inEnvironment, mach_msg_type_number_t inEnvironmentLength,
- AuthorizationBlob *authorization)
-{
- BEGIN_IPC(authorizationCreate)
- AuthorizationItemSet *authrights = NULL, *authenvironment = NULL;
-
- if (inRights && !copyout_AuthorizationItemSet(inRights, inRightsLength, &authrights))
- {
- Syslog::alert("ucsp_server_authorizationCreate(): error converting 'rights' input");
- CssmError::throwMe(errAuthorizationInternal); // allocation error probably
- }
-
- if (inEnvironment && !copyout_AuthorizationItemSet(inEnvironment, inEnvironmentLength, &authenvironment))
- {
- free(authrights);
- Syslog::alert("ucsp_server_authorizationCreate(): error converting 'environment' input");
- CssmError::throwMe(errAuthorizationInternal); // allocation error probably
- }
-
- Authorization::AuthItemSet rights(authrights), environment(authenvironment);
-
- *rcode = connection.process().session().authCreate(rights, environment,
- flags, *authorization, auditToken);
-
- // @@@ safe-guard against code throw()ing in here
-
- if (authrights)
- free(authrights);
-
- if (authenvironment)
- free(authenvironment);
-
- END_IPC(CSSM)
-}
-
-kern_return_t ucsp_server_authorizationRelease(UCSP_ARGS,
- AuthorizationBlob authorization, uint32 flags)
-{
- BEGIN_IPC(authorizationRelease)
- connection.process().session().authFree(authorization, flags);
- END_IPC(CSSM)
-}
-
-kern_return_t ucsp_server_authorizationCopyRights(UCSP_ARGS,
- AuthorizationBlob authorization,
- void *inRights, mach_msg_type_number_t inRightsLength,
- uint32 flags,
- void *inEnvironment, mach_msg_type_number_t inEnvironmentLength,
- void **result, mach_msg_type_number_t *resultLength)
-{
- BEGIN_IPC(authorizationCopyRights)
- AuthorizationItemSet *authrights = NULL, *authenvironment = NULL;
-
- if (inRights && !copyout_AuthorizationItemSet(inRights, inRightsLength, &authrights))
- {
- Syslog::alert("ucsp_server_authorizationCopyRights(): error converting 'rights' input");
- CssmError::throwMe(errAuthorizationInternal); // allocation error probably
- }
- if (inEnvironment && !copyout_AuthorizationItemSet(inEnvironment, inEnvironmentLength, &authenvironment))
- {
- free(authrights);
- Syslog::alert("ucsp_server_authorizationCopyRights(): error converting 'environment' input");
- CssmError::throwMe(errAuthorizationInternal); // allocation error probably
- }
-
- Authorization::AuthItemSet rights(authrights), environment(authenvironment), grantedRights;
- *rcode = Session::authGetRights(authorization, rights, environment, flags, grantedRights);
-
- // @@@ safe-guard against code throw()ing in here
-
- if (authrights)
- free(authrights);
-
- if (authenvironment)
- free(authenvironment);
-
- if (result && resultLength)
- {
- AuthorizationItemSet *copyout = grantedRights.copy();
- if (!copyin_AuthorizationItemSet(copyout, result, resultLength))
- {
- free(copyout);
- Syslog::alert("ucsp_server_authorizationCopyRights(): error packaging return information");
- CssmError::throwMe(errAuthorizationInternal);
- }
- free(copyout);
- Server::releaseWhenDone(*result);
- }
- END_IPC(CSSM)
-}
-
-kern_return_t ucsp_server_authorizationCopyInfo(UCSP_ARGS,
- AuthorizationBlob authorization,
- AuthorizationString tag,
- void **info, mach_msg_type_number_t *infoLength)
-{
- BEGIN_IPC(authorizationCopyInfo)
- Authorization::AuthItemSet infoSet;
- *info = NULL;
- *infoLength = 0;
- *rcode = connection.process().session().authGetInfo(authorization,
- tag[0] ? tag : NULL, infoSet);
- if (*rcode == noErr)
- {
- AuthorizationItemSet *copyout = infoSet.copy();
- if (!copyin_AuthorizationItemSet(copyout, info, infoLength))
- {
- free(copyout);
- Syslog::alert("ucsp_server_authorizationCopyInfo(): error packaging return information");
- CssmError::throwMe(errAuthorizationInternal);
- }
- free(copyout);
- Server::releaseWhenDone(*info);
- }
- END_IPC(CSSM)
-}
-
-kern_return_t ucsp_server_authorizationExternalize(UCSP_ARGS,
- AuthorizationBlob authorization, AuthorizationExternalForm *extForm)
-{
- BEGIN_IPC(authorizationExternalize)
- *rcode = connection.process().session().authExternalize(authorization, *extForm);
- END_IPC(CSSM)
-}
-
-kern_return_t ucsp_server_authorizationInternalize(UCSP_ARGS,
- AuthorizationExternalForm extForm, AuthorizationBlob *authorization)
-{
- BEGIN_IPC(authorizationInternalize)
- *rcode = connection.process().session().authInternalize(extForm, *authorization);
- END_IPC(CSSM)
-}
-
-
-//
-// Session management subsystem
-//
-kern_return_t ucsp_server_setSessionUserPrefs(UCSP_ARGS, SecuritySessionId sessionId, DATA_IN(userPrefs))
-{
- BEGIN_IPC(setSessionuserPrefs)
- CFRef<CFDataRef> data(CFDataCreate(NULL, (UInt8 *)userPrefs, userPrefsLength));
-
- if (!data)
- {
- *rcode = errSessionValueNotSet;
- return 0;
- }
-
- Session::find<DynamicSession>(sessionId).setUserPrefs(data);
- *rcode = 0;
-
- END_IPC(CSSM)
-}
-
-