2 * Copyright (c) 2003-2004,2006,2008-2009,2012,2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 * user_trust_enable.cpp
26 #include "user_trust_enable.h"
29 #include <security_utilities/simpleprefs.h>
30 #include <Security/TrustSettingsSchema.h> /* private SPI */
31 #include <CoreFoundation/CFNumber.h>
39 user_trust_enable(int argc
, char * const *argv
)
43 UserTrustOp op
= utoShow
;
44 CFBooleanRef disabledBool
= kCFBooleanFalse
; /* what we write to prefs */
48 while ((arg
= getopt(argc
, argv
, "deh")) != -1) {
52 disabledBool
= kCFBooleanTrue
;
56 disabledBool
= kCFBooleanFalse
;
60 return 2; /* @@@ Return 2 triggers usage message. */
64 return 2; /* @@@ Return 2 triggers usage message. */
68 bool utDisable
= false;
70 #if !defined MAC_OS_X_VERSION_10_6 || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
71 Dictionary
* prefsDict
= new Dictionary(kSecTrustSettingsPrefsDomain
, Dictionary::US_System
);
73 Dictionary
* prefsDict
= Dictionary::CreateDictionary(kSecTrustSettingsPrefsDomain
, Dictionary::US_System
);
75 if (prefsDict
!= NULL
)
77 utDisable
= prefsDict
->getBoolValue(kSecTrustSettingsDisableUserTrustSettings
);
81 fprintf(stdout
, "User-level Trust Settings are %s\n",
82 utDisable
? "Disabled" : "Enabled");
88 fprintf(stderr
, "You must be root to set this preference.\n");
92 /* get a mutable copy of the existing prefs, or a fresh empty one */
93 #if !defined MAC_OS_X_VERSION_10_6 || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
94 MutableDictionary
*prefsDict
= new MutableDictionary(kSecTrustSettingsPrefsDomain
, Dictionary::US_System
);
96 MutableDictionary
*prefsDict
= MutableDictionary::CreateMutableDictionary(kSecTrustSettingsPrefsDomain
, Dictionary::US_System
);
98 if (prefsDict
== NULL
)
100 prefsDict
= new MutableDictionary();
103 prefsDict
->setValue(kSecTrustSettingsDisableUserTrustSettings
, disabledBool
);
104 if(prefsDict
->writePlistToPrefs(kSecTrustSettingsPrefsDomain
, Dictionary::US_System
)) {
105 fprintf(stdout
, "...User-level Trust Settings are %s\n",
106 (disabledBool
== kCFBooleanTrue
) ? "Disabled" : "Enabled");
109 fprintf(stderr
, "Could not write system preferences.\n");