xref: /titanic_44/usr/src/cmd/cmd-inet/common/kcmd.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef	_KCMD_H
28*7c478bd9Sstevel@tonic-gate #define	_KCMD_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
33*7c478bd9Sstevel@tonic-gate extern "C" {
34*7c478bd9Sstevel@tonic-gate #endif
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #define	OPTS_FORWARD_CREDS		0x00000002
37*7c478bd9Sstevel@tonic-gate #define	OPTS_FORWARDABLE_CREDS		0x00000001
38*7c478bd9Sstevel@tonic-gate 
39*7c478bd9Sstevel@tonic-gate #define	SERVER	0
40*7c478bd9Sstevel@tonic-gate #define	CLIENT	1
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate enum kcmd_proto {
43*7c478bd9Sstevel@tonic-gate 	/*
44*7c478bd9Sstevel@tonic-gate 	 * Old protocol: DES encryption only.  No subkeys.
45*7c478bd9Sstevel@tonic-gate 	 * No protection for cleartext length.  No ivec supplied.
46*7c478bd9Sstevel@tonic-gate 	 * OOB hacks used for rlogin.  Checksum may be omitted at
47*7c478bd9Sstevel@tonic-gate 	 * connection startup.
48*7c478bd9Sstevel@tonic-gate 	 */
49*7c478bd9Sstevel@tonic-gate 	KCMD_OLD_PROTOCOL = 1,
50*7c478bd9Sstevel@tonic-gate 	/*
51*7c478bd9Sstevel@tonic-gate 	 * New protocol: Any encryption scheme.  Client-generated
52*7c478bd9Sstevel@tonic-gate 	 * subkey required.  Prepend cleartext-length to cleartext
53*7c478bd9Sstevel@tonic-gate 	 * data (but don't include it in count).  Starting ivec defined,
54*7c478bd9Sstevel@tonic-gate 	 * chained.  In-band signalling.  Checksum required.
55*7c478bd9Sstevel@tonic-gate 	 */
56*7c478bd9Sstevel@tonic-gate 	KCMD_NEW_PROTOCOL,
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate 	/*
59*7c478bd9Sstevel@tonic-gate 	 * Hack: Get credentials, and use the old protocol iff the session
60*7c478bd9Sstevel@tonic-gate 	 * key type is single-DES.
61*7c478bd9Sstevel@tonic-gate 	 */
62*7c478bd9Sstevel@tonic-gate 	KCMD_PROTOCOL_COMPAT_HACK,
63*7c478bd9Sstevel@tonic-gate 	/* Using Kerberos version 4.  */
64*7c478bd9Sstevel@tonic-gate 	KCMD_V4_PROTOCOL,
65*7c478bd9Sstevel@tonic-gate 	KCMD_UNKNOWN_PROTOCOL
66*7c478bd9Sstevel@tonic-gate };
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate #define	SOCK_FAMILY(ss) ((ss).ss_family)
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate #define	SOCK_PORT(ss) ((ss).ss_family == AF_INET6 ? \
71*7c478bd9Sstevel@tonic-gate ((struct sockaddr_in6 *)&(ss))->sin6_port : \
72*7c478bd9Sstevel@tonic-gate ((struct sockaddr_in *)&(ss))->sin_port)
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate #define	SOCK_ADDR(ss) ((ss).ss_family == AF_INET6 ? \
75*7c478bd9Sstevel@tonic-gate (void *)&((struct sockaddr_in6 *)&(ss))->sin6_addr : \
76*7c478bd9Sstevel@tonic-gate (void *)&((struct sockaddr_in *)&(ss))->sin_addr)
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate #define	SET_SOCK_FAMILY(ss, family) (SOCK_FAMILY(ss) = (family))
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate #define	SET_SOCK_PORT(ss, port) \
81*7c478bd9Sstevel@tonic-gate 	((ss).ss_family == AF_INET6 ? \
82*7c478bd9Sstevel@tonic-gate 	(((struct sockaddr_in6 *)&(ss))->sin6_port = (port)) : \
83*7c478bd9Sstevel@tonic-gate 	(((struct sockaddr_in *)&(ss))->sin_port = (port)))
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate #define	SET_SOCK_ADDR4(ss, addr) ((void)(sock_set_inaddr(&(ss), (addr))))
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate #define	SET_SOCK_ADDR_ANY(ss) \
88*7c478bd9Sstevel@tonic-gate 	((void) ((ss).ss_family == AF_INET6 ? \
89*7c478bd9Sstevel@tonic-gate 	(void) (((struct sockaddr_in6 *)&(ss))->sin6_addr = in6addr_any) : \
90*7c478bd9Sstevel@tonic-gate 	(void) (((struct sockaddr_in *)&(ss))->sin_addr.s_addr = \
91*7c478bd9Sstevel@tonic-gate 	htonl(INADDR_ANY))))
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate /*
94*7c478bd9Sstevel@tonic-gate  * Prototypes for functions in 'kcmd.c'
95*7c478bd9Sstevel@tonic-gate  */
96*7c478bd9Sstevel@tonic-gate char *strsave(char *sp);
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate int kcmd(int *sock, char **ahost, ushort_t rport, char *locuser,
99*7c478bd9Sstevel@tonic-gate 	char *remuser, char *cmd, int *fd2p, char *service, char *realm,
100*7c478bd9Sstevel@tonic-gate 	krb5_context bsd_context, krb5_auth_context *authconp,
101*7c478bd9Sstevel@tonic-gate 	krb5_creds **cred, krb5_int32 *seqno, krb5_int32 *server_seqno,
102*7c478bd9Sstevel@tonic-gate 	krb5_flags authopts,
103*7c478bd9Sstevel@tonic-gate 	int anyport, enum kcmd_proto *kcmd_proto);
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate krb5_error_code rd_and_store_for_creds(krb5_context context,
106*7c478bd9Sstevel@tonic-gate 				    krb5_auth_context auth_context,
107*7c478bd9Sstevel@tonic-gate 				    krb5_data *inbuf,
108*7c478bd9Sstevel@tonic-gate 				    krb5_ticket *ticket,
109*7c478bd9Sstevel@tonic-gate 				    char *lusername,
110*7c478bd9Sstevel@tonic-gate 				    krb5_ccache *ccache);
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate void init_encrypt(int, krb5_context, enum kcmd_proto,
113*7c478bd9Sstevel@tonic-gate 			krb5_data *, krb5_data *,
114*7c478bd9Sstevel@tonic-gate 			int, krb5_encrypt_block *);
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate int desread(int, char *, int, int);
117*7c478bd9Sstevel@tonic-gate int deswrite(int, char *, int, int);
118*7c478bd9Sstevel@tonic-gate 
119*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
120*7c478bd9Sstevel@tonic-gate }
121*7c478bd9Sstevel@tonic-gate #endif
122*7c478bd9Sstevel@tonic-gate 
123*7c478bd9Sstevel@tonic-gate #endif /* _KCMD_H */
124