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