[1252] in Kerberos-V5-bugs
krb5b4pl3: rlogin, rsh, rcp: consistently print program name in error messages
daemon@ATHENA.MIT.EDU (Jonathan I. Kamens)
Thu Mar 23 13:27:37 1995
From: "Jonathan I. Kamens" <jik@cam.ov.com>
Date: Thu, 23 Mar 1995 13:30:36 -0500
To: krb5-bugs@MIT.EDU
The patch below modifies kcmd.c, krlogin.c, krsh.c and krcp.c in
appl/bsd so that the name by which each program was invoked is always
printed before error messages. The change to kcmd.c is
backward-compatible; i.e., if there's anything outside of appl/bsd
using kcmd.c (which I doubt), it'll continue to work properly even if
it isn't modified as I've modified krlogin.c, krsh.c and krcp.c.
Share and enjoy :-).
--- kcmd.c 1995/03/23 03:33:23 1.7
+++ kcmd.c 1995/03/23 16:17:27
@@ -73,6 +73,7 @@
#define START_PORT 5120 /* arbitrary */
char *default_service = "host";
+char *progname = 0;
extern krb5_cksumtype krb5_kdc_req_sumtype;
@@ -115,6 +116,7 @@
krb5_ccache cc;
krb5_data outbuf;
krb5_flags options = authopts;
+ char *whoami = (progname ? progname : "kcmd");
pid = getpid();
@@ -135,7 +137,7 @@
else
hp = gethostbyaddr((char *) &addr, sizeof(unsigned long), AF_INET);
if (! hp) {
- fprintf(stderr, "kcmd: Unknown host: %s\n", *ahost);
+ fprintf(stderr, "%s: Unknown host: %s\n", whoami, *ahost);
return (-1);
}
@@ -145,20 +147,20 @@
* resolving before we call gethostbyaddr.
*/
if (! (addr_save = malloc(hp->h_length))) {
- fprintf(stderr, "kcmd: no memory\n");
+ fprintf(stderr, "%s: no memory\n", whoami);
return(-1);
}
memcpy(addr_save, hp->h_addr_list[0], hp->h_length);
if ((hp = gethostbyaddr(addr_save, hp->h_length, AF_INET)) == 0) {
krb5_xfree(addr_save);
- fprintf(stderr, "kcmd: cannot reverse resolve %s\n", *ahost);
+ fprintf(stderr, "%s: cannot reverse resolve %s\n", whoami, *ahost);
return (-1);
}
krb5_xfree(addr_save);
host_save = malloc(strlen(hp->h_name) + 1);
if ( host_save == (char *) 0){
- fprintf(stderr,"kcmd: no memory\n");
+ fprintf(stderr,"%s: no memory\n", whoami);
return(-1);
}
@@ -172,19 +174,19 @@
if ( sin_len < 20 ) sin_len = 20;
tmpstr = (char *) malloc(sin_len);
if ( tmpstr == (char *) 0){
- fprintf(stderr,"kcmd: no memory\n");
+ fprintf(stderr,"%s: no memory\n", whoami);
return(-1);
}
if (!(ret_cred = (krb5_creds *)calloc(1,sizeof(*ret_cred)))){
- fprintf(stderr,"kcmd: no memory\n");
+ fprintf(stderr,"%s: no memory\n", whoami);
return(-1);
}
status = krb5_sname_to_principal(host_save,service,KRB5_NT_SRV_HST,
&ret_cred->server);
if (status) {
- fprintf(stderr, "kcmd: krb5_sname_to_principal failed: %s\n",
- error_message(status));
+ fprintf(stderr, "%s: krb5_sname_to_principal failed: %s\n",
+ whoami, error_message(status));
return(-1);
}
@@ -209,9 +211,10 @@
s = getport(&lport);
if (s < 0) {
if (errno == EAGAIN)
- fprintf(stderr, "socket: All ports in use\n");
+ fprintf(stderr, "%s: socket: All ports in use\n", whoami);
else
- perror("kcmd: socket");
+ fprintf(stderr, "%s: socket: %s\n", whoami,
+ error_message(errno));
#ifdef POSIX_SIGNALS
sigprocmask(SIG_SETMASK, &oldmask, (sigset_t*)0);
#else
@@ -252,21 +255,19 @@
}
#if !(defined(tek) || defined(ultrix) || defined(sun) || defined(SYSV))
if (hp->h_addr_list[1] != NULL) {
- int oerrno = errno;
-
fprintf(stderr,
- "connect to address %s: ", inet_ntoa(sin.sin_addr));
- errno = oerrno;
- perror(0);
+ "%s: connect to address %s: %s\n", whoami,
+ inet_ntoa(sin.sin_addr), error_message(errno));
hp->h_addr_list++;
memcpy((caddr_t)&sin.sin_addr,hp->h_addr_list[0],
hp->h_length);
- fprintf(stderr, "Trying %s...\n",
+ fprintf(stderr, "%s: Trying %s...\n", whoami,
inet_ntoa(sin.sin_addr));
continue;
}
#endif /* !(defined(ultrix) || defined(sun)) */
- perror(hp->h_name);
+ fprintf(stderr, "%s: %s: %s\n", whoami, hp->h_name,
+ error_message(errno));
#ifdef POSIX_SIGNALS
sigprocmask(SIG_SETMASK, &oldmask, (sigset_t*)0);
#else
@@ -295,7 +296,8 @@
listen(s2, 1);
(void) sprintf(num, "%d", lport);
if (write(s, num, strlen(num)+1) != strlen(num)+1) {
- perror("write: setting up stderr");
+ fprintf(stderr, "%s: write: setting up stderr: %s\n",
+ whoami, error_message(errno));
(void) close(s2);
status = -1;
goto bad;
@@ -303,7 +305,8 @@
s3 = accept(s2, (struct sockaddr *)&from, &len);
(void) close(s2);
if (s3 < 0) {
- perror("accept");
+ fprintf(stderr, "%s: accept: %s\n", whoami,
+ error_message(errno));
lport = 0;
status = -1;
goto bad;
@@ -313,7 +316,8 @@
if (from.sin_family != AF_INET ||
from.sin_port >= IPPORT_RESERVED) {
fprintf(stderr,
- "socket: protocol failure in circuit setup.\n");
+ "%s: socket: protocol failure in circuit setup.\n",
+ whoami);
goto bad2;
}
}
@@ -325,7 +329,8 @@
sin_len = sizeof (struct sockaddr_in);
if (getsockname(s, (struct sockaddr *)laddr, &sin_len) < 0) {
- perror("getsockname");
+ fprintf(stderr, "%s: getsockname: %s\n", whoami,
+ error_message(errno));
status = -1;
goto bad2;
}
@@ -378,13 +383,15 @@
&error, /* No error return */
&rep_ret);
if (status) {
- printf("Couldn't authenticate to server: %s\n", error_message(status));
+ fprintf(stderr, "%s: Couldn't authenticate to server: %s\n",
+ whoami, error_message(status));
if (error) {
- printf("Server returned error code %d (%s)\n", error->error,
- error_message(ERROR_TABLE_BASE_krb5 + error->error));
+ fprintf(stderr, "%s: Server returned error code %d (%s)\n",
+ whoami, error->error,
+ error_message(ERROR_TABLE_BASE_krb5 + error->error));
if (error->text.length) {
- fprintf(stderr, "Error text sent from server: %s\n",
- error->text.data);
+ fprintf(stderr, "%s: Error text sent from server: %s\n",
+ whoami, error->text.data);
}
krb5_free_error(error);
error = 0;
@@ -409,7 +416,7 @@
/* Forwardable TGT? */
options & OPTS_FORWARDABLE_CREDS,
&outbuf)) {
- fprintf(stderr, "kcmd: Error getting forwarded creds\n");
+ fprintf(stderr, "%s: Error getting forwarded creds\n", whoami);
goto bad2;
}
@@ -425,9 +432,10 @@
if ((rc=read(s, &c, 1)) != 1) {
if (rc==-1) {
- perror(*ahost);
+ fprintf(stderr, "%s: %s: %s\n", whoami, *ahost,
+ error_message(errno));
} else {
- fprintf(stderr,"kcmd: bad connection with remote host\n");
+ fprintf(stderr,"%s: bad connection with remote host\n", whoami);
}
status = -1;
goto bad3;
--- krcp.c 1995/03/20 18:44:20 1.4
+++ krcp.c 1995/03/23 18:26:51
@@ -123,6 +123,11 @@
int userid;
int port;
+#ifdef KERBEROS
+extern
+#endif
+char *progname;
+
struct buffer {
int cnt;
char *buf;
@@ -151,6 +156,10 @@
krb5_error_code status;
char **orig_argv = save_argv(argc, argv);
+ if (strrchr(argv[0], '/'))
+ argv[0] = strrchr(argv[0], '/')+1;
+ progname = argv[0];
+
sp = getservbyname("kshell", "tcp");
krb5_init_ets();
desinbuf.data = des_inbuf;
@@ -161,17 +170,17 @@
#endif /* KERBEROS */
if (sp == NULL) {
#ifdef KERBEROS
- fprintf(stderr, "rcp: kshell/tcp: unknown service\n");
+ fprintf(stderr, "%s: kshell/tcp: unknown service\n", progname);
try_normal(orig_argv);
#else
- fprintf(stderr, "rcp: shell/tcp: unknown service\n");
+ fprintf(stderr, "%s: shell/tcp: unknown service\n", progname);
exit(1);
#endif /* KERBEROS */
}
port = sp->s_port;
pwd = getpwuid(userid = getuid());
if (pwd == 0) {
- fprintf(stderr, "who are you?\n");
+ fprintf(stderr, "%s: who are you?\n", progname);
exit(1);
}
@@ -196,7 +205,7 @@
if (argc == 0)
usage();
if(!(krb_realm = (char *)malloc(strlen(*argv) + 1))){
- fprintf(stderr, "rcp: Cannot malloc.\n");
+ fprintf(stderr, "%s: Cannot malloc.\n", progname);
exit(1);
}
strcpy(krb_realm, *argv);
@@ -351,7 +360,7 @@
if (status != -1)
fprintf(stderr,
"%s: kcmd to host %s failed - %s\n",
- orig_argv[0], host,
+ progname, host,
error_message(status));
try_normal(orig_argv);
}
@@ -439,7 +448,7 @@
if (status) {
fprintf(stderr,
"%s: kcmd to host %s failed - %s\n",
- orig_argv[0], host,
+ progname, host,
error_message(status));
try_normal(orig_argv);
@@ -455,11 +464,15 @@
#else
(void) setuid(0);
if(seteuid(userid)) {
- perror("rcp seteuid user"); errs++; exit(errs);
+ fprintf(stderr, "%s: seteuid user: %s\n", progname,
+ error_message(errno));
+ errs++; exit(errs);
}
sink(1, argv+argc-1);
if(seteuid(0)) {
- perror("rcp seteuid 0"); errs++; exit(errs);
+ fprintf(stderr, "%s: seteuid 0: %s\n", progname,
+ error_message(errno));
+ errs++; exit(errs);
}
#endif
#else
@@ -474,11 +487,15 @@
#else
(void) setuid(0);
if(seteuid(userid)) {
- perror("rcp seteuid user"); errs++; exit(errs);
+ fprintf(stderr, "%s: seteuid user: %s\n", progname,
+ error_message(errno));
+ errs++; exit(errs);
}
sink(1, argv+argc-1);
if(seteuid(0)) {
- perror("rcp seteuid 0"); errs++; exit(errs);
+ fprintf(stderr, "%s: seteuid 0: %s\n", progname,
+ error_message(errno));
+ errs++; exit(errs);
}
#endif
#endif /* KERBEROS */
@@ -540,7 +557,7 @@
} while (*cp);
return (1);
bad:
- fprintf(stderr, "rcp: invalid user name %s\n", cp0);
+ fprintf(stderr, "%s: invalid user name %s\n", progname, cp0);
return (0);
}
@@ -756,7 +773,7 @@
lostconn()
{
if (iamremote == 0)
- fprintf(stderr, "rcp: lost connection\n");
+ fprintf(stderr, "%s: lost connection\n", progname);
exit(1);
}
@@ -1040,9 +1057,10 @@
{
#ifdef KERBEROS
fprintf(stderr,
- "Usage: \trcp [-p] [-x] [-k realm] f1 f2; or:\n\trcp [-r] [-p] [-x] [-k realm] f1 ... fn d2\n");
+ "Usage: \t%s [-p] [-x] [-k realm] f1 f2; or:\n\t%s [-r] [-p] [-x] [-k realm] f1 ... fn d2\n", progname, progname);
#else /* !KERBEROS */
- fputs("usage: rcp [-p] f1 f2; or: rcp [-rp] f1 ... fn d2\n", stderr);
+ fprintf(stderr, "usage: %s [-p] f1 f2; or: rcp [-rp] f1 ... fn d2\n",
+ progname);
#endif
exit(1);
}
@@ -1081,13 +1099,13 @@
#endif
if (!encryptflag) {
- fprintf(stderr,"trying normal rcp (%s)\n", UCB_RCP);
+ fprintf(stderr,"%s: trying normal rcp (%s)\n", progname, UCB_RCP);
fflush(stderr);
/* close all but stdin, stdout, stderr */
for (i = getdtablesize(); i > 2; i--)
(void) close(i);
execv(UCB_RCP, argv);
- perror("exec");
+ fprintf(stderr, "%s: exec: %s\n", progname, error_message(errno));
}
exit(1);
}
@@ -1149,8 +1167,8 @@
if (status = krb5_cc_default(&cc)){
- fprintf(stderr,"rcp: send_auth failed krb5_cc_default : %s\n",
- error_message(status));
+ fprintf(stderr,"%s: send_auth failed krb5_cc_default : %s\n",
+ progname, error_message(status));
exit(1);
}
@@ -1158,15 +1176,15 @@
if (status = krb5_cc_get_principal(cc, &creds.client)){
fprintf(stderr,
- "rcp: send_auth failed krb5_cc_get_principal : %s\n",
- error_message(status));
+ "%s: send_auth failed krb5_cc_get_principal : %s\n",
+ progname, error_message(status));
krb5_cc_close(cc);
exit(1);
}
if (status = krb5_unparse_name(creds.client, &princ)){
- fprintf(stderr,"rcp: send_auth failed krb5_parse_name : %s\n",
- error_message(status));
+ fprintf(stderr,"%s: send_auth failed krb5_parse_name : %s\n",
+ progname, error_message(status));
krb5_cc_close(cc);
exit(1);
}
@@ -1178,8 +1196,8 @@
krb5_princ_realm(creds.client)->data,
0)){
fprintf(stderr,
- "rcp: send_auth failed krb5_build_principal_ext : %s\n",
- error_message(status));
+ "%s: send_auth failed krb5_build_principal_ext : %s\n",
+ progname, error_message(status));
krb5_cc_close(cc);
exit(1);
}
@@ -1187,8 +1205,8 @@
/* Get TGT from credentials cache */
if (status = krb5_get_credentials(KRB5_GC_CACHED, cc, &creds)){
fprintf(stderr,
- "rcp: send_auth failed krb5_get_credentials: %s\n",
- error_message(status));
+ "%s: send_auth failed krb5_get_credentials: %s\n",
+ progname, error_message(status));
krb5_cc_close(cc);
exit(1);
}
@@ -1201,24 +1219,24 @@
status = krb5_write_message((krb5_pointer) &rem, &princ_data);
if (status){
fprintf(stderr,
- "rcp: send_auth failed krb5_write_message: %s\n",
- error_message(status));
+ "%s: send_auth failed krb5_write_message: %s\n",
+ progname, error_message(status));
exit(1);
}
krb5_xfree(princ);
status = krb5_write_message((krb5_pointer) &rem, &creds.ticket);
if (status){
fprintf(stderr,
- "rcp: send_auth failed krb5_write_message: %s\n",
- error_message(status));
+ "%s: send_auth failed krb5_write_message: %s\n",
+ progname, error_message(status));
exit(1);
}
status = krb5_read_message((krb5_pointer) &rem, &reply);
if (status){
fprintf(stderr,
- "rcp: send_auth failed krb5_read_message: %s\n",
- error_message(status));
+ "%s: send_auth failed krb5_read_message: %s\n",
+ progname, error_message(status));
exit(1);
}
@@ -1239,8 +1257,8 @@
&authdat);
krb5_xfree(reply.data);
if (status) {
- fprintf(stderr, "rcp: send_auth failed krb5_rd_req: %s\n",
- error_message(status));
+ fprintf(stderr, "%s: send_auth failed krb5_rd_req: %s\n",
+ progname, error_message(status));
exit(1);
}
@@ -1251,8 +1269,8 @@
krb5_use_keytype(&eblock, session_key->keytype);
if ( status = krb5_process_key(&eblock,
session_key)){
- fprintf(stderr, "rcp: send_auth failed krb5_process_key: %s\n",
- error_message(status));
+ fprintf(stderr, "%s: send_auth failed krb5_process_key: %s\n",
+ progname, error_message(status));
exit(1);
}
--- krlogin.c 1995/03/23 03:37:32 1.11
+++ krlogin.c 1995/03/23 17:41:36
@@ -235,6 +235,10 @@
char *host=0; /* external, so it can be
reached from confirm_death() */
+#ifdef KERBEROS
+extern
+#endif
+char *progname;
/*
@@ -335,6 +339,7 @@
if (strrchr(argv[0], '/'))
argv[0] = strrchr(argv[0], '/')+1;
+ progname = argv[0];
if ( argc < 2 ) goto usage;
argc--;
@@ -418,11 +423,12 @@
argv++, argc--;
if (argc == 0) {
fprintf(stderr,
- "rlogin: -k flag must be followed with a realm name.\n");
+ "%s: -k flag must be followed with a realm name.\n",
+ progname);
exit (1);
}
if(!(krb_realm = (char *)malloc(strlen(*argv) + 1))){
- fprintf(stderr, "rlogin: Cannot malloc.\n");
+ fprintf(stderr, "%s: Cannot malloc.\n", progname);
exit(1);
}
strcpy(krb_realm, *argv);
@@ -438,7 +444,7 @@
#endif
if (argc > 0 && !strcmp(*argv, "-f")) {
if (Fflag) {
- fprintf(stderr, "rlogin: Only one of -f and -F allowed\n");
+ fprintf(stderr, "%s: Only one of -f and -F allowed\n", progname);
goto usage;
}
fflag++;
@@ -447,7 +453,7 @@
}
if (argc > 0 && !strcmp(*argv, "-F")) {
if (fflag) {
- fprintf(stderr, "rlogin: Only one of -f and -F allowed\n");
+ fprintf(stderr, "%s: Only one of -f and -F allowed\n", progname);
goto usage;
}
Fflag++;
@@ -461,7 +467,7 @@
goto usage;
pwd = getpwuid(getuid());
if (pwd == 0) {
- fprintf(stderr, "Who are you?\n");
+ fprintf(stderr, "%s: Who are you?\n", progname);
exit(1);
}
#ifdef KERBEROS
@@ -478,7 +484,7 @@
else
sp = getservbyname("klogin","tcp");
if (sp == 0) {
- fprintf(stderr, "rlogin: %s/tcp: unknown service\n",
+ fprintf(stderr, "%s: %s/tcp: unknown service\n", progname,
encrypt_flag ? "eklogin" : "klogin");
try_normal(orig_argv);
@@ -486,7 +492,7 @@
#else
sp = getservbyname("login", "tcp");
if (sp == 0) {
- fprintf(stderr, "rlogin: login/tcp: unknown service\n");
+ fprintf(stderr, "%s: login/tcp: unknown service\n", progname);
exit(2);
}
#endif /* KERBEROS */
@@ -574,7 +580,7 @@
/* kcmd returns either -1 *or* a com_err code; ick */
if (status != -1)
fprintf(stderr,
- "%s: kcmd to host %s failed - %s\n",orig_argv[0], host,
+ "%s: kcmd to host %s failed - %s\n", progname, host,
error_message(status));
try_normal(orig_argv);
}
@@ -585,7 +591,7 @@
if ( status = krb5_process_key(&eblock,&cred->keyblock)) {
fprintf(stderr,
"%s: Cannot process session key : %s.\n",
- orig_argv[0], error_message(status));
+ progname, error_message(status));
exit(1);
}
#else
@@ -628,10 +634,11 @@
#endif /* hpux */
if (options & SO_DEBUG &&
setsockopt(rem, SOL_SOCKET, SO_DEBUG, (char*)&on, sizeof (on)) < 0)
- perror("rlogin: setsockopt (SO_DEBUG)");
+ fprintf(stderr, "%s: setsockopt (SO_DEBUG): %s\n",
+ progname, error_message(errno));
uid = getuid();
if (setuid(uid) < 0) {
- perror("rlogin: setuid");
+ fprintf(stderr, "%s: setuid: %s\n", progname, error_message(errno));
exit(1);
}
flowcontrol = flow; /* Set up really correct non-volatile variable */
@@ -640,7 +647,8 @@
usage:
#ifdef KERBEROS
fprintf (stderr,
- "usage: rlogin host [-option] [-option...] [-k realm ] [-t ttytype] [-l username]\n");
+ "usage: %s host [-option] [-option...] [-k realm ] [-t ttytype] [-l username]\n",
+ progname);
fprintf (stderr, " where option is e, 7, 8, noflow, n, a, %sf, F, or c\n",
#ifdef NX
""
@@ -650,7 +658,8 @@
);
#else /* !KERBEROS */
fprintf (stderr,
- "usage: rlogin host [-option] [-option...] [-t ttytype] [-l username]\n");
+ "usage: %s host [-option] [-option...] [-t ttytype] [-l username]\n",
+ progname);
fprintf (stderr, " where option is e, 7, 8, noflow, n, a, or c\n");
#endif /* KERBEROS */
exit(1);
@@ -788,7 +797,7 @@
setsignal(SIGQUIT,exit);
child = fork();
if (child == -1) {
- perror("rlogin: fork");
+ fprintf(stderr, "%s: fork: %s\n", progname, error_message(errno));
done(1);
}
if (child == 0) {
@@ -974,7 +983,8 @@
break;
else
if (n < 0) {
- perror("select");
+ fprintf(stderr, "%s: select: %s\n", progname,
+ error_message(errno));
break;
}
}
@@ -1256,7 +1266,8 @@
#endif
for (;;) {
if (ioctl(rem, SIOCATMARK, &atmark) < 0) {
- perror("ioctl");
+ fprintf(stderr, "%s: ioctl: %s\n", progname,
+ error_message(errno));
break;
}
if (atmark)
@@ -1347,7 +1358,8 @@
if (rcvcnt < 0) {
if (errno == EINTR)
continue;
- perror("read");
+ fprintf(stderr, "%s: read: %s\n", progname,
+ error_message(errno));
return (-1);
}
}
@@ -1541,7 +1553,7 @@
if (encrypt_flag)
exit(1);
- fprintf(stderr,"trying normal rlogin (%s)\n",
+ fprintf(stderr,"%s: trying normal rlogin (%s)\n", progname,
UCB_RLOGIN);
fflush(stderr);
@@ -1554,7 +1566,7 @@
argv++;
execv(UCB_RLOGIN, argv);
- perror("exec");
+ fprintf(stderr, "%s: exec: %s\n", progname, error_message(errno));
exit(1);
}
@@ -1610,14 +1622,14 @@
if (net_len <= 0 || net_len > sizeof(des_inbuf)) {
/* preposterous length; assume out-of-sync; only
recourse is to close connection, so return 0 */
- fprintf(stderr,"Read size problem.\n");
+ fprintf(stderr,"%s: Read size problem.\n", progname);
return(0);
}
if ((cc = krb5_net_read(fd, desinbuf.data, net_len)) != net_len) {
/* pipe must have closed, return 0 */
fprintf(stderr,
- "Read error: length received %d != expected %d.\n",
- cc,net_len);
+ "%s: Read error: length received %d != expected %d.\n",
+ progname, cc,net_len);
return(0);
}
/* decrypt info */
@@ -1625,7 +1637,7 @@
(krb5_pointer) storage,
net_len,
&eblock, 0))) {
- fprintf(stderr,"Cannot decrypt data from network.\n");
+ fprintf(stderr,"%s: Cannot decrypt data from network.\n", progname);
return(0);
}
store_ptr = storage;
@@ -1658,7 +1670,7 @@
desoutbuf.length = krb5_encrypt_size(len,eblock.crypto_entry);
if (desoutbuf.length > sizeof(des_outbuf)){
- fprintf(stderr,"Write size problem.\n");
+ fprintf(stderr,"%s: Write size problem.\n", progname);
return(-1);
}
if (( krb5_encrypt((krb5_pointer)buf,
@@ -1666,7 +1678,7 @@
len,
&eblock,
0))){
- fprintf(stderr,"Write encrypt problem.\n");
+ fprintf(stderr,"%s: Write encrypt problem.\n", progname);
return(-1);
}
@@ -1677,7 +1689,7 @@
(void) write(fd, &net_len, sizeof(net_len));
#endif
if (write(fd, desoutbuf.data,desoutbuf.length) != desoutbuf.length){
- fprintf(stderr,"Could not write out all data.\n");
+ fprintf(stderr,"%s: Could not write out all data.\n", progname);
return(-1);
}
else return(len);
--- krsh.c 1995/03/14 16:02:58 1.6
+++ krsh.c 1995/03/23 17:18:54
@@ -76,6 +76,11 @@
#define UCB_RSH "/usr/ucb/rsh"
#endif
+#ifdef KERBEROS
+extern
+#endif
+char *progname;
+
#ifndef RLOGIN_PROGRAM
#ifdef KERBEROS
#define RLOGIN_PROGRAM KRB5_PATH_RLOGIN
@@ -114,6 +119,7 @@
if (strrchr(argv[0], '/'))
argv[0] = strrchr(argv[0], '/')+1;
+ progname = argv[0];
if ( argc < 2 ) goto usage;
argc--;
@@ -155,11 +161,12 @@
if (argc > 0 && !strcmp(*argv, "-k")) {
argv++, argc--;
if (argc == 0) {
- fprintf(stderr, "rsh(kerberos): -k flag must have a realm after it.\n");
+ fprintf(stderr, "%s: -k flag must have a realm after it.\n",
+ progname);
exit (1);
}
if(!(krb_realm = (char *)malloc(strlen(*argv) + 1))){
- fprintf(stderr, "rsh(kerberos): Cannot malloc.\n");
+ fprintf(stderr, "%s: Cannot malloc.\n", progname);
exit(1);
}
strcpy(krb_realm, *argv);
@@ -176,7 +183,8 @@
}
if (argc > 0 && !strncmp(*argv, "-f", 2)) {
if (Fflag) {
- fprintf(stderr, "rsh: Only one of -f and -F allowed\n");
+ fprintf(stderr, "%s: Only one of -f and -F allowed\n",
+ progname);
goto usage;
}
fflag++;
@@ -185,7 +193,8 @@
}
if (argc > 0 && !strncmp(*argv, "-F", 2)) {
if (fflag) {
- fprintf(stderr, "rsh: Only one of -f and -F allowed\n");
+ fprintf(stderr, "%s: Only one of -f and -F allowed\n",
+ progname);
goto usage;
}
Fflag++;
@@ -249,7 +258,10 @@
goto usage;
if (argv[0] == 0) {
execv(RLOGIN_PROGRAM, argv0);
- perror(RLOGIN_PROGRAM);
+ /* XXX No error_message() if not KERBEROS. But is there really
+ any chance at all that this file will compile without KERBEROS? */
+ fprintf(stderr, "%s: %s: %s\n", progname,
+ RLOGIN_PROGRAM, error_message(errno));
exit(1);
}
@@ -260,13 +272,13 @@
if (xflag)
{
fprintf (stderr, "%s: Encrypted rsh is not yet available.\n",
- argv0[0]);
+ progname);
return 1;
}
pwd = getpwuid(getuid());
if (pwd == 0) {
- fprintf(stderr, "who are you?\n");
+ fprintf(stderr, "%s: who are you?\n", progname);
exit(1);
}
cc = 0;
@@ -287,10 +299,10 @@
#endif /* KERBEROS */
if (sp == 0) {
#ifdef KERBEROS
- fprintf(stderr, "rsh: kshell/tcp: unknown service\n");
+ fprintf(stderr, "%s: kshell/tcp: unknown service\n", progname);
try_normal(argv0);
#else
- fprintf(stderr, "rsh: shell/tcp: unknown service\n");
+ fprintf(stderr, "%s: shell/tcp: unknown service\n", progname);
#endif /* KERBEROS */
exit(1);
}
@@ -323,7 +335,7 @@
if (status != -1)
/* check NO_TKT_FILE or equivalent... */
fprintf(stderr,
- "%s: kcmd to host %s failed - %s\n",argv0[0], host,
+ "%s: kcmd to host %s failed - %s\n", progname, host,
error_message(status));
try_normal(argv0);
}
@@ -334,16 +346,18 @@
exit(1);
#endif /* KERBEROS */
if (rfd2 < 0) {
- fprintf(stderr, "rsh: can't establish stderr\n");
+ fprintf(stderr, "%s: can't establish stderr\n", progname);
exit(2);
}
if (options & SO_DEBUG) {
if (setsockopt(rem, SOL_SOCKET, SO_DEBUG, (char *) &one,
sizeof (one)) < 0)
- perror("setsockopt (stdin)");
+ fprintf(stderr, "%s: setsockopt (stdin): %s\n", progname,
+ error_message(errno));
if (setsockopt(rfd2, SOL_SOCKET, SO_DEBUG, (char *) &one,
sizeof (one)) < 0)
- perror("setsockopt (stderr)");
+ fprintf(stderr, "%s: setsockopt (stderr): %s\n", progname,
+ error_message(errno));
}
(void) setuid(getuid());
#ifdef POSIX_SIGNALS
@@ -368,7 +382,8 @@
if (nflag == 0) {
pid = fork();
if (pid < 0) {
- perror("fork");
+ fprintf(stderr, "%s: fork: %s\n", progname,
+ error_message(errno));
exit(1);
}
}
@@ -387,7 +402,8 @@
rembits = 1<<rem;
if (select(16, 0, &rembits, 0, 0) < 0) {
if (errno != EINTR) {
- perror("select");
+ fprintf(stderr, "%s: select: %s\n", progname,
+ error_message(errno));
exit(1);
}
goto rewrite;
@@ -420,7 +436,8 @@
ready = readfrom;
if (select(16, &ready, 0, 0, 0) < 0) {
if (errno != EINTR) {
- perror("select");
+ fprintf(stderr, "%s: select: %s\n", progname,
+ error_message(errno));
exit(1);
}
continue;
@@ -449,9 +466,11 @@
exit(0);
usage:
fprintf(stderr,
- "usage: \trsh host [ -l login ] [ -n ] [ -f / -F] command\n");
+ "usage: \t%s host [ -l login ] [ -n ] [ -f / -F] command\n",
+ progname);
fprintf(stderr,
- "OR \trsh [ -l login ] [-n ] [ -f / -F ] host command\n");
+ "OR \t%s [ -l login ] [-n ] [ -f / -F ] host command\n",
+ progname);
exit(1);
}
@@ -492,11 +511,12 @@
if (!strcmp(host, "rsh"))
argv++;
- fprintf(stderr,"trying normal rsh (%s)\n",
- UCB_RSH);
+ fprintf(stderr,"%s: trying normal rsh (%s)\n",
+ progname, UCB_RSH);
fflush(stderr);
execv(UCB_RSH, argv);
- perror("exec");
+ fprintf(stderr, "%s: exec: %s\n", progname,
+ error_message(errno));
exit(1);
}
#endif /* KERBEROS */