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 * November 9, 2000 Allan Nathanson <ajn@apple.com>
33 #include <SystemConfiguration/SystemConfiguration.h>
34 #include <SystemConfiguration/SCPrivate.h>
35 #include "SCPreferencesInternal.h"
40 #include <sys/errno.h>
41 #include <sys/param.h>
43 __private_extern__ CFDataRef
44 __SCPSignatureFromStatbuf(const struct stat
*statBuf
)
46 CFMutableDataRef signature
;
47 SCPSignatureDataRef sig
;
49 signature
= CFDataCreateMutable(NULL
, sizeof(SCPSignatureData
));
50 CFDataSetLength(signature
, sizeof(SCPSignatureData
));
51 sig
= (SCPSignatureDataRef
)CFDataGetBytePtr(signature
);
52 sig
->st_dev
= statBuf
->st_dev
;
53 sig
->st_ino
= statBuf
->st_ino
;
54 sig
->st_mtimespec
= statBuf
->st_mtimespec
;
55 sig
->st_size
= statBuf
->st_size
;
60 __private_extern__
char *
61 __SCPreferencesPath(CFAllocatorRef allocator
,
66 CFStringRef path
= NULL
;
71 if (prefsID
== NULL
) {
72 /* no user prefsID specified */
74 } else if (CFStringHasPrefix(prefsID
, CFSTR("/"))) {
75 /* if absolute path */
76 path
= CFRetain(prefsID
);
79 * relative (to the user's preferences) path
81 char login
[MAXLOGNAME
+1];
84 bzero(&login
, sizeof(login
));
88 /* get current console user */
89 u
= SCDynamicStoreCopyConsoleUser(NULL
, NULL
, NULL
);
91 /* if could not get console user */
94 (void) CFStringGetBytes(u
,
95 CFRangeMake(0, CFStringGetLength(u
)),
96 kCFStringEncodingMacRoman
,
104 /* use specified user */
105 (void) CFStringGetBytes(user
,
106 CFRangeMake(0, CFStringGetLength(user
)),
107 kCFStringEncodingMacRoman
,
115 /* get password entry for user */
116 pwd
= getpwnam(login
);
118 /* if no home directory */
122 /* create prefs ID */
123 path
= CFStringCreateWithFormat(allocator
,
127 PREFS_DEFAULT_USER_DIR
,
131 if (prefsID
== NULL
) {
132 /* default preference ID */
133 path
= CFStringCreateWithFormat(allocator
,
137 PREFS_DEFAULT_CONFIG
);
138 } else if (CFStringHasPrefix(prefsID
, CFSTR("/"))) {
139 /* if absolute path */
140 path
= CFRetain(prefsID
);
143 path
= CFStringCreateWithFormat(allocator
,
152 * convert CFStringRef path to C-string path
154 pathLen
= CFStringGetLength(path
) + 1;
155 pathStr
= CFAllocatorAllocate(allocator
, pathLen
, 0);
156 if (!CFStringGetCString(path
,
159 kCFStringEncodingMacRoman
)) {
160 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("could not convert path to C string"));
161 CFAllocatorDeallocate(allocator
, pathStr
);
171 SCPreferencesGetSignature(SCPreferencesRef session
)
173 SCPreferencesPrivateRef sessionPrivate
= (SCPreferencesPrivateRef
)session
;
175 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("SCPreferencesGetSignature:"));
177 sessionPrivate
->accessed
= TRUE
;
178 return sessionPrivate
->signature
;
182 __private_extern__ CFStringRef
183 _SCPNotificationKey(CFAllocatorRef allocator
,
189 CFStringRef key
= NULL
;
193 pathStr
= __SCPreferencesPath(allocator
, prefsID
, perUser
, user
);
194 if (pathStr
== NULL
) {
198 /* create notification key */
200 case kSCPreferencesKeyLock
:
203 case kSCPreferencesKeyCommit
:
206 case kSCPreferencesKeyApply
:
213 key
= CFStringCreateWithFormat(allocator
,
216 kSCDynamicStoreDomainPrefs
,
220 CFAllocatorDeallocate(allocator
, pathStr
);
226 SCDynamicStoreKeyCreatePreferences(CFAllocatorRef allocator
,
230 return _SCPNotificationKey(allocator
, prefsID
, FALSE
, NULL
, keyType
);
235 SCDynamicStoreKeyCreateUserPreferences(CFAllocatorRef allocator
,
240 return _SCPNotificationKey(allocator
, prefsID
, TRUE
, user
, keyType
);