e2770979fe
If you access repositories over smart-http using http authentication, then it can be annoying to have git ask you for your password repeatedly. We cache credentials in memory, of course, but git is composed of many small programs. Having to input your password for each one can be frustrating. This patch introduces a credential helper that will cache passwords in memory for a short period of time. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
57 lines
1.0 KiB
C
57 lines
1.0 KiB
C
#include "cache.h"
|
|
#include "unix-socket.h"
|
|
|
|
static int unix_stream_socket(void)
|
|
{
|
|
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
if (fd < 0)
|
|
die_errno("unable to create socket");
|
|
return fd;
|
|
}
|
|
|
|
static void unix_sockaddr_init(struct sockaddr_un *sa, const char *path)
|
|
{
|
|
int size = strlen(path) + 1;
|
|
if (size > sizeof(sa->sun_path))
|
|
die("socket path is too long to fit in sockaddr");
|
|
memset(sa, 0, sizeof(*sa));
|
|
sa->sun_family = AF_UNIX;
|
|
memcpy(sa->sun_path, path, size);
|
|
}
|
|
|
|
int unix_stream_connect(const char *path)
|
|
{
|
|
int fd;
|
|
struct sockaddr_un sa;
|
|
|
|
unix_sockaddr_init(&sa, path);
|
|
fd = unix_stream_socket();
|
|
if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
|
|
close(fd);
|
|
return -1;
|
|
}
|
|
return fd;
|
|
}
|
|
|
|
int unix_stream_listen(const char *path)
|
|
{
|
|
int fd;
|
|
struct sockaddr_un sa;
|
|
|
|
unix_sockaddr_init(&sa, path);
|
|
fd = unix_stream_socket();
|
|
|
|
unlink(path);
|
|
if (bind(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
|
|
close(fd);
|
|
return -1;
|
|
}
|
|
|
|
if (listen(fd, 5) < 0) {
|
|
close(fd);
|
|
return -1;
|
|
}
|
|
|
|
return fd;
|
|
}
|