138679Skfall /*
2*62213Sbostic * Copyright (c) 1989, 1993
3*62213Sbostic * The Regents of the University of California. All rights reserved.
438679Skfall *
542761Sbostic * %sccs.include.redist.c%
638679Skfall */
738679Skfall
838679Skfall #ifndef lint
9*62213Sbostic static char sccsid[] = "@(#)krcmd.c 8.1 (Berkeley) 06/06/93";
1038679Skfall #endif /* not lint */
1138679Skfall
1242763Sbostic /*
1358470Sbostic * $Source: /usr/src/usr.bin/rlogin/RCS/krcmd.c,v $
1442763Sbostic * $Header: /mit/kerberos/ucb/mit/kcmd/RCS/krcmd.c,v 5.1
1542763Sbostic * 89/07/25 15:38:44 kfall Exp Locker: kfall $
1642763Sbostic * static char *rcsid_kcmd_c =
1742763Sbostic * "$Header: /mit/kerberos/ucb/mit/kcmd/RCS/krcmd.c,v 5.1 89/07/25 15:38:44
1842763Sbostic * kfall Exp Locker: kfall $";
1942763Sbostic */
2042763Sbostic
2145256Smckusick #ifdef KERBEROS
2238679Skfall #include <sys/types.h>
2358470Sbostic #ifdef CRYPT
2458470Sbostic #include <sys/socket.h>
2558470Sbostic #endif
2658470Sbostic
2758470Sbostic #include <netinet/in.h>
2858470Sbostic
2941760Skfall #include <kerberosIV/des.h>
3040852Sbostic #include <kerberosIV/krb.h>
3138679Skfall
3258470Sbostic #include <stdio.h>
3358470Sbostic
3438679Skfall #define SERVICE_NAME "rcmd"
3538679Skfall
3658470Sbostic int kcmd __P((int *, char **, u_short, char *, char *, char *, int *,
3758470Sbostic KTEXT, char *, char *, CREDENTIALS *, Key_schedule, MSG_DAT *,
3858470Sbostic struct sockaddr_in *, struct sockaddr_in *, long));
3958470Sbostic
4040852Sbostic /*
4140852Sbostic * krcmd: simplified version of Athena's "kcmd"
4240852Sbostic * returns a socket attached to the destination, -1 or krb error on error
4340852Sbostic * if fd2p is non-NULL, another socket is filled in for it
4440852Sbostic */
4540852Sbostic
4638679Skfall int
krcmd(ahost,rport,remuser,cmd,fd2p,realm)4738679Skfall krcmd(ahost, rport, remuser, cmd, fd2p, realm)
4838679Skfall char **ahost;
4938679Skfall u_short rport;
5038679Skfall char *remuser, *cmd;
5138679Skfall int *fd2p;
5238679Skfall char *realm;
5338679Skfall {
5440852Sbostic int sock = -1, err = 0;
5538679Skfall KTEXT_ST ticket;
5640852Sbostic long authopts = 0L;
5738679Skfall
5838679Skfall err = kcmd(
5938679Skfall &sock,
6038679Skfall ahost,
6138679Skfall rport,
6238679Skfall NULL, /* locuser not used */
6338679Skfall remuser,
6438679Skfall cmd,
6538679Skfall fd2p,
6638679Skfall &ticket,
6738679Skfall SERVICE_NAME,
6838679Skfall realm,
6940852Sbostic (CREDENTIALS *) NULL, /* credentials not used */
7040852Sbostic (bit_64 *) NULL, /* key schedule not used */
7140852Sbostic (MSG_DAT *) NULL, /* MSG_DAT not used */
7240852Sbostic (struct sockaddr_in *) NULL, /* local addr not used */
7340852Sbostic (struct sockaddr_in *) NULL, /* foreign addr not used */
7438679Skfall authopts
7538679Skfall );
7638679Skfall
7740852Sbostic if (err > KSUCCESS && err < MAX_KRB_ERRORS) {
7838679Skfall fprintf(stderr, "krcmd: %s\n", krb_err_txt[err]);
7938679Skfall return(-1);
8038679Skfall }
8140852Sbostic if (err < 0)
8240852Sbostic return(-1);
8338679Skfall return(sock);
8438679Skfall }
8538679Skfall
8658470Sbostic #ifdef CRYPT
8758470Sbostic int
krcmd_mutual(ahost,rport,remuser,cmd,fd2p,realm,cred,sched)8858470Sbostic krcmd_mutual(ahost, rport, remuser, cmd, fd2p, realm, cred, sched)
8958470Sbostic char **ahost;
9058470Sbostic u_short rport;
9158470Sbostic char *remuser, *cmd;
9258470Sbostic int *fd2p;
9358470Sbostic char *realm;
9458470Sbostic CREDENTIALS *cred;
9558470Sbostic Key_schedule sched;
9658470Sbostic {
9758470Sbostic int sock, err;
9858470Sbostic KTEXT_ST ticket;
9958470Sbostic MSG_DAT msg_dat;
10058470Sbostic struct sockaddr_in laddr, faddr;
10158470Sbostic long authopts = KOPT_DO_MUTUAL;
10258470Sbostic
10358470Sbostic err = kcmd(
10458470Sbostic &sock,
10558470Sbostic ahost,
10658470Sbostic rport,
10758470Sbostic NULL, /* locuser not used */
10858470Sbostic remuser,
10958470Sbostic cmd,
11058470Sbostic fd2p,
11158470Sbostic &ticket,
11258470Sbostic SERVICE_NAME,
11358470Sbostic realm,
11458470Sbostic cred, /* filled in */
11558470Sbostic sched, /* filled in */
11658470Sbostic &msg_dat, /* filled in */
11758470Sbostic &laddr, /* filled in */
11858470Sbostic &faddr, /* filled in */
11958470Sbostic authopts
12058470Sbostic );
12158470Sbostic
12258470Sbostic if (err > KSUCCESS && err < MAX_KRB_ERRORS) {
12358470Sbostic fprintf(stderr, "krcmd_mutual: %s\n", krb_err_txt[err]);
12458470Sbostic return(-1);
12558470Sbostic }
12658470Sbostic
12758470Sbostic if (err < 0)
12858470Sbostic return (-1);
12958470Sbostic return(sock);
13058470Sbostic }
13158470Sbostic #endif /* CRYPT */
13245256Smckusick #endif /* KERBEROS */
133