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