Currently using the command line gkey-lock/gkey-unlock with the flowing code to lock and unlock gnome default keyring, How can we implement gnome_keyring_info_get_is_locked()
from <gnome-keyring.h>
to check the locking state in c or python
Lock Keyring - gkey-lock.c
#include <stdio.h>
#include <gnome-keyring.h>
int main() {
GnomeKeyringResult lock_result = gnome_keyring_lock_all_sync();
if (lock_result == GNOME_KEYRING_RESULT_OK) {
printf("Successfully locked\n");
return 0;
} else {
printf("Error locking keyring: %d\n", lock_result);
return 1;
}
}
Unlock Keyring - gkey-unlock.c
#include <stdio.h>
#include <gnome-keyring.h>
int main() {
GnomeKeyringResult lock_result = gnome_keyring_unlock_sync(NULL,NULL);
if (lock_result == GNOME_KEYRING_RESULT_OK) {
printf("Successfully unlocked\n");
return 0;
} else {
printf("Error unlocking keyring: %d\n", lock_result);
return 1;
}
}
Gnome Keyring Command Line Tools (check/lock/unlock)
Sources & Release : https://github.com/intika/gnome-keyring-tools
Check Keyring - gkey-check.c
#include <stdio.h>
#include <gnome-keyring.h>
int main() {
GnomeKeyringInfo *info;
GnomeKeyringResult gkr;
gkr = gnome_keyring_get_info_sync(NULL, &info);
if (gkr != GNOME_KEYRING_RESULT_OK) {
printf("error\n");
return -1;
}
if (gnome_keyring_info_get_is_locked(info)) {
printf("locked\n");
return 0;
}
else {
printf("unlocked\n");
return -1;
}
gnome_keyring_info_free(info);
}
Check With Python - gkey-check.py
import gnomekeyring
print gnomekeyring.get_info_sync(gnomekeyring.get_default_keyring_sync()).get_is_locked()
How to build
cc gkey-check.c -o gkey-check -Wall -I/usr/include/gnome-keyring-1 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -lgnome-keyring -lglib-2.0