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