From 2a478083b6b8749fb4786e7829ac822ead054611 Mon Sep 17 00:00:00 2001 From: Johan Danielsson Date: Mon, 18 Feb 2002 19:17:22 +0000 Subject: [PATCH] make this build without krb5 git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@10843 ec53bebd-3082-4978-b11e-865c3cabbd6b --- appl/rsh/common.c | 13 ++-- appl/rsh/rsh.c | 163 +++++++++++++++++++++----------------------- appl/rsh/rsh_locl.h | 6 ++ 3 files changed, 90 insertions(+), 92 deletions(-) diff --git a/appl/rsh/common.c b/appl/rsh/common.c index a07f545b1..1480a2928 100644 --- a/appl/rsh/common.c +++ b/appl/rsh/common.c @@ -39,15 +39,15 @@ do_read (int fd, void *buf, size_t sz) { - int ret; - if (do_encrypt) { #ifdef KRB4 if (auth_method == AUTH_KRB4) { return des_enc_read (fd, buf, sz, schedule, &iv); } else #endif /* KRB4 */ +#ifdef KRB5 if(auth_method == AUTH_KRB5) { + krb5_error_code ret; u_int32_t len, outer_len; int status; krb5_data data; @@ -76,9 +76,9 @@ do_read (int fd, memcpy (buf, data.data, len); krb5_data_free (&data); return len; - } else { + } else +#endif /* KRB5 */ abort (); - } } else return read (fd, buf, sz); } @@ -92,6 +92,7 @@ do_write (int fd, void *buf, size_t sz) return des_enc_write (fd, buf, sz, schedule, &iv); } else #endif /* KRB4 */ +#ifdef KRB5 if(auth_method == AUTH_KRB5) { krb5_error_code status; krb5_data data; @@ -116,9 +117,9 @@ do_write (int fd, void *buf, size_t sz) return ret; free (data.data); return sz; - } else { + } else +#endif /* KRB5 */ abort(); - } } else return write (fd, buf, sz); } diff --git a/appl/rsh/rsh.c b/appl/rsh/rsh.c index 0e6ebf0bf..1ac70d4d1 100644 --- a/appl/rsh/rsh.c +++ b/appl/rsh/rsh.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997 - 2001 Kungliga Tekniska Högskolan + * Copyright (c) 1997 - 2002 Kungliga Tekniska Högskolan * (Royal Institute of Technology, Stockholm, Sweden). * All rights reserved. * @@ -41,9 +41,11 @@ int do_forwardable = -1; int do_unique_tkfile = 0; char *unique_tkfile = NULL; char tkfile[MAXPATHLEN]; +#ifdef KRB5 krb5_context context; krb5_keyblock *keyblock; krb5_crypto crypto; +#endif #ifdef KRB4 des_key_schedule schedule; des_cblock iv; @@ -180,6 +182,7 @@ send_krb4_auth(int s, } #endif /* KRB4 */ +#ifdef KRB5 /* * Send forward information on `s' for host `hostname', them being * forwardable themselves if `forwardable' @@ -369,6 +372,8 @@ send_krb5_auth(int s, return 0; } +#endif /* KRB5 */ + static int send_broken_auth(int s, struct sockaddr *thisaddr, @@ -593,38 +598,19 @@ static int doit_broken (int argc, char **argv, int optind, - const char *host, + struct addrinfo *ai, const char *remote_user, const char *local_user, - int port, int priv_socket1, int priv_socket2, const char *cmd, size_t cmd_len) { - struct addrinfo *ai, *a; - struct addrinfo hints; - int error; - char portstr[NI_MAXSERV]; + struct addrinfo *a; - memset (&hints, 0, sizeof(hints)); - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = IPPROTO_TCP; - hints.ai_family = AF_INET; - - snprintf (portstr, sizeof(portstr), "%u", ntohs(port)); - - error = getaddrinfo (host, portstr, &hints, &ai); - if (error) { - warnx ("%s: %s", host, gai_strerror(error)); - return 1; - } - if (connect (priv_socket1, ai->ai_addr, ai->ai_addrlen) < 0) { - if (ai->ai_next == NULL) { - freeaddrinfo (ai); + if (ai->ai_next == NULL) return 1; - } close(priv_socket1); close(priv_socket2); @@ -658,8 +644,6 @@ doit_broken (int argc, } else { int status; - freeaddrinfo (ai); - while(waitpid(pid, &status, 0) < 0) ; if(WIFEXITED(status) && WEXITSTATUS(status) == 0) @@ -670,8 +654,6 @@ doit_broken (int argc, } else { int ret; - freeaddrinfo (ai); - ret = proto (priv_socket1, priv_socket2, argv[optind], local_user, remote_user, @@ -681,11 +663,12 @@ doit_broken (int argc, } } +#if defined(KRB4) || defined(KRB5) static int doit (const char *hostname, + struct addrinfo *ai, const char *remote_user, const char *local_user, - int port, const char *cmd, size_t cmd_len, int do_errsock, @@ -695,25 +678,11 @@ doit (const char *hostname, const char *local_user, size_t cmd_len, const char *cmd)) { - struct addrinfo *ai, *a; - struct addrinfo hints; int error; - char portstr[NI_MAXSERV]; + struct addrinfo *a; int socketfailed = 1; int ret; - memset (&hints, 0, sizeof(hints)); - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = IPPROTO_TCP; - - snprintf (portstr, sizeof(portstr), "%u", ntohs(port)); - - error = getaddrinfo (hostname, portstr, &hints, &ai); - if (error) { - errx (1, "%s: %s", hostname, gai_strerror(error)); - return -1; - } - for (a = ai; a != NULL; a = a->ai_next) { int s; int errsock; @@ -762,7 +731,6 @@ doit (const char *hostname, } else errsock = -1; - freeaddrinfo (ai); ret = proto (s, errsock, hostname, local_user, remote_user, @@ -772,9 +740,9 @@ doit (const char *hostname, } if(socketfailed) warnx ("failed to contact %s", hostname); - freeaddrinfo (ai); return -1; } +#endif /* KRB4 || KRB5 */ struct getargs args[] = { #ifdef KRB4 @@ -822,8 +790,9 @@ main(int argc, char **argv) { int priv_port1, priv_port2; int priv_socket1, priv_socket2; - int port = 0; int optind = 0; + int error; + struct addrinfo hints, *ai; int ret = 1; char *cmd; char *tmp; @@ -831,7 +800,9 @@ main(int argc, char **argv) const char *local_user; char *host = NULL; int host_index = -1; +#ifdef KRB5 int status; +#endif uid_t uid; priv_port1 = priv_port2 = IPPORT_RESERVED-1; @@ -848,10 +819,6 @@ main(int argc, char **argv) optind = 1; } - status = krb5_init_context (&context); - if (status) - errx(1, "krb5_init_context failed: %d", status); - if (getarg (args, sizeof(args) / sizeof(args[0]), argc, argv, &optind)) usage (1); @@ -864,6 +831,15 @@ main(int argc, char **argv) return 0; } +#ifdef KRB5 + status = krb5_init_context (&context); + if (status) { + if(use_v5 == 1) + errx(1, "krb5_init_context failed: %d", status); + else + use_v5 = 0; + } + if (do_forwardable == -1) do_forwardable = krb5_config_get_bool (context, NULL, "libdefaults", @@ -887,6 +863,7 @@ main(int argc, char **argv) NULL)) do_encrypt = 0; } +#endif if (do_forwardable) do_forward = 1; @@ -950,21 +927,6 @@ main(int argc, char **argv) err (1, "execvp rlogin"); } - if (port_str) { - struct servent *s = roken_getservbyname (port_str, "tcp"); - - if (s) - port = s->s_port; - else { - char *ptr; - - port = strtol (port_str, &ptr, 10); - if (port == 0 && ptr == port_str) - errx (1, "Bad port `%s'", port_str); - port = htons(port); - } - } - local_user = get_default_username (); if (local_user == NULL) errx (1, "who are you?"); @@ -978,50 +940,79 @@ main(int argc, char **argv) * Try all different authentication methods */ +#ifdef KRB5 if (ret && use_v5) { - int tmp_port; + memset (&hints, 0, sizeof(hints)); + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; - if (port) - tmp_port = port; - else - tmp_port = krb5_getportbyname (context, "kshell", "tcp", 544); + if(port_str == NULL) { + error = getaddrinfo(host, "kshell", &hints, &ai); + if(error == EAI_NONAME) + error = getaddrinfo(host, "544", &hints, &ai); + } else + error = getaddrinfo(host, port_str, &hints, &ai); + + if(error) + errx (1, "getaddrinfo: %s", gai_strerror(error)); auth_method = AUTH_KRB5; - ret = doit (host, user, local_user, tmp_port, cmd, cmd_len, + ret = doit (host, ai, user, local_user, cmd, cmd_len, do_errsock, send_krb5_auth); + freeaddrinfo(ai); } +#endif #ifdef KRB4 if (ret && use_v4) { - int tmp_port; + memset (&hints, 0, sizeof(hints)); + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; - if (port) - tmp_port = port; - else if (do_encrypt) - tmp_port = krb5_getportbyname (context, "ekshell", "tcp", 545); - else - tmp_port = krb5_getportbyname (context, "kshell", "tcp", 544); + if(port_str == NULL) { + if(do_encrypt) { + error = getaddrinfo(host, "ekshell", &hints, &ai); + if(error == EAI_NONAME) + error = getaddrinfo(host, "545", &hints, &ai); + } else { + error = getaddrinfo(host, "kshell", &hints, &ai); + if(error == EAI_NONAME) + error = getaddrinfo(host, "544", &hints, &ai); + } + } else + error = getaddrinfo(host, port_str, &hints, &ai); + if(error) + errx (1, "getaddrinfo: %s", gai_strerror(error)); auth_method = AUTH_KRB4; - ret = doit (host, user, local_user, tmp_port, cmd, cmd_len, + ret = doit (host, ai, user, local_user, cmd, cmd_len, do_errsock, send_krb4_auth); + freeaddrinfo(ai); } #endif if (ret && use_broken) { - int tmp_port; + memset (&hints, 0, sizeof(hints)); + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + + if(port_str == NULL) { + error = getaddrinfo(host, "shell", &hints, &ai); + if(error == EAI_NONAME) + error = getaddrinfo(host, "514", &hints, &ai); + } else + error = getaddrinfo(host, port_str, &hints, &ai); + + if(error) + errx (1, "getaddrinfo: %s", gai_strerror(error)); - if(port) - tmp_port = port; - else - tmp_port = krb5_getportbyname(context, "shell", "tcp", 514); auth_method = AUTH_BROKEN; - ret = doit_broken (argc, argv, host_index, host, + ret = doit_broken (argc, argv, host_index, ai, user, local_user, - tmp_port, priv_socket1, do_errsock ? priv_socket2 : -1, cmd, cmd_len); + freeaddrinfo(ai); } return ret; } diff --git a/appl/rsh/rsh_locl.h b/appl/rsh/rsh_locl.h index 3c038f7ce..cfc152e84 100644 --- a/appl/rsh/rsh_locl.h +++ b/appl/rsh/rsh_locl.h @@ -97,8 +97,12 @@ #include #include #endif +#ifdef KRB5 #include +#endif +#ifdef KRB4 #include +#endif #ifndef _PATH_NOLOGIN #define _PATH_NOLOGIN "/etc/nologin" @@ -124,9 +128,11 @@ enum auth_method { AUTH_KRB4, AUTH_KRB5, AUTH_BROKEN }; extern enum auth_method auth_method; extern int do_encrypt; +#ifdef KRB5 extern krb5_context context; extern krb5_keyblock *keyblock; extern krb5_crypto crypto; +#endif #ifdef KRB4 extern des_key_schedule schedule; extern des_cblock iv;