+
+#ifdef KERBEROS
+old_warning(str)
+ char *str;
+{
+ (void)fprintf(stderr, "rcp: warning: %s, using standard rcp\n", str);
+}
+
+int
+kerberos(host, bp, locuser, user)
+
+ char **host, *bp, *locuser, *user;
+{
+ struct servent *sp;
+
+again:
+ if (use_kerberos) {
+ rem = KSUCCESS;
+ errno = 0;
+ if (dest_realm == NULL)
+ dest_realm = krb_realmofhost(*host);
+
+#ifdef CRYPT
+ if (encrypt)
+ rem = krcmd_mutual(
+ host, port,
+ user, bp, 0,
+ dest_realm,
+ &cred, schedule);
+ else
+#endif
+ rem = krcmd(
+ host, port,
+ user, bp, 0, dest_realm);
+
+ if (rem < 0) {
+ use_kerberos = 0;
+ sp = getservbyname("shell", "tcp");
+ if (sp == NULL) {
+ (void)fprintf(stderr,
+ "rcp: unknown service shell/tcp\n");
+ exit(1);
+ }
+ if (errno == ECONNREFUSED)
+ old_warning(
+ "remote host doesn't support Kerberos");
+
+ if (errno == ENOENT)
+ old_warning(
+ "Can't provide Kerberos auth data");
+ port = sp->s_port;
+ goto again;
+ }
+ } else {
+#ifdef CRYPT
+ if (encrypt) {
+ fprintf(stderr,
+ "The -x option requires Kerberos authentication\n");
+ exit(1);
+ }
+#endif
+ rem = rcmd(host, sp->s_port, locuser, user, bp, 0);
+ }
+ return(rem);
+}
+#endif /* KERBEROS */