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