In article
<a324b77a-303c-4c44-8f7c-41bb459a0bd9@[EMAIL PROTECTED]
>,
p2 <pradip.patel@[EMAIL PROTECTED]
> wrote:
> Hi
>
> I wrote following code. Also, I have created com.p1.myapp.plist from
> admin user at /Library/Preferences and has 666 permission.
>
> SInt kColor = 5;
> const CFStringRef kAppName = CFSTR("com.p1.myapp");
> const CFStringRef kPrefColor = CFSTR("color");
> CFNumberRef value = CFNumberCreate(NULL, kCFNumberSInt8Type, &kColor);
>
> CFPreferencesSetValue( kPrefColor, value, kAppName,
> kCFPreferencesAnyUser, kCFPreferencesCurrentHost);
>
> CFPreferencesAppSynchronize(kAppName); // this will fail ,return
> false in Non- admin
>
> above code is working in Tiger Non-Admin but failed in Leopard Non-
> Admin
>
> Is there any change ?
> My target is to change preferences for Any user(/Library/Preferences/)
> from non-admin account , How can i achieve this ?
>
> p2
I think you're wrong about it working for a non-admin user in Tiger,
since:
a) It's do***ented that you can't save such changes: "Note that you can
only save preferences for łAny User˛ if you have Admin privileges."
b) I've been using that routine since (at least) 10.2 and it has behaved
as do***ented.
So I'd say either it's not saving or your 10.4 user *is* an admin
despite what you think.
Your options are:
a) Only save this change when running as an admin user; if the synch
fails, fall back to user-local storage.
b) Write someplace else, essentially recreating a ****tion of the
CFPreferences API.
c) Use some form of privilege escalation like a single-purpose setuid
tool running as root to save this setting.
I advocate course (a) unless it's critical that this value be identical
for all users. (b) and (c) both have shortcomings that are beyond the
scope of this message - the increased complexity in comparison to (a) is
probably the least of your worries.
--
"Harry?" Ron's voice was a mere whisper. "Do you smell something ...
burning?"
- Harry Potter and the Odor of the Phoenix


|