summaryrefslogtreecommitdiff
path: root/unix-socket.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2011-12-10 10:34:14 (GMT)
committerJunio C Hamano <gitster@pobox.com>2011-12-12 07:16:25 (GMT)
commite2770979fec968a25ac21e34f9082bc17a71a780 (patch)
tree5ae5a950fec8c52cab6a0ee21f48d0912bafcafd /unix-socket.c
parenta6fc9fd3f4b42cd97b5262026e18bd451c28ee3c (diff)
downloadgit-e2770979fec968a25ac21e34f9082bc17a71a780.zip
git-e2770979fec968a25ac21e34f9082bc17a71a780.tar.gz
git-e2770979fec968a25ac21e34f9082bc17a71a780.tar.bz2
credentials: add "cache" helper
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>
Diffstat (limited to 'unix-socket.c')
-rw-r--r--unix-socket.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/unix-socket.c b/unix-socket.c
new file mode 100644
index 0000000..84b1509
--- /dev/null
+++ b/unix-socket.c
@@ -0,0 +1,56 @@
+#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;
+}