@@ -56,7 +56,20 @@ static SecretService* secretservice;
5656static SecretCollection * defaultcollection ;
5757#endif
5858
59- static void remmina_plugin_glibsecret_unlock_secret_service ()
59+
60+ gboolean remmina_plugin_glibsecret_is_service_available ()
61+ {
62+ #ifdef LIBSECRET_VERSION_0_18
63+ if (secretservice && defaultcollection )
64+ return TRUE;
65+ else
66+ return FALSE;
67+ #else
68+ return FALSE;
69+ #endif
70+ }
71+
72+ static void remmina_plugin_glibsecret_unlock_secret_service ()
6073{
6174 TRACE_CALL (__func__ );
6275
@@ -87,8 +100,6 @@ void remmina_plugin_glibsecret_store_password(RemminaFile *remminafile, const gc
87100 const gchar * path ;
88101 gchar * s ;
89102
90- remmina_plugin_glibsecret_unlock_secret_service ();
91-
92103 path = remmina_plugin_service -> file_get_path (remminafile );
93104 s = g_strdup_printf ("Remmina: %s - %s" , remmina_plugin_service -> file_get_string (remminafile , "name" ), key );
94105 secret_password_store_sync (& remmina_file_secret_schema , SECRET_COLLECTION_DEFAULT , s , password ,
@@ -111,8 +122,6 @@ remmina_plugin_glibsecret_get_password(RemminaFile *remminafile, const gchar *ke
111122 gchar * password ;
112123 gchar * p ;
113124
114- remmina_plugin_glibsecret_unlock_secret_service ();
115-
116125 path = remmina_plugin_service -> file_get_path (remminafile );
117126 password = secret_password_lookup_sync (& remmina_file_secret_schema , NULL , & r , "filename" , path , "key" , key , NULL );
118127 if (r == NULL ) {
@@ -132,8 +141,6 @@ void remmina_plugin_glibsecret_delete_password(RemminaFile *remminafile, const g
132141 GError * r = NULL ;
133142 const gchar * path ;
134143
135- remmina_plugin_glibsecret_unlock_secret_service ();
136-
137144 path = remmina_plugin_service -> file_get_path (remminafile );
138145 secret_password_clear_sync (& remmina_file_secret_schema , NULL , & r , "filename" , path , "key" , key , NULL );
139146 if (r == NULL ) {
@@ -144,9 +151,17 @@ void remmina_plugin_glibsecret_delete_password(RemminaFile *remminafile, const g
144151}
145152
146153static RemminaSecretPlugin remmina_plugin_glibsecret =
147- { REMMINA_PLUGIN_TYPE_SECRET , "glibsecret" , "GNOME libsecret" , NULL , VERSION ,
148-
149- TRUE, remmina_plugin_glibsecret_store_password , remmina_plugin_glibsecret_get_password , remmina_plugin_glibsecret_delete_password };
154+ { REMMINA_PLUGIN_TYPE_SECRET ,
155+ "glibsecret" ,
156+ "GNOME libsecret" ,
157+ NULL ,
158+ VERSION ,
159+ TRUE,
160+ remmina_plugin_glibsecret_store_password ,
161+ remmina_plugin_glibsecret_get_password ,
162+ remmina_plugin_glibsecret_delete_password ,
163+ remmina_plugin_glibsecret_is_service_available
164+ };
150165
151166G_MODULE_EXPORT gboolean
152167remmina_plugin_entry (RemminaPluginService * service )
@@ -164,17 +179,27 @@ remmina_plugin_entry(RemminaPluginService *service)
164179 error = NULL ;
165180 secretservice = secret_service_get_sync (SECRET_SERVICE_LOAD_COLLECTIONS , NULL , & error );
166181 if (error ) {
167- remmina_plugin_service -> log_printf ("[glibsecret] unable to get secret service: %s\n" , error -> message );
182+ g_print ("[glibsecret] unable to get secret service: %s\n" , error -> message );
183+ return FALSE;
184+ }
185+ if (secretservice == NULL ) {
186+ g_print ("[glibsecret] unable to get secret service: Unknown error.\n" );
168187 return FALSE;
169188 }
170189
171190 defaultcollection = secret_collection_for_alias_sync (secretservice , SECRET_COLLECTION_DEFAULT , SECRET_COLLECTION_NONE , NULL , & error );
172191 if (error ) {
173- remmina_plugin_service -> log_printf ("[glibsecret] unable to get secret service default collection: %s\n" , error -> message );
192+ g_print ("[glibsecret] unable to get secret service default collection: %s\n" , error -> message );
174193 return FALSE;
175194 }
176- #endif
177195
196+ remmina_plugin_glibsecret_unlock_secret_service ();
178197 return TRUE;
198+
199+ #else
200+ g_print ("Libsecret was too old during compilation, disabling secret service.\n" );
201+ return FALSE;
202+ #endif
203+
179204}
180205
0 commit comments