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/SCPrivate.h>
35 #include <SystemConfiguration/SCValidation.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 SCDynamicStoreRef mySession
= store
;
59 mySession
= SCDynamicStoreCreate(NULL
,
60 CFSTR("SCDynamicStoreCopyConsoleUser"),
64 SCLog(_sc_verbose
, LOG_INFO
, CFSTR("SCDynamicStoreCreate() failed"));
69 key
= SCDynamicStoreKeyCreateConsoleUser(NULL
);
70 dict
= SCDynamicStoreCopyValue(mySession
, key
);
72 if (!isA_CFDictionary(dict
)) {
73 _SCErrorSet(kSCStatusNoKey
);
77 consoleUser
= CFDictionaryGetValue(dict
, kSCPropUsersConsoleUserName
);
78 consoleUser
= isA_CFString(consoleUser
);
80 _SCErrorSet(kSCStatusNoKey
);
84 CFRetain(consoleUser
);
90 num
= CFDictionaryGetValue(dict
, kSCPropUsersConsoleUserUID
);
91 if (isA_CFNumber(num
)) {
92 if (CFNumberGetValue(num
, kCFNumberSInt32Type
, &val
)) {
102 num
= CFDictionaryGetValue(dict
, kSCPropUsersConsoleUserGID
);
103 if (isA_CFNumber(num
)) {
104 if (CFNumberGetValue(num
, kCFNumberSInt32Type
, &val
)) {
112 if (!store
&& mySession
) CFRelease(mySession
);
113 if (dict
) CFRelease(dict
);
120 SCDynamicStoreSetConsoleUser(SCDynamicStoreRef store
,
125 CFStringRef consoleUser
;
126 CFMutableDictionaryRef dict
= NULL
;
127 CFStringRef key
= SCDynamicStoreKeyCreateConsoleUser(NULL
);
128 SCDynamicStoreRef mySession
= store
;
133 mySession
= SCDynamicStoreCreate(NULL
,
134 CFSTR("SCDynamicStoreSetConsoleUser"),
138 SCLog(_sc_verbose
, LOG_INFO
, CFSTR("SCDynamicStoreCreate() failed"));
144 ok
= SCDynamicStoreRemoveValue(mySession
, key
);
148 dict
= CFDictionaryCreateMutable(NULL
,
150 &kCFTypeDictionaryKeyCallBacks
,
151 &kCFTypeDictionaryValueCallBacks
);
153 consoleUser
= CFStringCreateWithCString(NULL
, user
, kCFStringEncodingMacRoman
);
154 CFDictionarySetValue(dict
, kSCPropUsersConsoleUserName
, consoleUser
);
155 CFRelease(consoleUser
);
157 num
= CFNumberCreate(NULL
, kCFNumberSInt32Type
, (SInt32
*)&uid
);
158 CFDictionarySetValue(dict
, kSCPropUsersConsoleUserUID
, num
);
161 num
= CFNumberCreate(NULL
, kCFNumberSInt32Type
, (SInt32
*)&gid
);
162 CFDictionarySetValue(dict
, kSCPropUsersConsoleUserGID
, num
);
165 ok
= SCDynamicStoreSetValue(mySession
, key
, dict
);
169 if (dict
) CFRelease(dict
);
170 if (key
) CFRelease(key
);
171 if (!store
&& mySession
) CFRelease(mySession
);