2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
24 #include <CoreFoundation/CFPreferences.h>
27 // Construct the preferences object and read the current preference settings.
30 : mPluginFolders(NULL
)
32 if (!readPathFromPrefs() && !readPathFromEnv())
36 // Destroy the preferences object.
41 CFRelease(mPluginFolders
);
44 // Obtain the plugin path from a preferences file. Returns true on success of false
45 // if no prefs could be found.
48 MDSPrefs::readPathFromPrefs()
50 static const CFStringRef kPrefsSuite
= CFSTR("com.apple.mds");
51 static const CFStringRef kPluginPathKey
= CFSTR("securityPluginPath");
55 CFPreferencesAddSuitePreferencesToApp(kCFPreferencesCurrentApplication
, kPrefsSuite
);
57 CFPropertyListRef value
;
58 value
= CFPreferencesCopyAppValue(kPluginPathKey
, kCFPreferencesCurrentApplication
);
60 if (CFGetTypeID(value
) != CFArrayGetTypeID())
61 // the prefs object is not an array, so fail
65 // make sure that all array elements are strings
67 CFArrayRef array
= (CFArrayRef
) value
;
68 int numItems
= CFArrayGetCount(array
);
69 for (int i
= 0; i
< numItems
; i
++)
70 if (CFGetTypeID(CFArrayGetValueAtIndex(array
, i
)) != CFStringGetTypeID()) {
77 mPluginFolders
= (CFArrayRef
) value
;
85 MDSPrefs::readPathFromEnv()
87 static const char *kPluginPathEnv
= "MDSPATH";
88 static const CFStringRef kSeparator
= CFSTR(":");
90 char *envValue
= getenv(kPluginPathEnv
);
92 CFStringRef path
= CFStringCreateWithCString(NULL
, envValue
, kCFStringEncodingUTF8
);
94 mPluginFolders
= CFStringCreateArrayBySeparatingStrings(NULL
, path
, kSeparator
);
104 MDSPrefs::useDefaultPath()
106 static const CFStringRef kDefaultPluginPath
= CFSTR("/System/Library/Security");
108 mPluginFolders
= CFArrayCreate(NULL
, (const void **) &kDefaultPluginPath
, 1, &kCFTypeArrayCallBacks
);
111 // Retrieve the elements of the plugin path.
114 MDSPrefs::getNumberOfPluginFolders() const
117 return CFArrayGetCount(mPluginFolders
);
123 MDSPrefs::getPluginFolder(int index
)
125 if (mPluginFolders
) {
126 int numValues
= CFArrayGetCount(mPluginFolders
);
127 if (index
>= 0 && index
< numValues
) {
128 CFStringRef value
= (CFStringRef
) CFArrayGetValueAtIndex(mPluginFolders
, index
);
130 // we have to copy the string since it may be using a different native
131 // encoding than the one we want. the copy is put in a temporary buffer,
132 // so its lifetime is limited to the next call to getPluginFolder() or to
133 // the destruction of the MDSPrefs object. Very long paths will silently fail.
135 if (CFStringGetCString(value
, mTempBuffer
, kTempBufferSize
, kCFStringEncodingUTF8
))