Add support for sockets in /run used by recent gpg-agent
* subversion/libsvn_subr/gpg_agent.c (find_running_gpg_agent): Check for socket presence in /run/user/UID/gnupg and /var/run/user/UID/gnupg in addition to ~/.gnupg
Index: subversion/libsvn_subr/gpg_agent.c =================================================================== *** subversion/libsvn_subr/gpg_agent.c (revision 1792920) --- subversion/libsvn_subr/gpg_agent.c (working copy) *************** *** 62,70 **** --- 62,73 ---- #include <unistd.h> #include <sys/socket.h> + #include <sys/stat.h> #include <sys/un.h> #include <apr_pools.h> + #include <apr_user.h> + #include <apr_strings.h> #include "svn_auth.h" #include "svn_config.h" #include "svn_error.h" *************** find_running_gpg_agent(int *new_sd, apr_ *** 266,278 **** } else { const char *homedir = svn_user_get_homedir(pool); ! ! if (!homedir) ! return SVN_NO_ERROR; ! ! socket_name = svn_dirent_join_many(pool, homedir, ".gnupg", ! "S.gpg-agent", SVN_VA_NULL); } if (socket_name != NULL) --- 269,309 ---- } else { + int isockmax = 0; + const char* socketpaths[3] = {0,0,0}; + /* GnuPG since 2.1.13 uses /run/user/UID/gnupg based sockets */ + apr_uid_t uid; + apr_gid_t gid; + if(apr_uid_current(&uid, &gid, pool) == APR_SUCCESS) { + char* uidbuf = apr_psprintf(pool, "%lu", (unsigned long)uid); + socketpaths[isockmax++] = svn_dirent_join_many(pool, "/run/user", + uidbuf, "gnupg", + "S.gpg-agent", + SVN_VA_NULL); + socketpaths[isockmax++] = svn_dirent_join_many(pool, "/var/run/user", + uidbuf, "gnupg", + "S.gpg-agent", + SVN_VA_NULL); + } + /* older GnuPG versions use /home/USER/.gnupg based sockets */ const char *homedir = svn_user_get_homedir(pool); ! if(homedir) { ! socketpaths[isockmax++] = svn_dirent_join_many(pool, homedir, ! ".gnupg", ! "S.gpg-agent", ! SVN_VA_NULL); ! } ! ! /* find which of the available socket paths actually exists */ ! int isock = 0; ! for (isock = 0; isock < isockmax; isock++) { ! struct stat statbuf; ! stat(socketpaths[isock], &statbuf); ! if(S_ISSOCK(statbuf.st_mode)) { ! socket_name = socketpaths[isock]; ! break; ! } ! } } if (socket_name != NULL)