make the syslog messages somewhat more informative

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@10797 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
2001-11-30 14:38:48 +00:00
parent 73cc5cf8be
commit b396a05fa5

View File

@@ -91,11 +91,11 @@ syslog_and_die (const char *m, ...)
} }
static void static void
fatal (int sock, const char *m, ...) fatal (int, const char*, const char *, ...)
__attribute__ ((format (printf, 2, 3))); __attribute__ ((format (printf, 3, 4)));
static void static void
fatal (int sock, const char *m, ...) fatal (int sock, const char *what, const char *m, ...)
{ {
va_list args; va_list args;
char buf[BUFSIZ]; char buf[BUFSIZ];
@@ -106,6 +106,9 @@ fatal (int sock, const char *m, ...)
len = vsnprintf (buf + 1, sizeof(buf) - 1, m, args); len = vsnprintf (buf + 1, sizeof(buf) - 1, m, args);
len = min(len, sizeof(buf) - 1); len = min(len, sizeof(buf) - 1);
va_end(args); va_end(args);
if(what != NULL)
syslog (LOG_ERR, "%s: %m: %s", what, buf + 1);
else
syslog (LOG_ERR, "%s", buf + 1); syslog (LOG_ERR, "%s", buf + 1);
net_write (sock, buf, len + 1); net_write (sock, buf, len + 1);
exit (1); exit (1);
@@ -122,7 +125,7 @@ read_str (int s, char *str, size_t sz, char *expl)
--sz; --sz;
++str; ++str;
} }
fatal (s, "%s too long", expl); fatal (s, NULL, "%s too long", expl);
} }
static int static int
@@ -140,10 +143,10 @@ recv_bsd_auth (int s, u_char *buf,
read_str (s, cmd, COMMAND_SZ, "command"); read_str (s, cmd, COMMAND_SZ, "command");
pwd = getpwnam(server_username); pwd = getpwnam(server_username);
if (pwd == NULL) if (pwd == NULL)
fatal(s, "Login incorrect."); fatal(s, NULL, "Login incorrect.");
if (iruserok(thataddr->sin_addr.s_addr, pwd->pw_uid == 0, if (iruserok(thataddr->sin_addr.s_addr, pwd->pw_uid == 0,
client_username, server_username)) client_username, server_username))
fatal(s, "Login incorrect."); fatal(s, NULL, "Login incorrect.");
return 0; return 0;
} }
@@ -193,7 +196,7 @@ recv_krb4_auth (int s, u_char *buf,
read_str (s, server_username, USERNAME_SZ, "remote username"); read_str (s, server_username, USERNAME_SZ, "remote username");
if (kuserok (&auth, server_username) != 0) if (kuserok (&auth, server_username) != 0)
fatal (s, "Permission denied"); fatal (s, NULL, "Permission denied.");
read_str (s, cmd, COMMAND_SZ, "command"); read_str (s, cmd, COMMAND_SZ, "command");
syslog(LOG_INFO|LOG_AUTH, syslog(LOG_INFO|LOG_AUTH,
@@ -371,14 +374,14 @@ recv_krb5_auth (int s, u_char *buf,
if(!krb5_kuserok (context, if(!krb5_kuserok (context,
ticket->client, ticket->client,
server_username)) server_username))
fatal (s, "Permission denied"); fatal (s, NULL, "Permission denied.");
if (strncmp (cmd, "-x ", 3) == 0) { if (strncmp (cmd, "-x ", 3) == 0) {
do_encrypt = 1; do_encrypt = 1;
memmove (cmd, cmd + 3, strlen(cmd) - 2); memmove (cmd, cmd + 3, strlen(cmd) - 2);
} else { } else {
if(do_encrypt) if(do_encrypt)
fatal (s, "Encryption required"); fatal (s, NULL, "Encryption is required.");
do_encrypt = 0; do_encrypt = 0;
} }
@@ -494,7 +497,7 @@ static void
pipe_a_like (int fd[2]) pipe_a_like (int fd[2])
{ {
if (socketpair (AF_UNIX, SOCK_STREAM, 0, fd) < 0) if (socketpair (AF_UNIX, SOCK_STREAM, 0, fd) < 0)
fatal (STDOUT_FILENO, "socketpair: %m"); fatal (STDOUT_FILENO, "socketpair", "Pipe creation failed.");
} }
/* /*
@@ -511,7 +514,7 @@ setup_copier (void)
pipe_a_like(p2); pipe_a_like(p2);
pid = fork (); pid = fork ();
if (pid < 0) if (pid < 0)
fatal (STDOUT_FILENO, "fork: %m"); fatal (STDOUT_FILENO, "fork", "Could not create child process.");
if (pid == 0) { /* child */ if (pid == 0) { /* child */
close (p0[1]); close (p0[1]);
close (p1[0]); close (p1[0]);
@@ -528,7 +531,7 @@ setup_copier (void)
close (p2[1]); close (p2[1]);
if (net_write (STDOUT_FILENO, "", 1) != 1) if (net_write (STDOUT_FILENO, "", 1) != 1)
fatal (STDOUT_FILENO, "write failed"); fatal (STDOUT_FILENO, "net_write", "Write failure.");
loop (STDIN_FILENO, p0[1], loop (STDIN_FILENO, p0[1],
STDOUT_FILENO, p1[0], STDOUT_FILENO, p1[0],
@@ -619,7 +622,7 @@ doit (int do_kerberos, int check_rhosts)
syslog_and_die ("getpeername: %m"); syslog_and_die ("getpeername: %m");
if (!do_kerberos && !is_reserved(socket_get_port(thataddr))) if (!do_kerberos && !is_reserved(socket_get_port(thataddr)))
fatal(s, "Permission denied"); fatal(s, NULL, "Permission denied.");
p = buf; p = buf;
port = 0; port = 0;
@@ -635,7 +638,7 @@ doit (int do_kerberos, int check_rhosts)
} }
if (!do_kerberos && !is_reserved(htons(port))) if (!do_kerberos && !is_reserved(htons(port)))
fatal(s, "Permission denied"); fatal(s, NULL, "Permission denied.");
if (port) { if (port) {
int priv_port = IPPORT_RESERVED - 1; int priv_port = IPPORT_RESERVED - 1;
@@ -711,25 +714,25 @@ doit (int do_kerberos, int check_rhosts)
pwd = getpwnam (server_user); pwd = getpwnam (server_user);
if (pwd == NULL) if (pwd == NULL)
fatal (s, "Login incorrect."); fatal (s, NULL, "Login incorrect.");
if (*pwd->pw_shell == '\0') if (*pwd->pw_shell == '\0')
pwd->pw_shell = _PATH_BSHELL; pwd->pw_shell = _PATH_BSHELL;
if (pwd->pw_uid != 0 && access (_PATH_NOLOGIN, F_OK) == 0) if (pwd->pw_uid != 0 && access (_PATH_NOLOGIN, F_OK) == 0)
fatal (s, "Login disabled."); fatal (s, NULL, "Login disabled.");
ret = getnameinfo_verified (thataddr, thataddr_len, ret = getnameinfo_verified (thataddr, thataddr_len,
that_host, sizeof(that_host), that_host, sizeof(that_host),
NULL, 0, 0); NULL, 0, 0);
if (ret) if (ret)
fatal (s, "getnameinfo: %s", gai_strerror(ret)); fatal (s, NULL, "getnameinfo: %s", gai_strerror(ret));
if (login_access(pwd, that_host) == 0) { if (login_access(pwd, that_host) == 0) {
syslog(LOG_NOTICE, "Kerberos rsh denied to %s from %s", syslog(LOG_NOTICE, "Kerberos rsh denied to %s from %s",
server_user, that_host); server_user, that_host);
fatal(s, "Permission denied"); fatal(s, NULL, "Permission denied.");
} }
#ifdef HAVE_GETSPNAM #ifdef HAVE_GETSPNAM
@@ -742,7 +745,7 @@ doit (int do_kerberos, int check_rhosts)
today = time(0)/(24L * 60 * 60); today = time(0)/(24L * 60 * 60);
if (sp->sp_expire > 0) if (sp->sp_expire > 0)
if (today > sp->sp_expire) if (today > sp->sp_expire)
fatal(s, "Account has expired."); fatal(s, NULL, "Account has expired.");
} }
} }
#endif #endif
@@ -786,20 +789,20 @@ doit (int do_kerberos, int check_rhosts)
#endif /* HAVE_SETPCRED */ #endif /* HAVE_SETPCRED */
if (initgroups (pwd->pw_name, pwd->pw_gid) < 0) if (initgroups (pwd->pw_name, pwd->pw_gid) < 0)
fatal (s, "Login incorrect."); fatal (s, "initgroups", "Login incorrect.");
if (setgid(pwd->pw_gid) < 0) if (setgid(pwd->pw_gid) < 0)
fatal (s, "Login incorrect."); fatal (s, "setgid", "Login incorrect.");
if (setuid (pwd->pw_uid) < 0) if (setuid (pwd->pw_uid) < 0)
fatal (s, "Login incorrect."); fatal (s, "setuid", "Login incorrect.");
if (chdir (pwd->pw_dir) < 0) if (chdir (pwd->pw_dir) < 0)
fatal (s, "Remote directory."); fatal (s, "chdir", "Remote directory.");
if (errsock >= 0) { if (errsock >= 0) {
if (dup2 (errsock, STDERR_FILENO) < 0) if (dup2 (errsock, STDERR_FILENO) < 0)
fatal (s, "Dup2 failed."); fatal (s, "dup2", "Cannot dup stderr.");
close (errsock); close (errsock);
} }
@@ -809,7 +812,7 @@ doit (int do_kerberos, int check_rhosts)
setup_copier (); setup_copier ();
} else { } else {
if (net_write (s, "", 1) != 1) if (net_write (s, "", 1) != 1)
fatal (s, "write failed"); fatal (s, "net_write", "write failed");
} }
#ifdef KRB4 #ifdef KRB4