3 * Copyright (c) 1995-2005 Kungliga Tekniska Högskolan
4 * (Royal Institute of Technology, Stockholm, Sweden).
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the Institute nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50 #ifdef HAVE_SYS_PARAM_H
51 #include <sys/param.h>
53 #ifdef HAVE_INTTYPES_H
56 #ifdef HAVE_SYS_TYPES_H
57 #include <sys/types.h>
59 #ifdef HAVE_SYS_BITYPES_H
60 #include <sys/bitypes.h>
62 #ifdef HAVE_BIND_BITYPES_H
63 #include <bind/bitypes.h>
65 #ifdef HAVE_NETINET_IN6_MACHTYPES_H
66 #include <netinet/in6_machtypes.h>
71 #ifdef HAVE_SYS_SOCKET_H
72 #include <sys/socket.h>
80 #ifdef HAVE_SYS_STAT_H
83 #ifdef HAVE_NETINET_IN_H
84 #include <netinet/in.h>
86 #ifdef HAVE_NETINET_IN6_H
87 #include <netinet/in6.h>
89 #ifdef HAVE_NETINET6_IN6_H
90 #include <netinet6/in6.h>
92 #ifdef HAVE_ARPA_INET_H
93 #include <arpa/inet.h>
98 #ifdef HAVE_ARPA_NAMESER_H
99 #include <arpa/nameser.h>
114 #ifdef HAVE_TERMIOS_H
117 #if defined(HAVE_SYS_IOCTL_H) && SunOS != 40
118 #include <sys/ioctl.h>
120 #ifdef TIME_WITH_SYS_TIME
121 #include <sys/time.h>
123 #elif defined(HAVE_SYS_TIME_H)
124 #include <sys/time.h>
128 #ifdef HAVE_STRINGS_H
140 #include <roken-common.h>
144 #ifdef HAVE_UINTPTR_T
145 #define rk_UNCONST(x) ((void *)(uintptr_t)(const void *)(x))
147 #define rk_UNCONST(x) ((void *)(unsigned long)(const void *)(x))
150 #if !defined(HAVE_SETSID) && defined(HAVE__SETSID)
151 #define setsid _setsid
155 int ROKEN_LIB_FUNCTION
putenv(const char *);
158 #if !defined(HAVE_SETENV) || defined(NEED_SETENV_PROTO)
159 int ROKEN_LIB_FUNCTION
setenv(const char *, const char *, int);
162 #if !defined(HAVE_UNSETENV) || defined(NEED_UNSETENV_PROTO)
163 void ROKEN_LIB_FUNCTION
unsetenv(const char *);
166 #if !defined(HAVE_GETUSERSHELL) || defined(NEED_GETUSERSHELL_PROTO)
167 char * ROKEN_LIB_FUNCTION
getusershell(void);
168 void ROKEN_LIB_FUNCTION
endusershell(void);
171 #if !defined(HAVE_SNPRINTF) || defined(NEED_SNPRINTF_PROTO)
172 int ROKEN_LIB_FUNCTION
snprintf (char *, size_t, const char *, ...)
173 __attribute__ ((format (printf
, 3, 4)));
176 #if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO)
177 int ROKEN_LIB_FUNCTION
178 vsnprintf (char *, size_t, const char *, va_list)
179 __attribute__((format (printf
, 3, 0)));
182 #if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO)
183 int ROKEN_LIB_FUNCTION
184 asprintf (char **, const char *, ...)
185 __attribute__ ((format (printf
, 2, 3)));
188 #if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO)
189 int ROKEN_LIB_FUNCTION
190 vasprintf (char **, const char *, va_list)
191 __attribute__((format (printf
, 2, 0)));
194 #if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO)
195 int ROKEN_LIB_FUNCTION
196 asnprintf (char **, size_t, const char *, ...)
197 __attribute__ ((format (printf
, 3, 4)));
200 #if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO)
201 int ROKEN_LIB_FUNCTION
202 vasnprintf (char **, size_t, const char *, va_list)
203 __attribute__((format (printf
, 3, 0)));
207 char * ROKEN_LIB_FUNCTION
strdup(const char *);
210 #if !defined(HAVE_STRNDUP) || defined(NEED_STRNDUP_PROTO)
211 char * ROKEN_LIB_FUNCTION
strndup(const char *, size_t);
215 char * ROKEN_LIB_FUNCTION
strlwr(char *);
219 size_t ROKEN_LIB_FUNCTION
strnlen(const char*, size_t);
222 #if !defined(HAVE_STRSEP) || defined(NEED_STRSEP_PROTO)
223 char * ROKEN_LIB_FUNCTION
strsep(char**, const char*);
226 #if !defined(HAVE_STRSEP_COPY) || defined(NEED_STRSEP_COPY_PROTO)
227 ssize_t ROKEN_LIB_FUNCTION
strsep_copy(const char**, const char*, char*, size_t);
230 #ifndef HAVE_STRCASECMP
231 int ROKEN_LIB_FUNCTION
strcasecmp(const char *, const char *);
234 #ifdef NEED_FCLOSE_PROTO
235 int ROKEN_LIB_FUNCTION
fclose(FILE *);
238 #ifdef NEED_STRTOK_R_PROTO
239 char * ROKEN_LIB_FUNCTION
strtok_r(char *, const char *, char **);
243 char * ROKEN_LIB_FUNCTION
strupr(char *);
247 size_t ROKEN_LIB_FUNCTION
strlcpy (char *, const char *, size_t);
251 size_t ROKEN_LIB_FUNCTION
strlcat (char *, const char *, size_t);
254 #ifndef HAVE_GETDTABLESIZE
255 int ROKEN_LIB_FUNCTION
getdtablesize(void);
258 #if !defined(HAVE_STRERROR) && !defined(strerror)
259 char * ROKEN_LIB_FUNCTION
strerror(int);
262 #if !defined(HAVE_HSTRERROR) || defined(NEED_HSTRERROR_PROTO)
263 /* This causes a fatal error under Psoriasis */
264 #if !(defined(SunOS) && (SunOS >= 50))
265 const char * ROKEN_LIB_FUNCTION
hstrerror(int);
269 #if !HAVE_DECL_H_ERRNO
273 #if !defined(HAVE_INET_ATON) || defined(NEED_INET_ATON_PROTO)
274 int ROKEN_LIB_FUNCTION
inet_aton(const char *, struct in_addr
*);
277 #ifndef HAVE_INET_NTOP
278 const char * ROKEN_LIB_FUNCTION
279 inet_ntop(int af
, const void *src
, char *dst
, size_t size
);
282 #ifndef HAVE_INET_PTON
283 int ROKEN_LIB_FUNCTION
284 inet_pton(int, const char *, void *);
287 #if !defined(HAVE_GETCWD)
288 char* ROKEN_LIB_FUNCTION
getcwd(char *, size_t);
293 struct passwd
* ROKEN_LIB_FUNCTION
k_getpwnam (const char *);
294 struct passwd
* ROKEN_LIB_FUNCTION
k_getpwuid (uid_t
);
297 const char * ROKEN_LIB_FUNCTION
get_default_username (void);
300 int ROKEN_LIB_FUNCTION
seteuid(uid_t
);
304 int ROKEN_LIB_FUNCTION
setegid(gid_t
);
308 int ROKEN_LIB_FUNCTION
lstat(const char *, struct stat
*);
311 #if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO)
312 int ROKEN_LIB_FUNCTION
mkstemp(char *);
316 int ROKEN_LIB_FUNCTION
cgetent(char **, char **, const char *);
317 int ROKEN_LIB_FUNCTION
cgetstr(char *, const char *, char **);
320 #ifndef HAVE_INITGROUPS
321 int ROKEN_LIB_FUNCTION
initgroups(const char *, gid_t
);
325 int ROKEN_LIB_FUNCTION
fchown(int, uid_t
, gid_t
);
328 #if !defined(HAVE_DAEMON) || defined(NEED_DAEMON_PROTO)
329 int ROKEN_LIB_FUNCTION
daemon(int, int);
333 int ROKEN_LIB_FUNCTION
innetgr(const char *, const char *,
334 const char *, const char *);
338 int ROKEN_LIB_FUNCTION
chown(const char *, uid_t
, gid_t
);
342 int ROKEN_LIB_FUNCTION
343 rcmd(char **, unsigned short, const char *,
344 const char *, const char *, int *);
347 #if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO)
348 int ROKEN_LIB_FUNCTION
innetgr(const char*, const char*,
349 const char*, const char*);
352 #ifndef HAVE_IRUSEROK
353 int ROKEN_LIB_FUNCTION
iruserok(unsigned, int,
354 const char *, const char *);
357 #if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO)
358 int ROKEN_LIB_FUNCTION
gethostname(char *, int);
362 ssize_t ROKEN_LIB_FUNCTION
363 writev(int, const struct iovec
*, int);
367 ssize_t ROKEN_LIB_FUNCTION
368 readv(int, const struct iovec
*, int);
372 int ROKEN_LIB_FUNCTION
377 void ROKEN_LIB_FUNCTION
pidfile (const char*);
381 unsigned int ROKEN_LIB_FUNCTION
bswap32(unsigned int);
385 unsigned short ROKEN_LIB_FUNCTION
bswap16(unsigned short);
390 #define LOCK_SH 1 /* Shared lock */
393 #define LOCK_EX 2 /* Exclusive lock */
396 #define LOCK_NB 4 /* Don't block when locking */
399 #define LOCK_UN 8 /* Unlock */
402 int flock(int fd
, int operation
);
403 #endif /* HAVE_FLOCK */
405 time_t ROKEN_LIB_FUNCTION
tm2time (struct tm
, int);
407 int ROKEN_LIB_FUNCTION
unix_verify_user(char *, char *);
409 int ROKEN_LIB_FUNCTION
roken_concat (char *, size_t, ...);
411 size_t ROKEN_LIB_FUNCTION
roken_mconcat (char **, size_t, ...);
413 int ROKEN_LIB_FUNCTION
roken_vconcat (char *, size_t, va_list);
415 size_t ROKEN_LIB_FUNCTION
416 roken_vmconcat (char **, size_t, va_list);
418 ssize_t ROKEN_LIB_FUNCTION
net_write (int, const void *, size_t);
420 ssize_t ROKEN_LIB_FUNCTION
net_read (int, void *, size_t);
422 int ROKEN_LIB_FUNCTION
issuid(void);
424 #ifndef HAVE_STRUCT_WINSIZE
426 unsigned short ws_row
, ws_col
;
427 unsigned short ws_xpixel
, ws_ypixel
;
431 int ROKEN_LIB_FUNCTION
get_window_size(int fd
, struct winsize
*);
434 void ROKEN_LIB_FUNCTION
vsyslog(int, const char *, va_list);
437 #if !HAVE_DECL_OPTARG
440 #if !HAVE_DECL_OPTIND
443 #if !HAVE_DECL_OPTERR
447 #if !HAVE_DECL_ENVIRON
448 extern char **environ
;
451 #ifndef HAVE_GETIPNODEBYNAME
452 struct hostent
* ROKEN_LIB_FUNCTION
453 getipnodebyname (const char *, int, int, int *);
456 #ifndef HAVE_GETIPNODEBYADDR
457 struct hostent
* ROKEN_LIB_FUNCTION
458 getipnodebyaddr (const void *, size_t, int, int *);
461 #ifndef HAVE_FREEHOSTENT
462 void ROKEN_LIB_FUNCTION
463 freehostent (struct hostent
*);
466 #ifndef HAVE_COPYHOSTENT
467 struct hostent
* ROKEN_LIB_FUNCTION
468 copyhostent (const struct hostent
*);
471 #ifndef HAVE_SOCKLEN_T
472 typedef int socklen_t
;
475 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
477 #ifndef HAVE_SA_FAMILY_T
478 typedef unsigned short sa_family_t
;
482 #define _SS_MAXSIZE sizeof(struct sockaddr_in6)
484 #define _SS_MAXSIZE sizeof(struct sockaddr_in)
487 #define _SS_ALIGNSIZE sizeof(unsigned long)
489 #if HAVE_STRUCT_SOCKADDR_SA_LEN
491 typedef unsigned char roken_sa_family_t
;
493 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE)
494 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
496 struct sockaddr_storage
{
497 unsigned char ss_len
;
498 roken_sa_family_t ss_family
;
499 char __ss_pad1
[_SS_PAD1SIZE
];
500 unsigned long __ss_align
[_SS_PAD2SIZE
/ sizeof(unsigned long) + 1];
503 #else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
505 typedef unsigned short roken_sa_family_t
;
507 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE)
508 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
510 struct sockaddr_storage
{
511 roken_sa_family_t ss_family
;
512 char __ss_pad1
[_SS_PAD1SIZE
];
513 unsigned long __ss_align
[_SS_PAD2SIZE
/ sizeof(unsigned long) + 1];
516 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
518 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
520 #ifndef HAVE_STRUCT_ADDRINFO
528 struct sockaddr
*ai_addr
;
529 struct addrinfo
*ai_next
;
533 #ifndef HAVE_GETADDRINFO
534 int ROKEN_LIB_FUNCTION
535 getaddrinfo(const char *,
537 const struct addrinfo
*,
541 #ifndef HAVE_GETNAMEINFO
542 int ROKEN_LIB_FUNCTION
543 getnameinfo(const struct sockaddr
*, socklen_t
,
549 #ifndef HAVE_FREEADDRINFO
550 void ROKEN_LIB_FUNCTION
551 freeaddrinfo(struct addrinfo
*);
554 #ifndef HAVE_GAI_STRERROR
555 const char * ROKEN_LIB_FUNCTION
559 int ROKEN_LIB_FUNCTION
560 getnameinfo_verified(const struct sockaddr
*, socklen_t
,
565 int ROKEN_LIB_FUNCTION
566 roken_getaddrinfo_hostspec(const char *, int, struct addrinfo
**);
567 int ROKEN_LIB_FUNCTION
568 roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo
**);
570 #ifndef HAVE_STRFTIME
571 size_t ROKEN_LIB_FUNCTION
572 strftime (char *, size_t, const char *, const struct tm
*);
575 #ifndef HAVE_STRPTIME
576 char * ROKEN_LIB_FUNCTION
577 strptime (const char *, const char *, struct tm
*);
581 void * ROKEN_LIB_FUNCTION
emalloc (size_t);
584 void * ROKEN_LIB_FUNCTION
ecalloc(size_t, size_t);
586 #ifndef HAVE_EREALLOC
587 void * ROKEN_LIB_FUNCTION
erealloc (void *, size_t);
590 char * ROKEN_LIB_FUNCTION
estrdup (const char *);
598 int ROKEN_LIB_FUNCTION
599 roken_gethostby_setup(const char*, const char*);
600 struct hostent
* ROKEN_LIB_FUNCTION
601 roken_gethostbyname(const char*);
602 struct hostent
* ROKEN_LIB_FUNCTION
603 roken_gethostbyaddr(const void*, size_t, int);
605 #ifdef GETHOSTBYNAME_PROTO_COMPATIBLE
606 #define roken_gethostbyname(x) gethostbyname(x)
608 #define roken_gethostbyname(x) gethostbyname((char *)x)
611 #ifdef GETHOSTBYADDR_PROTO_COMPATIBLE
612 #define roken_gethostbyaddr(a, l, t) gethostbyaddr(a, l, t)
614 #define roken_gethostbyaddr(a, l, t) gethostbyaddr((char *)a, l, t)
618 #ifdef GETSERVBYNAME_PROTO_COMPATIBLE
619 #define roken_getservbyname(x,y) getservbyname(x,y)
621 #define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y)
624 #ifdef OPENLOG_PROTO_COMPATIBLE
625 #define roken_openlog(a,b,c) openlog(a,b,c)
627 #define roken_openlog(a,b,c) openlog((char *)a,b,c)
630 #ifdef GETSOCKNAME_PROTO_COMPATIBLE
631 #define roken_getsockname(a,b,c) getsockname(a,b,c)
633 #define roken_getsockname(a,b,c) getsockname(a, b, (void*)c)
636 #ifndef HAVE_SETPROGNAME
637 void ROKEN_LIB_FUNCTION
setprogname(const char *);
640 #ifndef HAVE_GETPROGNAME
641 const char * ROKEN_LIB_FUNCTION
getprogname(void);
644 #if !defined(HAVE_SETPROGNAME) && !defined(HAVE_GETPROGNAME) && !HAVE_DECL___PROGNAME
645 extern const char *__progname
;
648 void ROKEN_LIB_FUNCTION
mini_inetd_addrinfo (struct addrinfo
*);
649 void ROKEN_LIB_FUNCTION
mini_inetd (int);
651 #ifndef HAVE_LOCALTIME_R
652 struct tm
* ROKEN_LIB_FUNCTION
653 localtime_r(const time_t *, struct tm
*);
656 #if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO)
657 int ROKEN_LIB_FUNCTION
658 strsvis(char *, const char *, int, const char *);
661 #if !defined(HAVE_STRUNVIS) || defined(NEED_STRUNVIS_PROTO)
662 int ROKEN_LIB_FUNCTION
663 strunvis(char *, const char *);
666 #if !defined(HAVE_STRVIS) || defined(NEED_STRVIS_PROTO)
667 int ROKEN_LIB_FUNCTION
668 strvis(char *, const char *, int);
671 #if !defined(HAVE_STRVISX) || defined(NEED_STRVISX_PROTO)
672 int ROKEN_LIB_FUNCTION
673 strvisx(char *, const char *, size_t, int);
676 #if !defined(HAVE_SVIS) || defined(NEED_SVIS_PROTO)
677 char * ROKEN_LIB_FUNCTION
678 svis(char *, int, int, int, const char *);
681 #if !defined(HAVE_UNVIS) || defined(NEED_UNVIS_PROTO)
682 int ROKEN_LIB_FUNCTION
683 unvis(char *, int, int *, int);
686 #if !defined(HAVE_VIS) || defined(NEED_VIS_PROTO)
687 char * ROKEN_LIB_FUNCTION
688 vis(char *, int, int, int);
691 #if !defined(HAVE_CLOSEFROM)
692 int ROKEN_LIB_FUNCTION
696 #if !defined(HAVE_TIMEGM)
697 #define timegm rk_timegm
698 time_t ROKEN_LIB_FUNCTION
699 rk_timegm(struct tm
*tm
);
702 #ifdef SOCKET_WRAPPER_REPLACE
703 #include <socket_wrapper.h>