make this build without krb5

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@10843 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
2002-02-18 19:17:22 +00:00
parent 9d1fbca6b9
commit 2a478083b6
3 changed files with 90 additions and 92 deletions

View File

@@ -39,15 +39,15 @@ do_read (int fd,
void *buf, void *buf,
size_t sz) size_t sz)
{ {
int ret;
if (do_encrypt) { if (do_encrypt) {
#ifdef KRB4 #ifdef KRB4
if (auth_method == AUTH_KRB4) { if (auth_method == AUTH_KRB4) {
return des_enc_read (fd, buf, sz, schedule, &iv); return des_enc_read (fd, buf, sz, schedule, &iv);
} else } else
#endif /* KRB4 */ #endif /* KRB4 */
#ifdef KRB5
if(auth_method == AUTH_KRB5) { if(auth_method == AUTH_KRB5) {
krb5_error_code ret;
u_int32_t len, outer_len; u_int32_t len, outer_len;
int status; int status;
krb5_data data; krb5_data data;
@@ -76,9 +76,9 @@ do_read (int fd,
memcpy (buf, data.data, len); memcpy (buf, data.data, len);
krb5_data_free (&data); krb5_data_free (&data);
return len; return len;
} else { } else
#endif /* KRB5 */
abort (); abort ();
}
} else } else
return read (fd, buf, sz); 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); return des_enc_write (fd, buf, sz, schedule, &iv);
} else } else
#endif /* KRB4 */ #endif /* KRB4 */
#ifdef KRB5
if(auth_method == AUTH_KRB5) { if(auth_method == AUTH_KRB5) {
krb5_error_code status; krb5_error_code status;
krb5_data data; krb5_data data;
@@ -116,9 +117,9 @@ do_write (int fd, void *buf, size_t sz)
return ret; return ret;
free (data.data); free (data.data);
return sz; return sz;
} else { } else
#endif /* KRB5 */
abort(); abort();
}
} else } else
return write (fd, buf, sz); return write (fd, buf, sz);
} }

View File

@@ -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). * (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved. * All rights reserved.
* *
@@ -41,9 +41,11 @@ int do_forwardable = -1;
int do_unique_tkfile = 0; int do_unique_tkfile = 0;
char *unique_tkfile = NULL; char *unique_tkfile = NULL;
char tkfile[MAXPATHLEN]; char tkfile[MAXPATHLEN];
#ifdef KRB5
krb5_context context; krb5_context context;
krb5_keyblock *keyblock; krb5_keyblock *keyblock;
krb5_crypto crypto; krb5_crypto crypto;
#endif
#ifdef KRB4 #ifdef KRB4
des_key_schedule schedule; des_key_schedule schedule;
des_cblock iv; des_cblock iv;
@@ -180,6 +182,7 @@ send_krb4_auth(int s,
} }
#endif /* KRB4 */ #endif /* KRB4 */
#ifdef KRB5
/* /*
* Send forward information on `s' for host `hostname', them being * Send forward information on `s' for host `hostname', them being
* forwardable themselves if `forwardable' * forwardable themselves if `forwardable'
@@ -369,6 +372,8 @@ send_krb5_auth(int s,
return 0; return 0;
} }
#endif /* KRB5 */
static int static int
send_broken_auth(int s, send_broken_auth(int s,
struct sockaddr *thisaddr, struct sockaddr *thisaddr,
@@ -593,38 +598,19 @@ static int
doit_broken (int argc, doit_broken (int argc,
char **argv, char **argv,
int optind, int optind,
const char *host, struct addrinfo *ai,
const char *remote_user, const char *remote_user,
const char *local_user, const char *local_user,
int port,
int priv_socket1, int priv_socket1,
int priv_socket2, int priv_socket2,
const char *cmd, const char *cmd,
size_t cmd_len) size_t cmd_len)
{ {
struct addrinfo *ai, *a; struct addrinfo *a;
struct addrinfo hints;
int error;
char portstr[NI_MAXSERV];
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 (connect (priv_socket1, ai->ai_addr, ai->ai_addrlen) < 0) {
if (ai->ai_next == NULL) { if (ai->ai_next == NULL)
freeaddrinfo (ai);
return 1; return 1;
}
close(priv_socket1); close(priv_socket1);
close(priv_socket2); close(priv_socket2);
@@ -658,8 +644,6 @@ doit_broken (int argc,
} else { } else {
int status; int status;
freeaddrinfo (ai);
while(waitpid(pid, &status, 0) < 0) while(waitpid(pid, &status, 0) < 0)
; ;
if(WIFEXITED(status) && WEXITSTATUS(status) == 0) if(WIFEXITED(status) && WEXITSTATUS(status) == 0)
@@ -670,8 +654,6 @@ doit_broken (int argc,
} else { } else {
int ret; int ret;
freeaddrinfo (ai);
ret = proto (priv_socket1, priv_socket2, ret = proto (priv_socket1, priv_socket2,
argv[optind], argv[optind],
local_user, remote_user, local_user, remote_user,
@@ -681,11 +663,12 @@ doit_broken (int argc,
} }
} }
#if defined(KRB4) || defined(KRB5)
static int static int
doit (const char *hostname, doit (const char *hostname,
struct addrinfo *ai,
const char *remote_user, const char *remote_user,
const char *local_user, const char *local_user,
int port,
const char *cmd, const char *cmd,
size_t cmd_len, size_t cmd_len,
int do_errsock, int do_errsock,
@@ -695,25 +678,11 @@ doit (const char *hostname,
const char *local_user, size_t cmd_len, const char *local_user, size_t cmd_len,
const char *cmd)) const char *cmd))
{ {
struct addrinfo *ai, *a;
struct addrinfo hints;
int error; int error;
char portstr[NI_MAXSERV]; struct addrinfo *a;
int socketfailed = 1; int socketfailed = 1;
int ret; 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) { for (a = ai; a != NULL; a = a->ai_next) {
int s; int s;
int errsock; int errsock;
@@ -762,7 +731,6 @@ doit (const char *hostname,
} else } else
errsock = -1; errsock = -1;
freeaddrinfo (ai);
ret = proto (s, errsock, ret = proto (s, errsock,
hostname, hostname,
local_user, remote_user, local_user, remote_user,
@@ -772,9 +740,9 @@ doit (const char *hostname,
} }
if(socketfailed) if(socketfailed)
warnx ("failed to contact %s", hostname); warnx ("failed to contact %s", hostname);
freeaddrinfo (ai);
return -1; return -1;
} }
#endif /* KRB4 || KRB5 */
struct getargs args[] = { struct getargs args[] = {
#ifdef KRB4 #ifdef KRB4
@@ -822,8 +790,9 @@ 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 port = 0;
int optind = 0; int optind = 0;
int error;
struct addrinfo hints, *ai;
int ret = 1; int ret = 1;
char *cmd; char *cmd;
char *tmp; char *tmp;
@@ -831,7 +800,9 @@ main(int argc, char **argv)
const char *local_user; const char *local_user;
char *host = NULL; char *host = NULL;
int host_index = -1; int host_index = -1;
#ifdef KRB5
int status; int status;
#endif
uid_t uid; uid_t uid;
priv_port1 = priv_port2 = IPPORT_RESERVED-1; priv_port1 = priv_port2 = IPPORT_RESERVED-1;
@@ -848,10 +819,6 @@ main(int argc, char **argv)
optind = 1; 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, if (getarg (args, sizeof(args) / sizeof(args[0]), argc, argv,
&optind)) &optind))
usage (1); usage (1);
@@ -864,6 +831,15 @@ main(int argc, char **argv)
return 0; 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) if (do_forwardable == -1)
do_forwardable = krb5_config_get_bool (context, NULL, do_forwardable = krb5_config_get_bool (context, NULL,
"libdefaults", "libdefaults",
@@ -887,6 +863,7 @@ main(int argc, char **argv)
NULL)) NULL))
do_encrypt = 0; do_encrypt = 0;
} }
#endif
if (do_forwardable) if (do_forwardable)
do_forward = 1; do_forward = 1;
@@ -950,21 +927,6 @@ main(int argc, char **argv)
err (1, "execvp rlogin"); 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 (); local_user = get_default_username ();
if (local_user == NULL) if (local_user == NULL)
errx (1, "who are you?"); errx (1, "who are you?");
@@ -978,50 +940,79 @@ main(int argc, char **argv)
* Try all different authentication methods * Try all different authentication methods
*/ */
#ifdef KRB5
if (ret && use_v5) { if (ret && use_v5) {
int tmp_port; memset (&hints, 0, sizeof(hints));
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
if (port) if(port_str == NULL) {
tmp_port = port; error = getaddrinfo(host, "kshell", &hints, &ai);
else if(error == EAI_NONAME)
tmp_port = krb5_getportbyname (context, "kshell", "tcp", 544); 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; 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, do_errsock,
send_krb5_auth); send_krb5_auth);
freeaddrinfo(ai);
} }
#endif
#ifdef KRB4 #ifdef KRB4
if (ret && use_v4) { if (ret && use_v4) {
int tmp_port; memset (&hints, 0, sizeof(hints));
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
if (port) if(port_str == NULL) {
tmp_port = port; if(do_encrypt) {
else if (do_encrypt) error = getaddrinfo(host, "ekshell", &hints, &ai);
tmp_port = krb5_getportbyname (context, "ekshell", "tcp", 545); if(error == EAI_NONAME)
else error = getaddrinfo(host, "545", &hints, &ai);
tmp_port = krb5_getportbyname (context, "kshell", "tcp", 544); } 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; 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, do_errsock,
send_krb4_auth); send_krb4_auth);
freeaddrinfo(ai);
} }
#endif #endif
if (ret && use_broken) { 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; auth_method = AUTH_BROKEN;
ret = doit_broken (argc, argv, host_index, host, ret = doit_broken (argc, argv, host_index, ai,
user, local_user, user, local_user,
tmp_port,
priv_socket1, priv_socket1,
do_errsock ? priv_socket2 : -1, do_errsock ? priv_socket2 : -1,
cmd, cmd_len); cmd, cmd_len);
freeaddrinfo(ai);
} }
return ret; return ret;
} }

View File

@@ -97,8 +97,12 @@
#include <krb.h> #include <krb.h>
#include <prot.h> #include <prot.h>
#endif #endif
#ifdef KRB5
#include <krb5.h> #include <krb5.h>
#endif
#ifdef KRB4
#include <kafs.h> #include <kafs.h>
#endif
#ifndef _PATH_NOLOGIN #ifndef _PATH_NOLOGIN
#define _PATH_NOLOGIN "/etc/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 enum auth_method auth_method;
extern int do_encrypt; extern int do_encrypt;
#ifdef KRB5
extern krb5_context context; extern krb5_context context;
extern krb5_keyblock *keyblock; extern krb5_keyblock *keyblock;
extern krb5_crypto crypto; extern krb5_crypto crypto;
#endif
#ifdef KRB4 #ifdef KRB4
extern des_key_schedule schedule; extern des_key_schedule schedule;
extern des_cblock iv; extern des_cblock iv;