nm: Pass back the username auth-dialog runs as to access ssh-agent socket
This ensures we access the socket as user who NM ran the auth-dialog for, especially for system-wide connections where the connection does not mention a user. We also make sure we don't use the cached socket and user of a previous connection attempt, because system-wide connections might be used by different users.
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include <glib/gi18n.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <libsecret/secret.h>
|
||||
#include <pwd.h>
|
||||
|
||||
#include <NetworkManager.h>
|
||||
#include <nm-vpn-service-plugin.h>
|
||||
@@ -217,6 +218,11 @@ static void print_secret (const char *secret_name, gchar *secret)
|
||||
printf("%s\n%s\n", secret_name, secret);
|
||||
g_free(secret);
|
||||
}
|
||||
}
|
||||
|
||||
static void print_last_secret (const char *secret_name, gchar *secret)
|
||||
{
|
||||
print_secret(secret_name, secret);
|
||||
printf("\n\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
@@ -316,6 +322,17 @@ int main (int argc, char *argv[])
|
||||
agent = getenv("SSH_AUTH_SOCK");
|
||||
if (agent)
|
||||
{
|
||||
int uid = getuid();
|
||||
struct passwd *pw = getpwuid(uid);
|
||||
|
||||
if (!pw)
|
||||
{
|
||||
fprintf(stderr, "Unable to determine username for "
|
||||
"authentication via ssh-agent\n");
|
||||
status = 1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (external_ui_mode)
|
||||
{
|
||||
GKeyFile *keyfile;
|
||||
@@ -326,6 +343,7 @@ int main (int argc, char *argv[])
|
||||
g_key_file_set_string (keyfile, UI_KEYFILE_GROUP, "Description", "SSH agent");
|
||||
g_key_file_set_string (keyfile, UI_KEYFILE_GROUP, "Title", _("Authenticate VPN"));
|
||||
|
||||
keyfile_add_entry_info (keyfile, "agent-user", pw->pw_name, "SSH agent user", TRUE, FALSE);
|
||||
keyfile_add_entry_info (keyfile, "agent", agent, "SSH agent socket", TRUE, FALSE);
|
||||
|
||||
keyfile_print_stdout (keyfile);
|
||||
@@ -333,7 +351,8 @@ int main (int argc, char *argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
print_secret("agent", g_strdup (agent));
|
||||
print_secret("agent-user", g_strdup (pw->pw_name));
|
||||
print_last_secret("agent", g_strdup (agent));
|
||||
wait_for_quit ();
|
||||
}
|
||||
}
|
||||
@@ -366,7 +385,7 @@ int main (int argc, char *argv[])
|
||||
}
|
||||
else if (!external_ui_mode)
|
||||
{
|
||||
print_secret("password", pass);
|
||||
print_last_secret("password", pass);
|
||||
wait_for_quit ();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user