No empty .Rs/.Re
[netbsd-mini2440.git] / crypto / dist / heimdal / appl / kx / kx.h
blob7e5667d80f2180e2a8a350a5f8881dedd94c91c8
1 /*
2 * Copyright (c) 1995 - 2001 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * 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.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
34 /* $Heimdal: kx.h 20452 2007-04-19 20:04:19Z lha $
35 $NetBSD$ */
37 #ifdef HAVE_CONFIG_H
38 #include "config.h"
39 #endif /* HAVE_CONFIG_H */
41 #include <stdio.h>
42 #include <stdarg.h>
43 #include <stdlib.h>
44 #include <string.h>
45 #include <signal.h>
46 #include <errno.h>
47 #ifdef HAVE_UNISTD_H
48 #include <unistd.h>
49 #endif
50 #ifdef HAVE_PWD_H
51 #include <pwd.h>
52 #endif
53 #ifdef HAVE_GRP_H
54 #include <grp.h>
55 #endif
56 #ifdef HAVE_SYSLOG_H
57 #include <syslog.h>
58 #endif
59 #ifdef HAVE_SYS_TYPES_H
60 #include <sys/types.h>
61 #endif
62 #ifdef TIME_WITH_SYS_TIME
63 #include <sys/time.h>
64 #include <time.h>
65 #elif defined(HAVE_SYS_TIME_H)
66 #include <sys/time.h>
67 #else
68 #include <time.h>
69 #endif
70 #ifdef HAVE_SYS_RESOURCE_H
71 #include <sys/resource.h>
72 #endif
73 #ifdef HAVE_SYS_SELECT_H
74 #include <sys/select.h>
75 #endif
76 #ifdef HAVE_SYS_WAIT_H
77 #include <sys/wait.h>
78 #endif
79 #ifdef HAVE_SYS_STAT_H
80 #include <sys/stat.h>
81 #endif
82 #ifdef HAVE_SYS_SOCKET_H
83 #include <sys/socket.h>
84 #endif
85 #ifdef HAVE_NETINET_IN_H
86 #include <netinet/in.h>
87 #endif
88 #ifdef HAVE_NETINET_TCP_H
89 #include <netinet/tcp.h>
90 #endif
91 #ifdef HAVE_ARPA_INET_H
92 #include <arpa/inet.h>
93 #endif
94 #ifdef HAVE_NETDB_H
95 #include <netdb.h>
96 #endif
97 #ifdef HAVE_SYS_UN_H
98 #include <sys/un.h>
99 #endif
100 #include <X11/X.h>
101 #include <X11/Xlib.h>
102 #include <X11/Xauth.h>
104 #ifdef HAVE_SYS_STREAM_H
105 #include <sys/stream.h>
106 #endif
107 #ifdef HAVE_SYS_STROPTS_H
108 #include <sys/stropts.h>
109 #endif
111 /* defined by aix's sys/stream.h and again by arpa/nameser.h */
113 #undef NOERROR
115 /* as far as we know, this is only used with later versions of Slowlaris */
116 #if SunOS >= 50 && defined(HAVE_SYS_STROPTS_H) && defined(HAVE_FATTACH) && defined(I_PUSH)
117 #define MAY_HAVE_X11_PIPES
118 #endif
120 #ifdef SOCKS
121 #include <socks.h>
122 /* This doesn't belong here. */
123 struct tm *localtime(const time_t *);
124 struct hostent *gethostbyname(const char *);
125 #endif
127 #ifdef KRB4
128 #include <krb.h>
129 #include <prot.h>
130 #endif
131 #ifdef KRB5
132 #include <krb5.h>
133 #endif
135 #include <err.h>
136 #include <getarg.h>
137 #include <roken.h>
139 struct x_socket {
140 char *pathname;
141 int fd;
142 enum {
143 LISTENP = 0x80,
144 TCP = LISTENP | 1,
145 UNIX_SOCKET = LISTENP | 2,
146 STREAM_PIPE = 3
147 } flags;
150 extern char x_socket[];
151 extern uint32_t display_num;
152 extern char display[];
153 extern int display_size;
154 extern char xauthfile[];
155 extern int xauthfile_size;
156 extern u_char cookie[];
157 extern size_t cookie_len;
159 int get_xsockets (int *number, struct x_socket **sockets, int tcpp);
160 int chown_xsockets (int n, struct x_socket *sockets, uid_t uid, gid_t gid);
162 int connect_local_xsocket (unsigned dnr);
163 int create_and_write_cookie (char *file,
164 size_t file_size,
165 u_char *cookie_buf,
166 size_t sz);
167 int verify_and_remove_cookies (int fd, int sock, int cookiesp);
168 int replace_cookie(int xserver, int fd, char *filename, int cookiesp);
170 int suspicious_address (int sock, struct sockaddr *addr);
172 #define KX_PORT 2111
174 #define KX_OLD_VERSION "KXSERV.1"
175 #define KX_VERSION "KXSERV.2"
177 #define COOKIE_TYPE "MIT-MAGIC-COOKIE-1"
179 enum { INIT = 0, ACK = 1, NEW_CONN = 2, ERROR = 3 };
181 enum kx_flags { PASSIVE = 1, KEEP_ALIVE = 2 };
183 typedef enum kx_flags kx_flags;
185 struct kx_context {
186 int (*authenticate)(struct kx_context *kc, int s);
187 int (*userok)(struct kx_context *kc, char *user);
188 ssize_t (*read)(struct kx_context *kc,
189 int fd, void *buf, size_t len);
190 ssize_t (*write)(struct kx_context *kc,
191 int fd, const void *buf, size_t len);
192 int (*copy_encrypted)(struct kx_context *kc,
193 int fd1, int fd2);
194 void (*destroy)(struct kx_context *kc);
195 const char *host;
196 const char *user;
197 int port;
198 int debug_flag;
199 int keepalive_flag;
200 int tcp_flag;
201 struct sockaddr_storage __ss_this;
202 struct sockaddr_storage __ss_that;
203 struct sockaddr *thisaddr;
204 struct sockaddr *thataddr;
205 socklen_t thisaddr_len, thataddr_len;
206 void *data;
209 typedef struct kx_context kx_context;
211 void
212 context_set (kx_context *kc, const char *host, const char *user, int port,
213 int debug_flag, int keepalive_flag, int tcp_flag);
215 void
216 context_destroy (kx_context *kc);
219 context_authenticate (kx_context *kc, int s);
222 context_userok (kx_context *kc, char *user);
224 ssize_t
225 kx_read (kx_context *kc, int fd, void *buf, size_t len);
227 ssize_t
228 kx_write (kx_context *kc, int fd, const void *buf, size_t len);
231 copy_encrypted (kx_context *kc, int fd1, int fd2);
233 #ifdef KRB4
235 void
236 krb4_make_context (kx_context *c);
239 recv_v4_auth (kx_context *kc, int sock, u_char *buf);
241 #endif
243 #ifdef KRB5
245 void
246 krb5_make_context (kx_context *c);
249 recv_v5_auth (kx_context *kc, int sock, u_char *buf);
251 #endif
253 void
254 fatal (kx_context *kc, int fd, char *format, ...)
255 #ifdef __GNUC__
256 __attribute__ ((format (printf, 3, 4)))
257 #endif
261 kx_get_int(void *f, uint32_t *to, int size, int lsb);
264 kx_put_int(uint32_t from, void *to, size_t rem, int size);