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