2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
24 * Modification History
26 * June 1, 2001 Allan Nathanson <ajn@apple.com>
27 * - public API conversion
29 * January 2, 2001 Allan Nathanson <ajn@apple.com>
33 #include <SystemConfiguration/SystemConfiguration.h>
34 #include <SystemConfiguration/SCValidation.h>
35 #include <SystemConfiguration/SCPrivate.h>
38 SCDynamicStoreKeyCreateConsoleUser(CFAllocatorRef allocator
)
40 return SCDynamicStoreKeyCreate(allocator
,
42 kSCDynamicStoreDomainState
,
44 kSCEntUsersConsoleUser
);
49 SCDynamicStoreCopyConsoleUser(SCDynamicStoreRef store
,
53 CFStringRef consoleUser
= NULL
;
54 CFDictionaryRef dict
= NULL
;
56 Boolean tempSession
= FALSE
;
59 store
= SCDynamicStoreCreate(NULL
,
60 CFSTR("SCDynamicStoreCopyConsoleUser"),
64 SCLog(_sc_verbose
, LOG_INFO
, CFSTR("SCDynamicStoreCreate() failed"));
70 key
= SCDynamicStoreKeyCreateConsoleUser(NULL
);
71 dict
= SCDynamicStoreCopyValue(store
, key
);
73 if (!isA_CFDictionary(dict
)) {
74 _SCErrorSet(kSCStatusNoKey
);
78 consoleUser
= CFDictionaryGetValue(dict
, kSCPropUsersConsoleUserName
);
79 consoleUser
= isA_CFString(consoleUser
);
81 _SCErrorSet(kSCStatusNoKey
);
85 CFRetain(consoleUser
);
91 num
= CFDictionaryGetValue(dict
, kSCPropUsersConsoleUserUID
);
92 if (isA_CFNumber(num
)) {
93 if (CFNumberGetValue(num
, kCFNumberSInt32Type
, &val
)) {
103 num
= CFDictionaryGetValue(dict
, kSCPropUsersConsoleUserGID
);
104 if (isA_CFNumber(num
)) {
105 if (CFNumberGetValue(num
, kCFNumberSInt32Type
, &val
)) {
113 if (tempSession
) CFRelease(store
);
114 if (dict
) CFRelease(dict
);
121 SCDynamicStoreSetConsoleUser(SCDynamicStoreRef store
,
126 CFStringRef consoleUser
;
127 CFMutableDictionaryRef dict
= NULL
;
128 CFStringRef key
= SCDynamicStoreKeyCreateConsoleUser(NULL
);
131 Boolean tempSession
= FALSE
;
134 store
= SCDynamicStoreCreate(NULL
,
135 CFSTR("SCDynamicStoreSetConsoleUser"),
139 SCLog(_sc_verbose
, LOG_INFO
, CFSTR("SCDynamicStoreCreate() failed"));
146 ok
= SCDynamicStoreRemoveValue(store
, key
);
150 dict
= CFDictionaryCreateMutable(NULL
,
152 &kCFTypeDictionaryKeyCallBacks
,
153 &kCFTypeDictionaryValueCallBacks
);
155 consoleUser
= CFStringCreateWithCString(NULL
, user
, kCFStringEncodingMacRoman
);
156 CFDictionarySetValue(dict
, kSCPropUsersConsoleUserName
, consoleUser
);
157 CFRelease(consoleUser
);
159 num
= CFNumberCreate(NULL
, kCFNumberSInt32Type
, (SInt32
*)&uid
);
160 CFDictionarySetValue(dict
, kSCPropUsersConsoleUserUID
, num
);
163 num
= CFNumberCreate(NULL
, kCFNumberSInt32Type
, (SInt32
*)&gid
);
164 CFDictionarySetValue(dict
, kSCPropUsersConsoleUserGID
, num
);
167 ok
= SCDynamicStoreSetValue(store
, key
, dict
);
171 if (dict
) CFRelease(dict
);
172 if (key
) CFRelease(key
);
173 if (tempSession
) CFRelease(store
);