Bug 1931419 - use preexisting unique pointer support for GError in LibSecret r=jschanck
Differential Revision: https://phabricator.services.mozilla.com/D229054
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "mozilla/Base64.h"
|
#include "mozilla/Base64.h"
|
||||||
|
#include "mozilla/GUniquePtr.h"
|
||||||
#include "mozilla/Logging.h"
|
#include "mozilla/Logging.h"
|
||||||
#include "MainThreadUtils.h"
|
#include "MainThreadUtils.h"
|
||||||
#include "prlink.h"
|
#include "prlink.h"
|
||||||
@@ -124,9 +125,6 @@ nsresult MaybeLoadLibSecret() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct ScopedDelete {
|
struct ScopedDelete {
|
||||||
void operator()(GError* error) {
|
|
||||||
if (error) g_error_free(error);
|
|
||||||
}
|
|
||||||
void operator()(char* val) {
|
void operator()(char* val) {
|
||||||
if (val) secret_password_free(val);
|
if (val) secret_password_free(val);
|
||||||
}
|
}
|
||||||
@@ -142,7 +140,6 @@ struct ScopedMaybeDelete {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::unique_ptr<GError, ScopedMaybeDelete<GError>> ScopedGError;
|
|
||||||
typedef std::unique_ptr<char, ScopedMaybeDelete<char>> ScopedPassword;
|
typedef std::unique_ptr<char, ScopedMaybeDelete<char>> ScopedPassword;
|
||||||
|
|
||||||
LibSecret::LibSecret() = default;
|
LibSecret::LibSecret() = default;
|
||||||
@@ -183,14 +180,14 @@ nsresult LibSecret::StoreSecret(const nsACString& aSecret,
|
|||||||
MOZ_LOG(gLibSecretLog, LogLevel::Debug, ("Error base64-encoding secret"));
|
MOZ_LOG(gLibSecretLog, LogLevel::Debug, ("Error base64-encoding secret"));
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
GError* raw_error = nullptr;
|
GUniquePtr<GError> error;
|
||||||
bool stored = secret_password_store_sync(
|
bool stored = secret_password_store_sync(
|
||||||
&kSchema, SECRET_COLLECTION_DEFAULT, PromiseFlatCString(aLabel).get(),
|
&kSchema, SECRET_COLLECTION_DEFAULT, PromiseFlatCString(aLabel).get(),
|
||||||
PromiseFlatCString(base64).get(),
|
PromiseFlatCString(base64).get(),
|
||||||
nullptr, // GCancellable
|
nullptr, // GCancellable
|
||||||
&raw_error, "string", PromiseFlatCString(aLabel).get(), nullptr);
|
getter_Transfers(error), "string", PromiseFlatCString(aLabel).get(),
|
||||||
ScopedGError error(raw_error);
|
nullptr);
|
||||||
if (raw_error) {
|
if (error) {
|
||||||
MOZ_LOG(gLibSecretLog, LogLevel::Debug, ("Error storing secret"));
|
MOZ_LOG(gLibSecretLog, LogLevel::Debug, ("Error storing secret"));
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
@@ -203,14 +200,14 @@ nsresult LibSecret::DeleteSecret(const nsACString& aLabel) {
|
|||||||
if (!secret_password_clear_sync || !secret_error_get_quark) {
|
if (!secret_password_clear_sync || !secret_error_get_quark) {
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
GError* raw_error = nullptr;
|
GUniquePtr<GError> error;
|
||||||
Unused << secret_password_clear_sync(
|
Unused << secret_password_clear_sync(&kSchema,
|
||||||
&kSchema,
|
nullptr, // GCancellable
|
||||||
nullptr, // GCancellable
|
getter_Transfers(error), "string",
|
||||||
&raw_error, "string", PromiseFlatCString(aLabel).get(), nullptr);
|
PromiseFlatCString(aLabel).get(),
|
||||||
ScopedGError error(raw_error);
|
nullptr);
|
||||||
if (raw_error && !(raw_error->domain == secret_error_get_quark() &&
|
if (error && !(error->domain == secret_error_get_quark() &&
|
||||||
raw_error->code == SECRET_ERROR_NO_SUCH_OBJECT)) {
|
error->code == SECRET_ERROR_NO_SUCH_OBJECT)) {
|
||||||
MOZ_LOG(gLibSecretLog, LogLevel::Debug, ("Error deleting secret"));
|
MOZ_LOG(gLibSecretLog, LogLevel::Debug, ("Error deleting secret"));
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
@@ -224,14 +221,14 @@ nsresult LibSecret::RetrieveSecret(const nsACString& aLabel,
|
|||||||
if (!secret_password_lookup_sync || !secret_password_free) {
|
if (!secret_password_lookup_sync || !secret_password_free) {
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
GError* raw_error = nullptr;
|
GUniquePtr<GError> error;
|
||||||
aSecret.Truncate();
|
aSecret.Truncate();
|
||||||
ScopedPassword s(secret_password_lookup_sync(
|
ScopedPassword s(
|
||||||
&kSchema,
|
secret_password_lookup_sync(&kSchema,
|
||||||
nullptr, // GCancellable
|
nullptr, // GCancellable
|
||||||
&raw_error, "string", PromiseFlatCString(aLabel).get(), nullptr));
|
getter_Transfers(error), "string",
|
||||||
ScopedGError error(raw_error);
|
PromiseFlatCString(aLabel).get(), nullptr));
|
||||||
if (raw_error || !s) {
|
if (error || !s) {
|
||||||
MOZ_LOG(gLibSecretLog, LogLevel::Debug,
|
MOZ_LOG(gLibSecretLog, LogLevel::Debug,
|
||||||
("Error retrieving secret or didn't find it"));
|
("Error retrieving secret or didn't find it"));
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
|
|||||||
@@ -167,6 +167,8 @@ if CONFIG["MOZ_WIDGET_TOOLKIT"] == "gtk":
|
|||||||
]
|
]
|
||||||
CFLAGS += CONFIG["GLIB_CFLAGS"]
|
CFLAGS += CONFIG["GLIB_CFLAGS"]
|
||||||
CXXFLAGS += CONFIG["GLIB_CFLAGS"]
|
CXXFLAGS += CONFIG["GLIB_CFLAGS"]
|
||||||
|
CFLAGS += CONFIG["MOZ_GTK3_CFLAGS"]
|
||||||
|
CXXFLAGS += CONFIG["MOZ_GTK3_CFLAGS"]
|
||||||
|
|
||||||
if CONFIG["TARGET_KERNEL"] == "Darwin":
|
if CONFIG["TARGET_KERNEL"] == "Darwin":
|
||||||
UNIFIED_SOURCES += [
|
UNIFIED_SOURCES += [
|
||||||
|
|||||||
Reference in New Issue
Block a user