Annotation of src/usr.bin/rlogin/krcmd.c, Revision 1.1.1.1
1.1 deraadt 1: /* $NetBSD: krcmd.c,v 1.2 1995/03/21 07:58:36 cgd Exp $ */
2:
3: /*
4: * Copyright (c) 1989, 1993
5: * The Regents of the University of California. All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. All advertising materials mentioning features or use of this software
16: * must display the following acknowledgement:
17: * This product includes software developed by the University of
18: * California, Berkeley and its contributors.
19: * 4. Neither the name of the University nor the names of its contributors
20: * may be used to endorse or promote products derived from this software
21: * without specific prior written permission.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33: * SUCH DAMAGE.
34: */
35:
36: #ifndef lint
37: #if 0
38: static char sccsid[] = "@(#)krcmd.c 8.1 (Berkeley) 6/6/93";
39: #else
40: static char rcsid[] = "$NetBSD: krcmd.c,v 1.2 1995/03/21 07:58:36 cgd Exp $";
41: #endif
42: #endif /* not lint */
43:
44: /*
45: * $Source: /a/cvsroot/src/usr.bin/rlogin/krcmd.c,v
46: * $Header: /mit/kerberos/ucb/mit/kcmd/RCS/krcmd.c,v 5.1
47: * 89/07/25 15:38:44 kfall Exp Locker: kfall
48: * static char *rcsid_kcmd_c =
49: * "$Header: /mit/kerberos/ucb/mit/kcmd/RCS/krcmd.c,v 5.1 89/07/25 15:38:44
50: * kfall Exp Locker: kfall ";
51: */
52:
53: #ifdef KERBEROS
54: #include <sys/types.h>
55: #ifdef CRYPT
56: #include <sys/socket.h>
57: #endif
58:
59: #include <netinet/in.h>
60:
61: #include <kerberosIV/des.h>
62: #include <kerberosIV/krb.h>
63:
64: #include <stdio.h>
65:
66: #define SERVICE_NAME "rcmd"
67:
68: int kcmd __P((int *, char **, u_short, char *, char *, char *, int *,
69: KTEXT, char *, char *, CREDENTIALS *, Key_schedule, MSG_DAT *,
70: struct sockaddr_in *, struct sockaddr_in *, long));
71:
72: /*
73: * krcmd: simplified version of Athena's "kcmd"
74: * returns a socket attached to the destination, -1 or krb error on error
75: * if fd2p is non-NULL, another socket is filled in for it
76: */
77:
78: int
79: krcmd(ahost, rport, remuser, cmd, fd2p, realm)
80: char **ahost;
81: u_short rport;
82: char *remuser, *cmd;
83: int *fd2p;
84: char *realm;
85: {
86: int sock = -1, err = 0;
87: KTEXT_ST ticket;
88: long authopts = 0L;
89:
90: err = kcmd(
91: &sock,
92: ahost,
93: rport,
94: NULL, /* locuser not used */
95: remuser,
96: cmd,
97: fd2p,
98: &ticket,
99: SERVICE_NAME,
100: realm,
101: (CREDENTIALS *) NULL, /* credentials not used */
102: (bit_64 *) NULL, /* key schedule not used */
103: (MSG_DAT *) NULL, /* MSG_DAT not used */
104: (struct sockaddr_in *) NULL, /* local addr not used */
105: (struct sockaddr_in *) NULL, /* foreign addr not used */
106: authopts
107: );
108:
109: if (err > KSUCCESS && err < MAX_KRB_ERRORS) {
110: fprintf(stderr, "krcmd: %s\n", krb_err_txt[err]);
111: return(-1);
112: }
113: if (err < 0)
114: return(-1);
115: return(sock);
116: }
117:
118: #ifdef CRYPT
119: int
120: krcmd_mutual(ahost, rport, remuser, cmd, fd2p, realm, cred, sched)
121: char **ahost;
122: u_short rport;
123: char *remuser, *cmd;
124: int *fd2p;
125: char *realm;
126: CREDENTIALS *cred;
127: Key_schedule sched;
128: {
129: int sock, err;
130: KTEXT_ST ticket;
131: MSG_DAT msg_dat;
132: struct sockaddr_in laddr, faddr;
133: long authopts = KOPT_DO_MUTUAL;
134:
135: err = kcmd(
136: &sock,
137: ahost,
138: rport,
139: NULL, /* locuser not used */
140: remuser,
141: cmd,
142: fd2p,
143: &ticket,
144: SERVICE_NAME,
145: realm,
146: cred, /* filled in */
147: sched, /* filled in */
148: &msg_dat, /* filled in */
149: &laddr, /* filled in */
150: &faddr, /* filled in */
151: authopts
152: );
153:
154: if (err > KSUCCESS && err < MAX_KRB_ERRORS) {
155: fprintf(stderr, "krcmd_mutual: %s\n", krb_err_txt[err]);
156: return(-1);
157: }
158:
159: if (err < 0)
160: return (-1);
161: return(sock);
162: }
163: #endif /* CRYPT */
164: #endif /* KERBEROS */