libsecret not working with user account space for ubuntu2004

Bug #1915897 reported by avinash
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
GNOME Keyring
Fix Released
Unknown
gnome-keyring (Ubuntu)
Invalid
Low
Unassigned

Bug Description

I am using libsecret library and facing problem with ubuntu2004 gnome-keyring
I have written below cpp code

#include<libsecret/secret.h>
#include<iostream>
#include<time.h>
#defineSCHEMAgetSchema()
#defineCREDENTIALS_TOKEN_LABEL"ubuntu2004test"

constSecretSchema*getSchema(void)
{

staticconst SecretSchema schema = {
"org.example.credentials",
SECRET_SCHEMA_NONE,
{
{"username", SECRET_SCHEMA_ATTRIBUTE_STRING},
{NULL, (SecretSchemaAttributeType)0}}};

return &schema;
}

voidputCredentials(std::stringusername,std::stringpassword)
{
GError *error = NULL;
secret_password_store_sync(SCHEMA, SECRET_COLLECTION_DEFAULT, CREDENTIALS_TOKEN_LABEL, password.c_str(), NULL,
&error, "username",username.c_str(),NULL);
}
voiddeleteAllCredentials(){
std::cout<<"\nDeletting all credential....\n";
GError *error = NULL;
SecretService *sec = secret_service_get_sync(SECRET_SERVICE_LOAD_COLLECTIONS, NULL, &error);
_SecretCollection *collection = NULL;

collection = secret_collection_for_alias_sync(sec, SECRET_COLLECTION_DEFAULT,
SECRET_COLLECTION_LOAD_ITEMS, NULL, &error);
GList *items = secret_collection_get_items(collection);
for (unsignedinti = 0; i < g_list_length(items); i++)
{
SecretItem *item = (SecretItem *)g_list_nth_data(items, i);
std::stringlabel(secret_item_get_label(item));
if (label==CREDENTIALS_TOKEN_LABEL)
{
secret_item_delete_sync(item, NULL, &error);
if (error != NULL)
{
std::cout<<"Error: Cannot delete item:"<<error->message;
}
}
g_object_unref(item);
}
g_list_free(items);
std::cout<<"...All credentials deleted...";
}

intmain()
{
std::cout<<"Adding tokens";
std::cout<<"\nEnter new username or type exit :";
std::stringusername[] = {"user1", "user2", "user3", "user4", "user5", "user6"};
std::stringpassword[] = {"pass1", "pass2", "pass3", "pass4", "pass5", "pass6"};

for (inti = 0; i < 6; i++)
{
std::cout<<"Adding credentials....\n";
std::cout<<username[i]<<std::endl;
std::cout<<password[i]<<std::endl;
putCredentials(username[i], password[i]);
sleep(3);
}
deleteAllCredentials();
return0;
}

And I compile it using
g++ ubuntu2004-libsecret.cpp -o test `pkg-config --cflags --libs glib-2.0 libsecret-1`

I have below shell script
#!/bin/bash
location="/home/avinash/Documents/training/"
EXE_CMD=$location"test"
echo$EXE_CMD
if [ `whoami` = "root" ]
then
echo"adding in user account: "`logname`
runuser -l `logname` -c "$EXE_CMD 2>/dev/null"
else
$EXE_CMD 2>/dev/null

fi

I get below results "sh ./
Ubuntu 1804: users added and removed in user account ,with and without sudo
Ubuntu 2004: users added and removed in user account only without sudo, sudo run does not add and remove credentials to user account here.

Any help for ubuntu2004 will be appreciated.

Revision history for this message
avinash (avinashkh) wrote :
Revision history for this message
Sebastien Bacher (seb128) wrote :

Thank you for your bug report, it's likely an upstream issue though so it would be best if you could also report it to the upstream code writers on https://gitlab.gnome.org/GNOME/libsecret/-/issues

Changed in gnome-keyring (Ubuntu):
importance: Undecided → Low
Revision history for this message
avinash (avinashkh) wrote :

Thanks, below is the upstream logged issue.
https://gitlab.gnome.org/GNOME/libsecret/-/issues/57

Revision history for this message
Sebastien Bacher (seb128) wrote :

Thanks! (you might want to edit the description on gitlab and click the 'source' formatting for the code examples)

Changed in gnome-keyring (Ubuntu):
status: New → Triaged
Changed in gnome-keyring:
status: Unknown → Fix Released
Revision history for this message
Sebastien Bacher (seb128) wrote :

upstream closed with this note

'That's to be expected. The D-Bus socket for the session bus is located in $XDG_RUNTIME_DIR, which is user-specific. When you use sudo, the command that is started by it doesn't have the $XDG_RUNTIME_DIR envvar set (or anything related to the current session basically), so it can't do anything with it.
See also https://unix.stackexchange.com/questions/346841/why-does-sudo-i-not-set-xdg-runtime-dir-for-the-target-user . The fact that this once used to work, is also explained there.
Closing this as this is really not a bug, let alone one of libsecret'

Changed in gnome-keyring (Ubuntu):
status: Triaged → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.