2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 * Modification History
27 * May 1, 2003 Allan Nathanson <ajn@apple.com>
28 * - add console [session] information SPIs
30 * June 1, 2001 Allan Nathanson <ajn@apple.com>
31 * - public API conversion
33 * January 2, 2001 Allan Nathanson <ajn@apple.com>
37 #include <SystemConfiguration/SystemConfiguration.h>
38 #include <SystemConfiguration/SCValidation.h>
39 #include <SystemConfiguration/SCPrivate.h>
42 #ifndef kSCPropUsersConsoleUserName
43 #define kSCPropUsersConsoleUserName CFSTR("Name")
46 #ifndef kSCPropUsersConsoleUserUID
47 #define kSCPropUsersConsoleUserUID CFSTR("UID")
50 #ifndef kSCPropUsersConsoleUserGID
51 #define kSCPropUsersConsoleUserGID CFSTR("GID")
54 #ifndef kSCPropUsersConsoleSessionInfo
55 #define kSCPropUsersConsoleSessionInfo CFSTR("SessionInfo")
59 // from CoreGraphics (CGSession.h)
60 const CFStringRef kSCConsoleSessionUserName
= CFSTR("kCGSSessionUserNameKey"); /* value is CFString */
61 const CFStringRef kSCConsoleSessionUID
= CFSTR("kCGSSessionUserIDKey"); /* value is CFNumber (a uid_t) */
62 const CFStringRef kSCConsoleSessionConsoleSet
= CFSTR("kCGSSessionConsoleSetKey"); /* value is CFNumber */
63 const CFStringRef kSCConsoleSessionOnConsole
= CFSTR("kCGSSessionOnConsoleKey"); /* value is CFBoolean */
64 const CFStringRef kSCConsoleSessionLoginDone
= CFSTR("kCGSessionLoginDoneKey"); /* value is CFBoolean */
66 // from CoreGraphics (CGSSession.h)
67 const CFStringRef kSCConsoleSessionID
= CFSTR("kCGSSessionIDKey"); /* value is CFNumber */
70 const CFStringRef kSCConsoleSessionSystemSafeBoot
= CFSTR("kCGSSessionSystemSafeBoot"); /* value is CFBoolean */
71 const CFStringRef kSCConsoleSessionLoginwindowSafeLogin
= CFSTR("kCGSSessionLoginwindowSafeLogin"); /* value is CFBoolean */
75 SCDynamicStoreKeyCreateConsoleUser(CFAllocatorRef allocator
)
77 return SCDynamicStoreKeyCreate(allocator
,
79 kSCDynamicStoreDomainState
,
81 kSCEntUsersConsoleUser
);
86 SCDynamicStoreCopyConsoleUser(SCDynamicStoreRef store
,
90 CFStringRef consoleUser
= NULL
;
91 CFDictionaryRef dict
= NULL
;
93 Boolean tempSession
= FALSE
;
96 store
= SCDynamicStoreCreate(NULL
,
97 CFSTR("SCDynamicStoreCopyConsoleUser"),
106 key
= SCDynamicStoreKeyCreateConsoleUser(NULL
);
107 dict
= SCDynamicStoreCopyValue(store
, key
);
109 if (!isA_CFDictionary(dict
)) {
110 _SCErrorSet(kSCStatusNoKey
);
114 consoleUser
= CFDictionaryGetValue(dict
, kSCPropUsersConsoleUserName
);
115 consoleUser
= isA_CFString(consoleUser
);
117 _SCErrorSet(kSCStatusNoKey
);
121 CFRetain(consoleUser
);
127 num
= CFDictionaryGetValue(dict
, kSCPropUsersConsoleUserUID
);
128 if (isA_CFNumber(num
)) {
129 if (CFNumberGetValue(num
, kCFNumberSInt32Type
, &val
)) {
139 num
= CFDictionaryGetValue(dict
, kSCPropUsersConsoleUserGID
);
140 if (isA_CFNumber(num
)) {
141 if (CFNumberGetValue(num
, kCFNumberSInt32Type
, &val
)) {
149 if (tempSession
) CFRelease(store
);
150 if (dict
) CFRelease(dict
);
156 SCDynamicStoreCopyConsoleInformation(SCDynamicStoreRef store
)
158 CFDictionaryRef dict
= NULL
;
159 CFArrayRef info
= NULL
;
161 Boolean tempSession
= FALSE
;
164 store
= SCDynamicStoreCreate(NULL
,
165 CFSTR("SCDynamicStoreCopyConsoleUser"),
174 key
= SCDynamicStoreKeyCreateConsoleUser(NULL
);
175 dict
= SCDynamicStoreCopyValue(store
, key
);
177 if (!isA_CFDictionary(dict
)) {
178 _SCErrorSet(kSCStatusNoKey
);
182 info
= CFDictionaryGetValue(dict
, kSCPropUsersConsoleSessionInfo
);
183 info
= isA_CFArray(info
);
185 _SCErrorSet(kSCStatusNoKey
);
193 if (tempSession
) CFRelease(store
);
194 if (dict
) CFRelease(dict
);
200 SCDynamicStoreSetConsoleInformation(SCDynamicStoreRef store
,
206 CFStringRef consoleUser
;
207 CFMutableDictionaryRef dict
= NULL
;
208 CFStringRef key
= SCDynamicStoreKeyCreateConsoleUser(NULL
);
210 Boolean tempSession
= FALSE
;
213 store
= SCDynamicStoreCreate(NULL
,
214 CFSTR("SCDynamicStoreSetConsoleUser"),
223 if ((user
== NULL
) && (sessions
== NULL
)) {
224 (void) SCDynamicStoreRemoveValue(store
, key
);
228 dict
= CFDictionaryCreateMutable(NULL
,
230 &kCFTypeDictionaryKeyCallBacks
,
231 &kCFTypeDictionaryValueCallBacks
);
236 consoleUser
= CFStringCreateWithCString(NULL
, user
, kCFStringEncodingMacRoman
);
237 CFDictionarySetValue(dict
, kSCPropUsersConsoleUserName
, consoleUser
);
238 CFRelease(consoleUser
);
240 num
= CFNumberCreate(NULL
, kCFNumberSInt32Type
, (SInt32
*)&uid
);
241 CFDictionarySetValue(dict
, kSCPropUsersConsoleUserUID
, num
);
244 num
= CFNumberCreate(NULL
, kCFNumberSInt32Type
, (SInt32
*)&gid
);
245 CFDictionarySetValue(dict
, kSCPropUsersConsoleUserGID
, num
);
249 if (sessions
!= NULL
) {
250 CFDictionarySetValue(dict
, kSCPropUsersConsoleSessionInfo
, sessions
);
253 ok
= SCDynamicStoreSetValue(store
, key
, dict
);
257 if (dict
) CFRelease(dict
);
258 if (key
) CFRelease(key
);
259 if (tempSession
) CFRelease(store
);
265 SCDynamicStoreSetConsoleUser(SCDynamicStoreRef store
,
270 CFStringRef consoleUser
;
271 CFMutableDictionaryRef dict
= NULL
;
272 CFStringRef key
= SCDynamicStoreKeyCreateConsoleUser(NULL
);
275 Boolean tempSession
= FALSE
;
278 store
= SCDynamicStoreCreate(NULL
,
279 CFSTR("SCDynamicStoreSetConsoleUser"),
289 (void) SCDynamicStoreRemoveValue(store
, key
);
293 dict
= CFDictionaryCreateMutable(NULL
,
295 &kCFTypeDictionaryKeyCallBacks
,
296 &kCFTypeDictionaryValueCallBacks
);
298 consoleUser
= CFStringCreateWithCString(NULL
, user
, kCFStringEncodingMacRoman
);
299 CFDictionarySetValue(dict
, kSCPropUsersConsoleUserName
, consoleUser
);
300 CFRelease(consoleUser
);
302 num
= CFNumberCreate(NULL
, kCFNumberSInt32Type
, (SInt32
*)&uid
);
303 CFDictionarySetValue(dict
, kSCPropUsersConsoleUserUID
, num
);
306 num
= CFNumberCreate(NULL
, kCFNumberSInt32Type
, (SInt32
*)&gid
);
307 CFDictionarySetValue(dict
, kSCPropUsersConsoleUserGID
, num
);
310 ok
= SCDynamicStoreSetValue(store
, key
, dict
);
314 if (dict
) CFRelease(dict
);
315 if (key
) CFRelease(key
);
316 if (tempSession
) CFRelease(store
);