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