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 "security_tool.h"
27 #include "user_trust_enable.h"
30 #include <security_utilities/simpleprefs.h>
31 #include <Security/TrustSettingsSchema.h> /* private SPI */
32 #include <CoreFoundation/CFNumber.h>
40 user_trust_enable(int argc
, char * const *argv
)
44 UserTrustOp op
= utoShow
;
45 CFBooleanRef disabledBool
= kCFBooleanFalse
; /* what we write to prefs */
49 while ((arg
= getopt(argc
, argv
, "deh")) != -1) {
53 disabledBool
= kCFBooleanTrue
;
57 disabledBool
= kCFBooleanFalse
;
61 return SHOW_USAGE_MESSAGE
;
65 return SHOW_USAGE_MESSAGE
;
69 bool utDisable
= false;
71 #if !defined MAC_OS_X_VERSION_10_6 || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
72 Dictionary
* prefsDict
= new Dictionary(kSecTrustSettingsPrefsDomain
, Dictionary::US_System
);
74 Dictionary
* prefsDict
= Dictionary::CreateDictionary(kSecTrustSettingsPrefsDomain
, Dictionary::US_System
);
76 if (prefsDict
!= NULL
)
78 utDisable
= prefsDict
->getBoolValue(kSecTrustSettingsDisableUserTrustSettings
);
82 fprintf(stdout
, "User-level Trust Settings are %s\n",
83 utDisable
? "Disabled" : "Enabled");
89 fprintf(stderr
, "You must be root to set this preference.\n");
93 /* get a mutable copy of the existing prefs, or a fresh empty one */
94 #if !defined MAC_OS_X_VERSION_10_6 || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
95 MutableDictionary
*prefsDict
= new MutableDictionary(kSecTrustSettingsPrefsDomain
, Dictionary::US_System
);
97 MutableDictionary
*prefsDict
= MutableDictionary::CreateMutableDictionary(kSecTrustSettingsPrefsDomain
, Dictionary::US_System
);
99 if (prefsDict
== NULL
)
101 prefsDict
= new MutableDictionary();
104 prefsDict
->setValue(kSecTrustSettingsDisableUserTrustSettings
, disabledBool
);
105 if(prefsDict
->writePlistToPrefs(kSecTrustSettingsPrefsDomain
, Dictionary::US_System
)) {
106 fprintf(stdout
, "...User-level Trust Settings are %s\n",
107 (disabledBool
== kCFBooleanTrue
) ? "Disabled" : "Enabled");
110 fprintf(stderr
, "Could not write system preferences.\n");