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