xref: /titanic_44/usr/src/cmd/ssh/include/defines.h (revision a4aeef46cda1835da2b19f8f62b4526de6521e6c)
1 /*
2  * Copyright (c) 1999-2003 Damien Miller.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  */
24 /*
25  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  */
28 
29 #ifndef	_DEFINES_H
30 #define	_DEFINES_H
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /* $Id: defines.h,v 1.96 2002/09/26 00:38:48 tim Exp $ */
37 
38 
39 /* Constants */
40 #ifndef SHUT_RDWR
41 enum
42 {
43 	SHUT_RD = 0,	/* No more receptions.  */
44 	SHUT_WR,	/* No more transmissions.  */
45 	SHUT_RDWR	/* No more receptions or transmissions. */
46 };
47 #define	SHUT_RD   SHUT_RD
48 #define	SHUT_WR   SHUT_WR
49 #define	SHUT_RDWR SHUT_RDWR
50 #endif
51 
52 #ifndef IPTOS_LOWDELAY
53 #define	IPTOS_LOWDELAY		0x10
54 #define	IPTOS_THROUGHPUT	0x08
55 #define	IPTOS_RELIABILITY	0x04
56 #define	IPTOS_LOWCOST		0x02
57 #define	IPTOS_MINCOST		IPTOS_LOWCOST
58 #endif /* IPTOS_LOWDELAY */
59 
60 #ifndef MAXPATHLEN
61 #ifdef PATH_MAX
62 #define	MAXPATHLEN PATH_MAX
63 #else /* PATH_MAX */
64 #define	MAXPATHLEN 64 /* Should be safe */
65 #endif /* PATH_MAX */
66 #endif /* MAXPATHLEN */
67 
68 #ifndef STDIN_FILENO
69 #define	STDIN_FILENO    0
70 #endif
71 
72 #ifndef STDOUT_FILENO
73 #define	STDOUT_FILENO   1
74 #endif
75 
76 #ifndef STDERR_FILENO
77 #define	STDERR_FILENO   2
78 #endif
79 
80 /* Disable groupaccess if NGROUPS_UMAX, NGROUPS_MAX and NGROUPS are not set */
81 #ifndef NGROUPS_UMAX
82 #ifdef NGROUPS_MAX
83 #define	NGROUPS_UMAX NGROUPS_MAX
84 #elif defined(NGROUPS)
85 #define	NGROUPS_UMAX NGROUPS
86 #else
87 #define	NGROUPS_UMAX 0
88 #endif
89 #endif
90 
91 #ifndef O_NONBLOCK	/* Non Blocking Open */
92 #define	O_NONBLOCK	00004
93 #endif
94 
95 #ifndef S_ISDIR
96 #define	S_ISDIR(mode)	(((mode) & (_S_IFMT)) == (_S_IFDIR))
97 #endif /* S_ISDIR */
98 
99 #ifndef S_ISREG
100 #define	S_ISREG(mode)	(((mode) & (_S_IFMT)) == (_S_IFREG))
101 #endif /* S_ISREG */
102 
103 #ifndef S_ISLNK
104 #define	S_ISLNK(mode)	(((mode) & S_IFMT) == S_IFLNK)
105 #endif /* S_ISLNK */
106 
107 #ifndef S_IXUSR
108 #define	S_IXUSR			0000100	/* execute/search permission, */
109 #define	S_IXGRP			0000010	/* execute/search permission, */
110 #define	S_IXOTH			0000001	/* execute/search permission, */
111 #define	_S_IWUSR		0000200	/* write permission, */
112 #define	S_IWUSR			_S_IWUSR /* write permission, owner */
113 #define	S_IWGRP			0000020	/* write permission, group */
114 #define	S_IWOTH			0000002	/* write permission, other */
115 #define	S_IRUSR			0000400	/* read permission, owner */
116 #define	S_IRGRP			0000040	/* read permission, group */
117 #define	S_IROTH			0000004	/* read permission, other */
118 #define	S_IRWXU			0000700	/* read, write, execute */
119 #define	S_IRWXG			0000070	/* read, write, execute */
120 #define	S_IRWXO			0000007	/* read, write, execute */
121 #endif /* S_IXUSR */
122 
123 #if !defined(MAP_ANON) && defined(MAP_ANONYMOUS)
124 #define	MAP_ANON MAP_ANONYMOUS
125 #endif
126 
127 #ifndef MAP_FAILED
128 #define	MAP_FAILED ((void *)-1)
129 #endif
130 
131 /* *-*-nto-qnx doesn't define this constant in the system headers */
132 #ifdef MISSING_NFDBITS
133 #define	NFDBITS (8 * sizeof (unsigned long))
134 #endif
135 
136 /*
137  * SCO Open Server 3 has INADDR_LOOPBACK defined in rpc/rpc.h but including
138  * rpc/rpc.h breaks Solaris 6
139  */
140 #ifndef INADDR_LOOPBACK
141 #define	INADDR_LOOPBACK ((ulong_t)0x7f000001)
142 #endif
143 
144 /* Types */
145 
146 /*
147  * If sys/types.h does not supply intXX_t, supply them ourselves (or die trying)
148  */
149 #ifndef HAVE_U_INT
150 /* for now, we can't remove u_int without changing almost all other files */
151 /* CSTYLED */
152 typedef unsigned int u_int;
153 #endif
154 
155 #ifndef HAVE_INTXX_T
156 #if (SIZEOF_CHAR == 1)
157 typedef char int8_t;
158 #else
159 #error "8 bit int type not found."
160 #endif
161 #if (SIZEOF_SHORT_INT == 2)
162 typedef short int int16_t;
163 #else
164 #ifdef _UNICOS
165 #if (SIZEOF_SHORT_INT == 4)
166 typedef short int16_t;
167 #else
168 typedef long  int16_t;
169 #endif
170 #else
171 #error "16 bit int type not found."
172 #endif /* _UNICOS */
173 #endif
174 #if (SIZEOF_INT == 4)
175 typedef int int32_t;
176 #else
177 #ifdef _UNICOS
178 typedef long  int32_t;
179 #else
180 #error "32 bit int type not found."
181 #endif /* _UNICOS */
182 #endif
183 #endif
184 
185 /* If sys/types.h does not supply u_intXX_t, supply them ourselves */
186 #ifndef HAVE_U_INTXX_T
187 #ifdef HAVE_UINTXX_T
188 typedef uint8_t u_int8_t;
189 typedef uint16_t u_int16_t;
190 typedef uint32_t u_int32_t;
191 #define	HAVE_U_INTXX_T 1
192 #else
193 #if (SIZEOF_CHAR == 1)
194 typedef unsigned char u_int8_t;
195 #else
196 #error "8 bit int type not found."
197 #endif
198 #if (SIZEOF_SHORT_INT == 2)
199 typedef unsigned short int u_int16_t;
200 #else
201 #ifdef _UNICOS
202 #if (SIZEOF_SHORT_INT == 4)
203 typedef unsigned short u_int16_t;
204 #else
205 typedef unsigned long  u_int16_t;
206 #endif
207 #else
208 #error "16 bit int type not found."
209 #endif
210 #endif
211 #if (SIZEOF_INT == 4)
212 typedef unsigned int u_int32_t;
213 #else
214 #ifdef _UNICOS
215 typedef unsigned long  u_int32_t;
216 #else
217 #error "32 bit int type not found."
218 #endif
219 #endif
220 #endif
221 #define	__BIT_TYPES_DEFINED__
222 #endif
223 
224 /* 64-bit types */
225 #ifndef HAVE_INT64_T
226 #if (SIZEOF_LONG_INT == 8)
227 typedef long int int64_t;
228 #define	HAVE_INT64_T 1
229 #else
230 #if (SIZEOF_LONG_LONG_INT == 8)
231 typedef long long int int64_t;
232 #define	HAVE_INT64_T 1
233 #endif
234 #endif
235 #endif
236 
237 #ifndef HAVE_U_INT64_T
238 #if (SIZEOF_LONG_INT == 8)
239 typedef unsigned long int u_int64_t;
240 #define	HAVE_U_INT64_T 1
241 #else
242 #if (SIZEOF_LONG_LONG_INT == 8)
243 typedef unsigned long long int u_int64_t;
244 #define	HAVE_U_INT64_T 1
245 #endif
246 #endif
247 #endif
248 
249 #if !defined(HAVE_LONG_LONG_INT) && (SIZEOF_LONG_LONG_INT == 8)
250 #define	HAVE_LONG_LONG_INT 1
251 #endif
252 
253 #ifndef HAVE_U_CHAR
254 /* for now, we can't remove u_char without changing almost all other files */
255 /* CSTYLED */
256 typedef unsigned char u_char;
257 #define	HAVE_U_CHAR
258 #endif /* HAVE_U_CHAR */
259 
260 #ifndef SIZE_T_MAX
261 #define	SIZE_T_MAX ULONG_MAX
262 #endif /* SIZE_T_MAX */
263 
264 #ifndef HAVE_SIZE_T
265 typedef unsigned int size_t;
266 #define	HAVE_SIZE_T
267 #endif /* HAVE_SIZE_T */
268 
269 #ifndef HAVE_SSIZE_T
270 typedef int ssize_t;
271 #define	HAVE_SSIZE_T
272 #endif /* HAVE_SSIZE_T */
273 
274 #ifndef HAVE_CLOCK_T
275 typedef long clock_t;
276 #define	HAVE_CLOCK_T
277 #endif /* HAVE_CLOCK_T */
278 
279 #ifndef HAVE_SA_FAMILY_T
280 typedef int sa_family_t;
281 #define	HAVE_SA_FAMILY_T
282 #endif /* HAVE_SA_FAMILY_T */
283 
284 #ifndef HAVE_PID_T
285 typedef int pid_t;
286 #define	HAVE_PID_T
287 #endif /* HAVE_PID_T */
288 
289 #ifndef HAVE_SIG_ATOMIC_T
290 typedef int sig_atomic_t;
291 #define	HAVE_SIG_ATOMIC_T
292 #endif /* HAVE_SIG_ATOMIC_T */
293 
294 #ifndef HAVE_MODE_T
295 typedef int mode_t;
296 #define	HAVE_MODE_T
297 #endif /* HAVE_MODE_T */
298 
299 #if !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE___SS_FAMILY_IN_SS)
300 #define	ss_family __ss_family
301 #endif /* !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE_SA_FAMILY_IN_SS) */
302 
303 #ifndef HAVE_SYS_UN_H
304 struct	sockaddr_un {
305 	short	sun_family;		/* AF_UNIX */
306 	char	sun_path[108];		/* path name (gag) */
307 };
308 #endif /* HAVE_SYS_UN_H */
309 
310 #if defined(BROKEN_SYS_TERMIO_H) && !defined(_STRUCT_WINSIZE)
311 #define	_STRUCT_WINSIZE
312 struct winsize {
313 	unsigned short ws_row;		/* rows, in characters */
314 	unsigned short ws_col;		/* columns, in character */
315 	unsigned short ws_xpixel;	/* horizontal size, pixels */
316 	unsigned short ws_ypixel;	/* vertical size, pixels */
317 };
318 #endif
319 
320 /* *-*-nto-qnx does not define this type in the system headers */
321 #ifdef MISSING_FD_MASK
322 typedef unsigned long int fd_mask;
323 #endif
324 
325 /* Paths */
326 
327 #ifndef _PATH_BSHELL
328 #define	_PATH_BSHELL "/bin/sh"
329 #endif
330 
331 #ifndef _PATH_CSHELL
332 #define	_PATH_CSHELL "/bin/csh"
333 #endif
334 
335 #ifndef _PATH_SHELLS
336 #define	_PATH_SHELLS "/etc/shells"
337 #endif
338 
339 #ifdef USER_PATH
340 #ifdef _PATH_STDPATH
341 #undef _PATH_STDPATH
342 #endif
343 #define	_PATH_STDPATH USER_PATH
344 #endif
345 
346 #ifndef _PATH_STDPATH
347 #define	_PATH_STDPATH "/usr/bin"
348 #endif
349 
350 #ifndef _PATH_DEVNULL
351 #define	_PATH_DEVNULL "/dev/null"
352 #endif
353 
354 #ifndef MAIL_DIRECTORY
355 #define	MAIL_DIRECTORY "/var/spool/mail"
356 #endif
357 
358 #ifndef MAILDIR
359 #define	MAILDIR MAIL_DIRECTORY
360 #endif
361 
362 #if !defined(_PATH_MAILDIR) && defined(MAILDIR)
363 #define	_PATH_MAILDIR MAILDIR
364 #endif /* !defined(_PATH_MAILDIR) && defined(MAILDIR) */
365 
366 #ifndef _PATH_RSH
367 #ifdef RSH_PATH
368 #define	_PATH_RSH RSH_PATH
369 #else /* RSH_PATH */
370 #define	_PATH_RSH "/usr/bin/rsh"
371 #endif /* RSH_PATH */
372 #endif /* _PATH_RSH */
373 
374 #ifndef _PATH_NOLOGIN
375 #define	_PATH_NOLOGIN "/etc/nologin"
376 #endif
377 
378 /* Define this to be the path of the xauth program. */
379 #ifdef XAUTH_PATH
380 #define	_PATH_XAUTH XAUTH_PATH
381 #endif /* XAUTH_PATH */
382 
383 /* derived from XF4/xc/lib/dps/Xlibnet.h */
384 #ifndef X_UNIX_PATH
385 #ifdef __hpux
386 #define	X_UNIX_PATH "/var/spool/sockets/X11/%u"
387 #else
388 #define	X_UNIX_PATH "/tmp/.X11-unix/X%u"
389 #endif
390 #endif /* X_UNIX_PATH */
391 
392 #define	_PATH_UNIX_X X_UNIX_PATH
393 
394 #ifndef _PATH_TTY
395 #define	_PATH_TTY "/dev/tty"
396 #endif
397 
398 /* Macros */
399 
400 #if defined(HAVE_LOGIN_GETCAPBOOL) && defined(HAVE_LOGIN_CAP_H)
401 #define	HAVE_LOGIN_CAP
402 #endif
403 
404 #ifndef MAX
405 #define	MAX(a, b) (((a) > (b)) ? (a) : (b))
406 #define	MIN(a, b) (((a) < (b)) ? (a) : (b))
407 #endif
408 
409 #ifndef roundup
410 #define	roundup(x, y)   ((((x) + ((y) - 1)) / (y)) * (y))
411 #endif
412 
413 #ifndef timersub
414 #define	timersub(a, b, result)						\
415 	do {								\
416 		(result)->tv_sec = (a)->tv_sec - (b)->tv_sec;		\
417 		(result)->tv_usec = (a)->tv_usec - (b)->tv_usec;	\
418 		if ((result)->tv_usec < 0) {				\
419 			--(result)->tv_sec;				\
420 			(result)->tv_usec += 1000000;			\
421 		}							\
422 	} while (0)
423 #endif
424 
425 #ifndef __P
426 #define	__P(x) x
427 #endif
428 
429 #if !defined(IN6_IS_ADDR_V4MAPPED)
430 #define	IN6_IS_ADDR_V4MAPPED(a) \
431 	((((u_int32_t *)(a))[0] == 0) && (((u_int32_t *)(a))[1] == 0) && \
432 	(((u_int32_t *)(a))[2] == htonl(0xffff)))
433 #endif /* !defined(IN6_IS_ADDR_V4MAPPED) */
434 
435 #if !defined(__GNUC__) || (__GNUC__ < 2)
436 #define	__attribute__(x)
437 #endif /* !defined(__GNUC__) || (__GNUC__ < 2) */
438 
439 #if !defined(HAVE_ATTRIBUTE__BOUNDED__) && !defined(__bounded__)
440 #define	__bounded__(x, y, z)
441 #endif
442 
443 /* *-*-nto-qnx doesn't define this macro in the system headers */
444 #ifdef MISSING_HOWMANY
445 #define	howmany(x, y)	(((x) + ((y) - 1)) / (y))
446 #endif
447 
448 #ifndef OSSH_ALIGNBYTES
449 #define	OSSH_ALIGNBYTES	(sizeof (int) - 1)
450 #endif
451 
452 #ifndef __CMSG_ALIGN
453 #define	__CMSG_ALIGN(p) (((uint_t)(p) + OSSH_ALIGNBYTES) &~ OSSH_ALIGNBYTES)
454 #endif
455 
456 /* Length of the contents of a control message of length len */
457 #ifndef CMSG_LEN
458 #define	CMSG_LEN(len)	(__CMSG_ALIGN(sizeof (struct cmsghdr)) + (len))
459 #endif
460 
461 /* Length of the space taken up by a padded control message of length len */
462 #ifndef CMSG_SPACE
463 #define	CMSG_SPACE(len)	\
464 	(__CMSG_ALIGN(sizeof (struct cmsghdr)) + __CMSG_ALIGN(len))
465 #endif
466 
467 /* Function replacement / compatibility hacks */
468 
469 #if !defined(HAVE_GETADDRINFO) && (defined(HAVE_OGETADDRINFO) || \
470 	defined(HAVE_NGETADDRINFO))
471 #define	HAVE_GETADDRINFO
472 #endif
473 
474 #ifndef HAVE_GETOPT_OPTRESET
475 #undef getopt
476 #undef opterr
477 #undef optind
478 #undef optopt
479 #undef optreset
480 #undef optarg
481 #define	getopt(ac, av, o)	BSDgetopt(ac, av, o)
482 #define	opterr			BSDopterr
483 #define	optind			BSDoptind
484 #define	optopt			BSDoptopt
485 #define	optreset		BSDoptreset
486 #define	optarg			BSDoptarg
487 #endif
488 
489 /* In older versions of libpam, pam_strerror takes a single argument */
490 #ifdef HAVE_OLD_PAM
491 #define	PAM_STRERROR(a, b) pam_strerror((b))
492 #else
493 #define	PAM_STRERROR(a, b) pam_strerror((a), (b))
494 #endif
495 
496 #ifdef PAM_SUN_CODEBASE
497 #define	PAM_MSG_MEMBER(msg, n, member) ((*(msg))[(n)].member)
498 #else
499 #define	PAM_MSG_MEMBER(msg, n, member) ((msg)[(n)]->member)
500 #endif
501 
502 #if defined(BROKEN_GETADDRINFO) && defined(HAVE_GETADDRINFO)
503 #undef HAVE_GETADDRINFO
504 #endif
505 
506 #if defined(BROKEN_GETADDRINFO) && defined(HAVE_FREEADDRINFO)
507 #undef HAVE_FREEADDRINFO
508 #endif
509 
510 #if defined(BROKEN_GETADDRINFO) && defined(HAVE_GAI_STRERROR)
511 #undef HAVE_GAI_STRERROR
512 #endif
513 
514 #if !defined(HAVE_MEMMOVE) && defined(HAVE_BCOPY)
515 #define	memmove(s1, s2, n) bcopy((s2), (s1), (n))
516 #endif /* !defined(HAVE_MEMMOVE) && defined(HAVE_BCOPY) */
517 
518 #if defined(HAVE_VHANGUP) && !defined(HAVE_DEV_PTMX)
519 #define	USE_VHANGUP
520 #endif /* defined(HAVE_VHANGUP) && !defined(HAVE_DEV_PTMX) */
521 
522 #ifndef GETPGRP_VOID
523 #define	getpgrp() getpgrp(0)
524 #endif
525 
526 /* OPENSSL_free() is Free() in versions before OpenSSL 0.9.6 */
527 #if !defined(OPENSSL_VERSION_NUMBER) || (OPENSSL_VERSION_NUMBER < 0x0090600f)
528 #define	OPENSSL_free(x) Free(x)
529 #endif
530 
531 #if !defined(HAVE___func__) && defined(HAVE___FUNCTION__)
532 #define	__func__ __FUNCTION__
533 #elif !defined(HAVE___func__)
534 #define	__func__ ""
535 #endif
536 
537 /*
538  * login recorder definitions
539  */
540 
541 /* FIXME: put default paths back in */
542 #ifndef UTMP_FILE
543 #ifdef _PATH_UTMP
544 #define	UTMP_FILE _PATH_UTMP
545 #else
546 #ifdef CONF_UTMP_FILE
547 #define	UTMP_FILE CONF_UTMP_FILE
548 #endif
549 #endif
550 #endif
551 
552 #ifndef WTMP_FILE
553 #ifdef _PATH_WTMP
554 #define	WTMP_FILE _PATH_WTMP
555 #else
556 #ifdef CONF_WTMP_FILE
557 #define	WTMP_FILE CONF_WTMP_FILE
558 #endif
559 #endif
560 #endif
561 
562 /* pick up the user's location for lastlog if given */
563 #ifndef LASTLOG_FILE
564 #ifdef _PATH_LASTLOG
565 #define	LASTLOG_FILE _PATH_LASTLOG
566 #else
567 #ifdef CONF_LASTLOG_FILE
568 #define	LASTLOG_FILE CONF_LASTLOG_FILE
569 #endif
570 #endif
571 #endif
572 
573 /* The login() library function in libutil is first choice */
574 #if defined(HAVE_LOGIN) && !defined(DISABLE_LOGIN)
575 #define	USE_LOGIN
576 #else
577 /* Simply select your favourite login types. */
578 /* Can't do if-else because some systems use several... <sigh> */
579 #if defined(UTMPX_FILE) && !defined(DISABLE_UTMPX)
580 #define	USE_UTMPX
581 #endif
582 #if defined(UTMP_FILE) && !defined(DISABLE_UTMP)
583 #define	USE_UTMP
584 #endif
585 #if defined(WTMPX_FILE) && !defined(DISABLE_WTMPX)
586 #define	USE_WTMPX
587 #endif
588 #if defined(WTMP_FILE) && !defined(DISABLE_WTMP)
589 #define	USE_WTMP
590 #endif
591 #endif
592 
593 /* I hope that the presence of LASTLOG_FILE is enough to detect this */
594 #if defined(LASTLOG_FILE) && !defined(DISABLE_LASTLOG)
595 #define	USE_LASTLOG
596 #endif
597 
598 /* end of login recorder definitions */
599 
600 #ifdef __cplusplus
601 }
602 #endif
603 
604 #endif /* _DEFINES_H */
605