Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
pwstorage.c
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2010 Henrik Andersson.
4 Copyright (C) 2010-2011 johannes hanika.
5 Copyright (C) 2010, 2012-2014, 2016 Tobias Ellinghaus.
6 Copyright (C) 2012, 2014 Moritz Lipp.
7 Copyright (C) 2012 Richard Wonka.
8 Copyright (C) 2014 Pascal de Bruijn.
9 Copyright (C) 2020 wpferguson.
10 Copyright (C) 2021 Ralf Brown.
11 Copyright (C) 2022 Martin Baƙinka.
12
13 darktable is free software: you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 darktable is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with darktable. If not, see <http://www.gnu.org/licenses/>.
25*/
26
27// darktable is free software: you can redistribute it and/or modify
28// it under the terms of the GNU General Public License as published by
29// the Free Software Foundation, either version 3 of the License, or
30// (at your option) any later version.
31//
32// darktable is distributed in the hope that it will be useful,
33// but WITHOUT ANY WARRANTY; without even the implied warranty of
34// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35// GNU General Public License for more details.
36//
37// You should have received a copy of the GNU General Public License
38// along with darktable. If not, see <http://www.gnu.org/licenses/>.
39
40#ifdef HAVE_CONFIG_H
41#include "config.h"
42#endif
43
44#include "pwstorage.h"
45
46#ifdef HAVE_LIBSECRET
47#include "backend_libsecret.h"
48#endif
49
50#ifdef HAVE_KWALLET
51#include "backend_kwallet.h"
52#endif
53
54#include "control/conf.h"
55#include "control/control.h"
56
57#include <glib.h>
58#include <string.h>
59
62{
63/* add password storage capabilities */
64#ifdef HAVE_LIBSECRET
65 dt_capabilities_add("libsecret");
66#endif
67#ifdef HAVE_KWALLET
68 dt_capabilities_add("kwallet");
69#endif
70
71 dt_pwstorage_t *pwstorage = g_malloc(sizeof(dt_pwstorage_t));
72 dt_print(DT_DEBUG_PWSTORAGE, "[pwstorage_new] Creating new context %p\n", pwstorage);
73
74 if(IS_NULL_PTR(pwstorage)) return NULL;
75
76 const char *_backend_str = dt_conf_get_string_const("plugins/pwstorage/pwstorage_backend");
77 gint _backend = PW_STORAGE_BACKEND_NONE;
78
79 if(strcmp(_backend_str, "auto") == 0)
80 {
81 const gchar *desktop = getenv("XDG_CURRENT_DESKTOP");
82 if(g_strcmp0(desktop, "KDE") == 0)
84 else if(g_strcmp0(desktop, "GNOME") == 0)
86 else if(g_strcmp0(desktop, "Unity") == 0)
88 else if(g_strcmp0(desktop, "XFCE") == 0)
90
91 dt_print(DT_DEBUG_PWSTORAGE, "[pwstorage_new] autodetected storage backend.\n");
92 }
93 else if(strcmp(_backend_str, "none") == 0)
94 _backend = PW_STORAGE_BACKEND_NONE;
95#ifdef HAVE_LIBSECRET
96 else if(strcmp(_backend_str, "libsecret") == 0)
98#endif
99#ifdef HAVE_KWALLET
100 else if(strcmp(_backend_str, "kwallet") == 0)
102#endif
103 else if(strcmp(_backend_str, "gnome keyring") == 0)
104 {
105 fprintf(stderr, "[pwstorage_new] GNOME Keyring backend is no longer supported.\n");
106 dt_control_log(_("GNOME Keyring backend is no longer supported. configure a different one"));
107 _backend = PW_STORAGE_BACKEND_NONE;
108 }
109
110 switch(_backend)
111 {
112 default:
113 dt_print(DT_DEBUG_PWSTORAGE, "[pwstorage_new] unknown storage backend. Using none.\n");
116 pwstorage->backend_context = NULL;
117 dt_print(DT_DEBUG_PWSTORAGE, "[pwstorage_new] no storage backend. not storing username/password. "
118 "please change in preferences, core tab.\n");
119 break;
121#ifdef HAVE_LIBSECRET
122 dt_print(DT_DEBUG_PWSTORAGE, "[pwstorage_new] using libsecret backend for username/password storage.\n");
123 pwstorage->backend_context = (void *)dt_pwstorage_libsecret_new();
124 if(IS_NULL_PTR(pwstorage->backend_context))
125 {
126 dt_print(DT_DEBUG_PWSTORAGE, "[pwstorage_new] error starting libsecret. using no storage backend.\n");
127 pwstorage->backend_context = NULL;
129 }
130 else
131 {
133 }
134 break;
135#else
137 "[pwstorage_new] libsecret backend not available. using no storage backend.\n");
138 pwstorage->backend_context = NULL;
140#endif
142#ifdef HAVE_KWALLET
143 dt_print(DT_DEBUG_PWSTORAGE, "[pwstorage_new] using kwallet backend for username/password storage.\n");
144 pwstorage->backend_context = (void *)dt_pwstorage_kwallet_new();
145 if(IS_NULL_PTR(pwstorage->backend_context))
146 {
147 dt_print(DT_DEBUG_PWSTORAGE, "[pwstorage_new] error starting kwallet. using no storage backend.\n");
148 pwstorage->backend_context = NULL;
150 }
151 else
152 {
154 }
155 dt_print(DT_DEBUG_PWSTORAGE, " done.\n");
156 break;
157#else
159 "[pwstorage_new] kwallet backend not available. using no storage backend.\n");
160 pwstorage->backend_context = NULL;
162#endif
163 }
164
165 switch(pwstorage->pw_storage_backend)
166 {
168 dt_conf_set_string("plugins/pwstorage/pwstorage_backend", "none");
169 break;
171 dt_conf_set_string("plugins/pwstorage/pwstorage_backend", "libsecret");
172 break;
174 dt_conf_set_string("plugins/pwstorage/pwstorage_backend", "kwallet");
175 break;
176 }
177
178 return pwstorage;
179}
180
183{
184 dt_print(DT_DEBUG_PWSTORAGE, "[pwstorage_new] Destroying context %p\n", pwstorage);
186 {
188 // nothing to be done
189 break;
191#ifdef HAVE_LIBSECRET
193#endif
194 break;
196#ifdef HAVE_KWALLET
198#endif
199 break;
200 }
201}
202
204gboolean dt_pwstorage_set(const gchar *slot, GHashTable *table)
205{
207 {
209 dt_print(DT_DEBUG_PWSTORAGE, "[pwstorage_set] no backend. not storing anything.\n");
210 break;
212#if HAVE_LIBSECRET
214 slot, table);
215#endif
216 break;
218#ifdef HAVE_KWALLET
220 table);
221#endif
222 break;
223 }
224 return FALSE;
225}
226
228GHashTable *dt_pwstorage_get(const gchar *slot)
229{
231 {
233 dt_print(DT_DEBUG_PWSTORAGE, "[pwstorage_get] no backend. not reading anything.\n");
234 break;
236#if HAVE_LIBSECRET
238 slot);
239#endif
240 break;
242#ifdef HAVE_KWALLET
244#endif
245 break;
246 }
247
248 return g_hash_table_new(g_str_hash, g_str_equal);
249}
250
251// clang-format off
252// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
253// vim: shiftwidth=2 expandtab tabstop=2 cindent
254// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
255// clang-format on
256
#define FALSE
Definition ashift_lsd.c:158
const backend_kwallet_context_t * dt_pwstorage_kwallet_new()
void dt_pwstorage_kwallet_destroy(const backend_kwallet_context_t *context)
GHashTable * dt_pwstorage_kwallet_get(const backend_kwallet_context_t *context, const gchar *slot)
gboolean dt_pwstorage_kwallet_set(const backend_kwallet_context_t *context, const gchar *slot, GHashTable *table)
gboolean dt_pwstorage_libsecret_set(const backend_libsecret_context_t *context, const gchar *slot, GHashTable *attributes)
const backend_libsecret_context_t * dt_pwstorage_libsecret_new()
GHashTable * dt_pwstorage_libsecret_get(const backend_libsecret_context_t *context, const gchar *slot)
void dt_pwstorage_libsecret_destroy(const backend_libsecret_context_t *context)
void dt_conf_set_string(const char *name, const char *val)
const char * dt_conf_get_string_const(const char *name)
void dt_control_log(const char *msg,...)
Definition control.c:761
darktable_t darktable
Definition darktable.c:181
void dt_capabilities_add(char *capability)
Definition darktable.c:1773
void dt_print(dt_debug_thread_t thread, const char *msg,...)
Definition darktable.c:1542
@ DT_DEBUG_PWSTORAGE
Definition darktable.h:721
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
Definition darktable.h:281
const dt_pwstorage_t * dt_pwstorage_new()
Definition pwstorage.c:61
GHashTable * dt_pwstorage_get(const gchar *slot)
Definition pwstorage.c:228
gboolean dt_pwstorage_set(const gchar *slot, GHashTable *table)
Definition pwstorage.c:204
void dt_pwstorage_destroy(const dt_pwstorage_t *pwstorage)
Definition pwstorage.c:182
@ PW_STORAGE_BACKEND_KWALLET
Definition pwstorage.h:43
@ PW_STORAGE_BACKEND_LIBSECRET
Definition pwstorage.h:44
@ PW_STORAGE_BACKEND_NONE
Definition pwstorage.h:42
const struct dt_pwstorage_t * pwstorage
Definition darktable.h:780
pw_storage_backend_t pw_storage_backend
Definition pwstorage.h:50
void * backend_context
Definition pwstorage.h:51