15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/mac/security_wrappers.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
71320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include <Security/Security.h>
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
91320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/mac/mac_logging.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace chrome {
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ScopedSecKeychainSetUserInteractionAllowed::
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ScopedSecKeychainSetUserInteractionAllowed(Boolean allowed) {
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  OSStatus status = SecKeychainGetUserInteractionAllowed(&old_allowed_);
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (status != errSecSuccess) {
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    OSSTATUS_LOG(ERROR, status);
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    old_allowed_ = TRUE;
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  status = SecKeychainSetUserInteractionAllowed(allowed);
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (status != errSecSuccess) {
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    OSSTATUS_LOG(ERROR, status);
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ScopedSecKeychainSetUserInteractionAllowed::
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ~ScopedSecKeychainSetUserInteractionAllowed() {
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  OSStatus status = SecKeychainSetUserInteractionAllowed(old_allowed_);
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (status != errSecSuccess) {
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    OSSTATUS_LOG(ERROR, status);
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace chrome
36