(doit_broken): call print_addr from parent process, and skip

un-printable addresses; (print_addr): don't limit to IPv4


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@11464 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
2002-09-19 19:26:47 +00:00
parent 525a43814d
commit eb56509978

View File

@@ -625,13 +625,23 @@ construct_command (char **res, int argc, char **argv)
} }
static char * static char *
print_addr (const struct sockaddr_in *sin) print_addr (const struct sockaddr *sa)
{ {
char addr_str[256]; char addr_str[256];
char *res; char *res;
const char *as = NULL;
inet_ntop (AF_INET, &sin->sin_addr, addr_str, sizeof(addr_str)); if(sa->sa_family == AF_INET)
res = strdup(addr_str); as = inet_ntop (sa->sa_family, &((struct sockaddr_in*)sa)->sin_addr,
addr_str, sizeof(addr_str));
#ifdef HAVE_INET6
else if(sa->sa_family == AF_INET6)
as = inet_ntop (sa->sa_family, &((struct sockaddr_in6*)sa)->sin6_addr,
addr_str, sizeof(addr_str));
#endif
if(as == NULL)
return NULL;
res = strdup(as);
if (res == NULL) if (res == NULL)
errx (1, "malloc: out of memory"); errx (1, "malloc: out of memory");
return res; return res;
@@ -640,7 +650,7 @@ print_addr (const struct sockaddr_in *sin)
static int static int
doit_broken (int argc, doit_broken (int argc,
char **argv, char **argv,
int optind, int hostindex,
struct addrinfo *ai, struct addrinfo *ai,
const char *remote_user, const char *remote_user,
const char *local_user, const char *local_user,
@@ -652,14 +662,16 @@ doit_broken (int argc,
struct addrinfo *a; struct addrinfo *a;
if (connect (priv_socket1, ai->ai_addr, ai->ai_addrlen) < 0) { if (connect (priv_socket1, ai->ai_addr, ai->ai_addrlen) < 0) {
if (ai->ai_next == NULL) int save_errno = errno;
return 1;
close(priv_socket1); close(priv_socket1);
close(priv_socket2); close(priv_socket2);
for (a = ai->ai_next; a != NULL; a = a->ai_next) { for (a = ai->ai_next; a != NULL; a = a->ai_next) {
pid_t pid; pid_t pid;
char *adr = print_addr(a->ai_addr);
if(adr == NULL)
continue;
pid = fork(); pid = fork();
if (pid < 0) if (pid < 0)
@@ -667,25 +679,25 @@ doit_broken (int argc,
else if(pid == 0) { else if(pid == 0) {
char **new_argv; char **new_argv;
int i = 0; int i = 0;
struct sockaddr_in *sin = (struct sockaddr_in *)a->ai_addr;
new_argv = malloc((argc + 2) * sizeof(*new_argv)); new_argv = malloc((argc + 2) * sizeof(*new_argv));
if (new_argv == NULL) if (new_argv == NULL)
errx (1, "malloc: out of memory"); errx (1, "malloc: out of memory");
new_argv[i] = argv[i]; new_argv[i] = argv[i];
++i; ++i;
if (optind == i) if (hostindex == i)
new_argv[i++] = print_addr (sin); new_argv[i++] = adr;
new_argv[i++] = "-K"; new_argv[i++] = "-K";
for(; i <= argc; ++i) for(; i <= argc; ++i)
new_argv[i] = argv[i - 1]; new_argv[i] = argv[i - 1];
if (optind > 1) if (hostindex > 1)
new_argv[optind + 1] = print_addr(sin); new_argv[hostindex + 1] = adr;
new_argv[argc + 1] = NULL; new_argv[argc + 1] = NULL;
execv(PATH_RSH, new_argv); execv(PATH_RSH, new_argv);
err(1, "execv(%s)", PATH_RSH); err(1, "execv(%s)", PATH_RSH);
} else { } else {
int status; int status;
free(adr);
while(waitpid(pid, &status, 0) < 0) while(waitpid(pid, &status, 0) < 0)
; ;
@@ -693,12 +705,14 @@ doit_broken (int argc,
return 0; return 0;
} }
} }
errno = save_errno;
warn("%s", argv[hostindex]);
return 1; return 1;
} else { } else {
int ret; int ret;
ret = proto (priv_socket1, priv_socket2, ret = proto (priv_socket1, priv_socket2,
argv[optind], argv[hostindex],
local_user, remote_user, local_user, remote_user,
cmd, cmd_len, cmd, cmd_len,
send_broken_auth); send_broken_auth);
@@ -841,7 +855,7 @@ main(int argc, char **argv)
{ {
int priv_port1, priv_port2; int priv_port1, priv_port2;
int priv_socket1, priv_socket2; int priv_socket1, priv_socket2;
int optind = 0; int argindex = 0;
int error; int error;
struct addrinfo hints, *ai; struct addrinfo hints, *ai;
int ret = 1; int ret = 1;
@@ -867,11 +881,11 @@ main(int argc, char **argv)
if (argc >= 2 && argv[1][0] != '-') { if (argc >= 2 && argv[1][0] != '-') {
host = argv[host_index = 1]; host = argv[host_index = 1];
optind = 1; argindex = 1;
} }
if (getarg (args, sizeof(args) / sizeof(args[0]), argc, argv, if (getarg (args, sizeof(args) / sizeof(args[0]), argc, argv,
&optind)) &argindex))
usage (1); usage (1);
if (do_help) if (do_help)
@@ -986,10 +1000,10 @@ main(int argc, char **argv)
#endif #endif
if (host == NULL) { if (host == NULL) {
if (argc - optind < 1) if (argc - argindex < 1)
usage (1); usage (1);
else else
host = argv[host_index = optind++]; host = argv[host_index = argindex++];
} }
if((tmp = strchr(host, '@')) != NULL) { if((tmp = strchr(host, '@')) != NULL) {
@@ -998,7 +1012,7 @@ main(int argc, char **argv)
host = tmp; host = tmp;
} }
if (optind == argc) { if (argindex == argc) {
close (priv_socket1); close (priv_socket1);
close (priv_socket2); close (priv_socket2);
argv[0] = "rlogin"; argv[0] = "rlogin";
@@ -1013,7 +1027,7 @@ main(int argc, char **argv)
if (user == NULL) if (user == NULL)
user = local_user; user = local_user;
cmd_len = construct_command(&cmd, argc - optind, argv + optind); cmd_len = construct_command(&cmd, argc - argindex, argv + argindex);
/* /*
* Try all different authentication methods * Try all different authentication methods