shithub: tlsclient

Download patch

ref: 5ca0f0875e0762d2c34ce0f5450ffba585e413f0
parent: 0ca1541b155d0107aea29a8bed4ef23f20365f37
parent: 87bd72ba5cbafb99c58e608c335705a98b10ce23
author: B. Atticus Grobe <grobe0ba@gmail.com>
date: Tue Jul 5 15:16:42 EDT 2022

Merge branch 'master' of https://git.sr.ht/~moody/tlsclient

diff: cannot open b/.builds//null: file does not exist: 'b/.builds//null'
--- /dev/null
+++ b/.builds/obsd.yml
@@ -1,0 +1,13 @@
+image: openbsd/6.9
+sources:
+  - https://git.sr.ht/~moody/tlsclient
+packages:
+  - "openssl-1.1.1k"
+artifacts:
+  - tlsclient/tlsclient-obsd.tar.gz
+tasks:
+  - build: |
+      cd tlsclient
+      sed -i '/^OPENSSL/d' Make.config
+      sed -i 's/#OPENSSL/OPENSSL/g' Make.config
+      make -j $(sysctl -n hw.ncpu) 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/Make.config
+++ b/Make.config
@@ -5,4 +5,5 @@
 LDADD=
 TARG=tlsclient
 
+
 all: default
--- a/Makefile
+++ b/Makefile
@@ -62,3 +62,11 @@
 .PHONY: third_party/boringssl/libssl.a
 third_party/boringssl/libssl.a:
 	(cd third_party/boringssl; $(MAKE) libssl.a)
+
+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/cpu.c
+++ b/cpu.c
@@ -98,7 +98,6 @@
 	int pin[2];
 	int pout[2];
 	int infd, outfd;
-	char *srv = nil;
 	int i;
 	pid_t execc, xferc;
 
@@ -118,10 +117,9 @@
 		case 'a': authserver = EARGF(usage()); break;
 		case 'p': port = EARGF(usage()); break;
 		case 'R': Rflag++; break;
-		case 's': srv = EARGF(usage()); break;
 	} ARGEND
 
-	if(Rflag || srv != nil)
+	if(Rflag)
 		port = "17019";
 
 	if(user == nil || host == nil || authserver == nil || port == nil)
@@ -139,15 +137,7 @@
 		sysfatal("could not init openssl");
 	ssl_conn = SSL_new(ssl_ctx);
 
-
-	fd = unix_dial(host, port);
-	if(fd < 0){
-		sysfatal("Failed to connect to the client");
-	}
-
-	p9authtls(fd);
-
-	if(!Rflag || srv != nil){
+	if(*argv && !Rflag){
 		pipe(pin);
 		pipe(pout);
 		switch((execc = fork())){
@@ -165,13 +155,16 @@
 		close(pin[0]);
 		infd = pout[0];
 		outfd = pin[1];
-		if(srv != nil){
-			snprint(buf, sizeof buf - 1, "bind '#|' /n/p; <>[3]/n/p/data1 { echo 3 > /srv/%s; cat /n/p/data & cat > /n/p/data}\n", srv);
-			goto rcpu;
-		}
 	}
 
-	if(Rflag) {
+	fd = unix_dial(host, port);
+	if(fd < 0){
+		sysfatal("Failed to connect to the client");
+	}
+
+	p9authtls(fd);
+
+	if(*argv && Rflag) {
 		for(i=0,n=0; i<argc; i++)
 			n += snprint(buf+n, sizeof buf - n - 1, "%s ", argv[i]);
 		if(n <= 0)
@@ -178,7 +171,6 @@
 			usage();
 		buf[n-1] = '\n';
 		buf[n] = '\0';
-rcpu:
 		i = strlen(buf);
 		snprint(buf2, sizeof buf2, "%7d\n", i);
 		tls_send(-1, buf2, strlen(buf2));
--- 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