shithub: tlsclient

Download patch

ref: c782ad22b6042e7157607a56b5e6c436d57330a7
parent: 7b6722df5d44de56329d2e4cfb0152c4397c945f
author: Jacob Moody <moody@posixcafe.org>
date: Tue Sep 14 02:46:48 EDT 2021

fix ipv6 dns lookups (thanks Matthias)

diff: cannot open b/.builds//null: file does not exist: 'b/.builds//null'
--- /dev/null
+++ b/.builds/obsd.yml
@@ -1,0 +1,9 @@
+image: openbsd/6.9
+sources:
+  - https://git.sr.ht/~moody/tlsclient
+artifacts:
+  - tlsclient/tlsclient-obsd.tar.gz
+tasks:
+  - build: |
+      cd tlsclient
+      make -j $(nproc) obsddist
--- /dev/null
+++ b/.builds/pam.yml
@@ -1,0 +1,9 @@
+image: archlinux
+sources:
+  - https://git.sr.ht/~moody/tlsclient
+artifacts:
+  - tlsclient/tlsclient.tar.gz
+tasks:
+  - build: | 
+      cd tlsclient
+      make -j $(nproc) linuxdist
--- a/Makefile
+++ b/Makefile
@@ -51,3 +51,11 @@
 .PHONY: libsec/libsec.a
 libsec/libsec.a:
 	(cd libsec; $(MAKE))
+
+linuxdist: tlsclient pam_p9.so 9cpu
+	tar cf tlsclient.tar tlsclient pam_p9.so 9cpu
+	gzip tlsclient.tar
+
+obsddist: tlsclient login_-dp9ik 9cpu
+	tar cf tlsclient-obsd.tar tlsclient 9cpu login_-dp9ik
+	gzip tlsclient-obsd.tar
--- a/p9any.c
+++ b/p9any.c
@@ -31,24 +31,43 @@
 int
 unix_dial(char *host, char *port)
 {
-	int fd;
-	struct sockaddr_in server;
-	struct hostent *he;
-	struct in_addr **addr_list;
+	struct addrinfo hints, *res, *res0;
+	int error;
+	int save_errno;
+	int s;
+	const char *cause = NULL;
+	memset(&hints, 0, sizeof(hints));
+	hints.ai_family = AF_UNSPEC;
+	hints.ai_socktype = SOCK_STREAM;
 
-	he = gethostbyname(host);
-	if(he == nil){
+
+	error = getaddrinfo(host, port, &hints, &res0);
+	if(error){
 		printf("could not resolve %s", host);
 		return -1;
 	}
-	fd = socket(AF_INET, SOCK_STREAM, 0);
-	addr_list = (struct in_addr **) he->h_addr_list;
-	server.sin_addr.s_addr = inet_addr(inet_ntoa(*addr_list[0]));
-	server.sin_family = AF_INET;
-	server.sin_port = htons(atoi(port));
-	if(connect(fd, (struct sockaddr*)&server, sizeof(server)) < 0)
-		return -1;
-	return fd;
+	s = -1;
+	for (res = res0; res; res = res->ai_next) {
+		s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
+		if (s == -1) {
+			cause = "socket";
+			continue;
+		}
+		if (connect(s, res->ai_addr, res->ai_addrlen) == -1) {
+			cause = "connect";
+			save_errno = errno;
+			close(s);
+			errno = save_errno;
+			s = -1;
+			continue;
+		}
+
+		break;  /* okay we got one */
+	}
+	if (s == -1) {
+		err(1, "%s", cause);
+	}
+	return s;
 }
 
 static int