xref: /original-bsd/lib/libcompat/4.3/rexec.c (revision c05f5e42)
1 /* Copyright (c) 1982 Regents of the University of California */
2 
3 static char sccsid[] = "@(#)rexec.c 4.2 03/05/82";
4 
5 #include <stdio.h>
6 #include <sys/types.h>
7 #include <sys/socket.h>
8 #include <net/in.h>
9 #include <wellknown.h>
10 
11 char	*index(), *malloc(), *getpass(), *getlogin();
12 static	struct sockaddr_in sin = { AF_INET };
13 
14 rexec(ahost, port, cmd, name, pass)
15 	char **ahost, *cmd, *name, *pass;
16 {
17 	int rem, addr;
18 
19 	addr = rhost(ahost);
20 	if (addr == -1) {
21 		printf("%s: unknown host\n", *ahost);
22 		return (-1);
23 	}
24 	sin.sin_port = port;
25 	sin.sin_addr.s_addr = addr;
26 	ruserpass(*ahost, &name, &pass);
27 	rem = socket(SOCK_STREAM, 0, 0, SO_DEBUG);
28 	if (rem < 0) {
29 		perror("socket");
30 		return (-1);
31 	}
32 	if (connect(rem, &sin) < 0) {
33 		perror(*ahost);
34 		close(rem);
35 		return (-1);
36 	}
37 	write(rem, name, strlen(name) + 1);
38 	/* should public key encypt the password here */
39 	write(rem, pass, strlen(pass) + 1);
40 	if (cmd)
41 		write(rem, cmd, strlen(cmd) + 1);
42 	return (rem);
43 }
44