Initial import from FreeBSD RELENG_4:
[dragonfly.git] / crypto / kerberosIV / appl / bsd / bsd_locl.h
1 /*
2  * Copyright (c) 1995 - 2000 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.
12  * 
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  * 
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.
20  * 
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.
32  */
33
34 /* $Id: bsd_locl.h,v 1.111 1999/12/02 16:58:28 joda Exp $ */
35 /* $FreeBSD: src/crypto/kerberosIV/appl/bsd/bsd_locl.h,v 1.4.2.2 2003/02/13 21:34:35 nectar Exp $ */
36
37 #define LOGALL
38 #ifndef KERBEROS
39 #define KERBEROS
40 #endif
41 #define KLOGIN_PARANOID
42 #define LOGIN_ACCESS
43 #define PASSWD_FALLBACK
44
45 #ifdef HAVE_CONFIG_H
46 #include "config.h"
47 #endif
48
49 /* Any better way to test NO_MOTD? */
50 #if (SunOS >= 50) || defined(__hpux)
51 #define NO_MOTD
52 #endif
53
54 #ifdef HAVE_SHADOW_H
55 #define SYSV_SHADOW
56 #endif
57
58 #include <stdio.h>
59 #include <string.h>
60 #include <stdlib.h>
61 #include <ctype.h>
62 #include <setjmp.h>
63 #include <limits.h>
64
65 #include <stdarg.h>
66
67 #include <errno.h>
68 #ifdef HAVE_IO_H
69 #include <io.h>
70 #endif
71 #ifdef HAVE_UNISTD_H
72 #include <unistd.h>
73 #endif
74 #ifdef HAVE_LIBUTIL_H
75 #include <libutil.h>
76 #endif
77 #ifdef HAVE_SYS_TYPES_H
78 #include <sys/types.h>
79 #endif
80 #ifdef TIME_WITH_SYS_TIME
81 #include <sys/time.h>
82 #include <time.h>
83 #elif defined(HAVE_SYS_TIME_H)
84 #include <sys/time.h>
85 #else
86 #include <time.h>
87 #endif
88 #ifdef HAVE_SYS_STAT_H
89 #include <sys/stat.h>
90 #endif
91
92 #ifndef S_ISTXT
93 #ifdef S_ISVTX
94 #define S_ISTXT S_ISVTX
95 #else
96 #define S_ISTXT 0
97 #endif
98 #endif
99
100 #ifdef HAVE_FCNTL_H
101 #include <fcntl.h>
102 #endif
103 #ifdef HAVE_DIRENT_H
104 #include <dirent.h>
105 #endif
106 #include <signal.h>
107 #ifdef HAVE_SYS_RESOURCE_H
108 #include <sys/resource.h>
109 #endif /* HAVE_SYS_RESOURCE_H */
110 #ifdef HAVE_SYS_WAIT_H
111 #include <sys/wait.h>
112 #endif
113 #ifdef HAVE_SYS_PARAM_H
114 #include <sys/param.h>
115 #endif
116
117 #ifndef NCARGS
118 #define NCARGS  0x100000 /* (absolute) max # characters in exec arglist */
119 #endif
120 #ifdef HAVE_PWD_H
121 #include <pwd.h>
122 #endif
123
124 #ifdef HAVE_GRP_H
125 #include <grp.h>
126 #endif
127 #ifdef HAVE_UTIME_H
128 #include <utime.h>
129 #endif
130
131 #ifdef HAVE_SYS_SOCKET_H
132 #include <sys/socket.h>
133 #endif
134 #ifdef HAVE_NETINET_IN_H
135 #include <netinet/in.h>
136 #endif
137 #ifdef HAVE_NETINET_IN_SYSTM_H
138 #include <netinet/in_systm.h>
139 #endif
140 #ifdef HAVE_NETINET_IP_H
141 #include <netinet/ip.h>
142 #endif
143 #ifdef HAVE_NETINET_TCP_H
144 #include <netinet/tcp.h>
145 #endif
146 #ifdef HAVE_ARPA_INET_H
147 #include <arpa/inet.h>
148 #endif
149 #ifdef HAVE_NETDB_H
150 #include <netdb.h>
151 #endif
152
153 #if defined(HAVE_SYS_IOCTL_H) && SunOS != 40
154 #include <sys/ioctl.h>
155 #endif
156 #ifdef HAVE_SYS_IOCCOM_H
157 #include <sys/ioccom.h>
158 #endif
159
160 #ifdef HAVE_SYS_SOCKIO_H
161 #include <sys/sockio.h>
162 #endif
163
164 #ifdef HAVE_SYS_SELECT_H
165 #include <sys/select.h>
166 #endif
167
168 #ifdef HAVE_SYS_FILIO_H
169 #include <sys/filio.h>
170 #endif
171
172 #ifdef HAVE_SYS_STREAM_H
173 #ifdef HAVE_SYS_UIO_H
174 #include <sys/uio.h>
175 #endif /* HAVE_SYS_UIO_H */
176 #include <sys/stream.h>
177 #endif /* HAVE_SYS_STREAM_H */
178
179 #ifdef HAVE_SYS_PTYVAR_H
180 #ifdef HAVE_SYS_PROC_H
181 #include <sys/proc.h>
182 #endif
183 #ifdef HAVE_SYS_TTY_H
184 #include <sys/tty.h>
185 #endif
186 #ifdef HAVE_SYS_PTYIO_H
187 #include <sys/ptyio.h>
188 #endif
189 #include <sys/ptyvar.h>
190 #endif /* HAVE_SYS_PTYVAR_H */
191
192 /* Cray stuff */
193 #ifdef HAVE_UDB_H
194 #include <udb.h>
195 #endif
196 #ifdef HAVE_SYS_CATEGORY_H
197 #include <sys/category.h>
198 #endif
199
200 /* Strange ioctls that are not always defined */
201
202 #ifndef TIOCPKT_FLUSHWRITE
203 #define TIOCPKT_FLUSHWRITE      0x02
204 #endif
205  
206 #ifndef TIOCPKT_NOSTOP
207 #define TIOCPKT_NOSTOP  0x10
208 #endif
209  
210 #ifndef TIOCPKT_DOSTOP
211 #define TIOCPKT_DOSTOP  0x20
212 #endif
213
214 #ifndef TIOCPKT
215 #define TIOCPKT         _IOW('t', 112, int)   /* pty: set/clear packet mode */
216 #endif
217
218 #ifdef HAVE_LASTLOG_H
219 #include <lastlog.h>
220 #endif
221
222 #ifdef HAVE_LOGIN_H
223 #include <login.h>
224 #endif
225
226 #ifdef HAVE_TTYENT_H
227 #include <ttyent.h>
228 #endif
229
230 #ifdef HAVE_STROPTS_H
231 #include <stropts.h>
232 #endif
233
234 #ifdef HAVE_UTMP_H
235 #include <utmp.h>
236 #ifndef UT_NAMESIZE
237 #define UT_NAMESIZE     sizeof(((struct utmp *)0)->ut_name)
238 #endif
239 #endif
240
241 #ifdef HAVE_UTMPX_H
242 #include <utmpx.h>
243 #endif
244
245 #ifdef HAVE_USERPW_H
246 #include <userpw.h>
247 #endif /* HAVE_USERPW_H */
248
249 #ifdef HAVE_USERSEC_H
250 struct aud_rec;
251 #include <usersec.h>
252 #endif /* HAVE_USERSEC_H */
253
254 #ifdef HAVE_OSFC2
255 #include "/usr/include/prot.h"
256 #endif
257
258 #ifndef PRIO_PROCESS
259 #define PRIO_PROCESS 0
260 #endif
261
262 #include <err.h>
263
264 #include <roken.h>
265
266 #ifdef SOCKS
267 #include <socks.h>
268 /* This doesn't belong here. */
269 struct tm *localtime(const time_t *);
270 struct hostent  *gethostbyname(const char *);
271 #endif
272
273 #define OPENSSL_DES_LIBDES_COMPATIBILITY
274 #include <openssl/des.h>
275 #include <krb.h>
276 #include <kafs.h>
277
278 int kcmd(int *sock, char **ahost, u_int16_t rport, char *locuser,
279          char *remuser, char *cmd, int *fd2p, KTEXT ticket,
280          char *service, char *realm, CREDENTIALS *cred,
281          Key_schedule schedule, MSG_DAT *msg_data,
282          struct sockaddr_in *laddr, struct sockaddr_in *faddr,
283          int32_t authopts);
284
285 int krcmd(char **ahost, u_int16_t rport, char *remuser, char *cmd,
286           int *fd2p, char *realm);
287
288 int krcmd_mutual(char **ahost, u_int16_t rport, char *remuser,
289                  char *cmd,int *fd2p, char *realm,
290                  CREDENTIALS *cred, Key_schedule sched);
291
292 int klogin(struct passwd *pw, char *instance, char *localhost, char *password);
293
294 #if 0
295 typedef struct {
296         int cnt;
297         char *buf;
298 } BUF;
299 #endif
300
301 char *colon(char *cp);
302 int okname(char *cp0);
303 int susystem(char *s, int userid);
304
305 int forkpty(int *amaster, char *name,
306             struct termios *termp, struct winsize *winp);
307
308 int forkpty_truncate(int *amaster, char *name, size_t name_sz,
309                      struct termios *termp, struct winsize *winp);
310
311 #ifndef MODEMASK
312 #define MODEMASK        (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
313 #endif
314
315 #ifdef HAVE_PATHS_H
316 #include <paths.h>
317 #endif
318 #ifdef HAVE_MAILLOCK_H
319 #include <maillock.h>
320 #endif
321 #include "pathnames.h"
322
323 void stty_default (void);
324
325 int utmpx_login(char *line, char *user, char *host);
326
327 extern char **environ;
328
329 void sysv_newenv(int argc, char **argv, struct passwd *pwd,
330                  char *term, int pflag);
331
332 int login_access(struct passwd *user, char *from);
333 void fatal(int f, const char *msg, int syserr);
334
335 extern int LEFT_JUSTIFIED;
336
337 /* used in des_read and des_write */
338 #define DES_RW_MAXWRITE (1024*16)
339 #define DES_RW_BSIZE    (DES_RW_MAXWRITE+4)
340
341 void sysv_defaults(void);
342 void utmp_login(char *tty, char *username, char *hostname);
343 void sleepexit (int);
344
345 #ifndef HAVE_SETPRIORITY
346 #define setpriority(which, who, niceval) 0
347 #endif
348
349 #ifndef HAVE_GETPRIORITY
350 #define getpriority(which, who) 0
351 #endif
352
353 #ifdef HAVE_TERMIOS_H
354 #include <termios.h>
355 #endif
356
357 #ifndef _POSIX_VDISABLE
358 #define _POSIX_VDISABLE 0
359 #endif /* _POSIX_VDISABLE */
360 #if SunOS == 40
361 #include <sys/ttold.h>
362 #endif
363
364 #if defined(HAVE_SYS_TERMIO_H) && !defined(HAVE_TERMIOS_H)
365 #include <sys/termio.h>
366 #endif
367
368 #ifndef CEOF
369 #define CEOF 04
370 #endif
371
372 /* concession to Sun */
373 #ifndef SIGUSR1
374 #define SIGUSR1 30
375 #endif
376
377 #ifndef TIOCPKT_WINDOW
378 #define TIOCPKT_WINDOW 0x80
379 #endif
380
381 int get_shell_port(int kerberos, int encryption);
382 int get_login_port(int kerberos, int encryption);
383 int speed_t2int (speed_t);
384 speed_t int2speed_t (int);
385 void ip_options_and_die (int sock, struct sockaddr_in *);
386 void warning(const char *fmt, ...)
387 #ifdef __GNUC__
388 __attribute__ ((format (printf, 1, 2)))
389 #endif
390 ;
391
392 char *clean_ttyname (char *tty);
393 char *make_id (char *tty);
394 #ifdef HAVE_UTMP_H
395 void prepare_utmp (struct utmp *utmp, char *tty, char *username,
396                    char *hostname);
397 #endif
398
399 int do_osfc2_magic(uid_t);
400
401 void paranoid_setuid (uid_t uid);