roken.h.in revision 78527
1/* -*- C -*- */
2/*
3 * Copyright (c) 1995 - 2001 Kungliga Tekniska H�gskolan
4 * (Royal Institute of Technology, Stockholm, Sweden).
5 * All rights reserved.
6 * 
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 
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.
17 * 
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.
21 * 
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
32 * SUCH DAMAGE.
33 */
34
35/* $Id: roken.h.in,v 1.157 2001/05/18 18:00:12 assar Exp $ */
36
37#include <stdio.h>
38#include <stdlib.h>
39#include <stdarg.h>
40#include <string.h>
41#include <signal.h>
42
43#ifdef _AIX
44struct ether_addr;
45struct sockaddr_dl;
46#endif
47#ifdef HAVE_SYS_PARAM_H
48#include <sys/param.h>
49#endif
50#ifdef HAVE_INTTYPES_H
51#include <inttypes.h>
52#endif
53#ifdef HAVE_SYS_TYPES_H
54#include <sys/types.h>
55#endif
56#ifdef HAVE_SYS_BITYPES_H
57#include <sys/bitypes.h>
58#endif
59#ifdef HAVE_BIND_BITYPES_H
60#include <bind/bitypes.h>
61#endif
62#ifdef HAVE_NETINET_IN6_MACHTYPES_H
63#include <netinet/in6_machtypes.h>
64#endif
65#ifdef HAVE_UNISTD_H
66#include <unistd.h>
67#endif
68#ifdef HAVE_SYS_SOCKET_H
69#include <sys/socket.h>
70#endif
71#ifdef HAVE_SYS_UIO_H
72#include <sys/uio.h>
73#endif
74#ifdef HAVE_GRP_H
75#include <grp.h>
76#endif
77#ifdef HAVE_SYS_STAT_H
78#include <sys/stat.h>
79#endif
80#ifdef HAVE_NETINET_IN_H
81#include <netinet/in.h>
82#endif
83#ifdef HAVE_NETINET_IN6_H
84#include <netinet/in6.h>
85#endif
86#ifdef HAVE_NETINET6_IN6_H
87#include <netinet6/in6.h>
88#endif
89#ifdef HAVE_ARPA_INET_H
90#include <arpa/inet.h>
91#endif
92#ifdef HAVE_NETDB_H
93#include <netdb.h>
94#endif
95#ifdef HAVE_SYSLOG_H
96#include <syslog.h>
97#endif
98#ifdef HAVE_WINSOCK_H
99#include <winsock.h>
100#endif
101#ifdef HAVE_FCNTL_H
102#include <fcntl.h>
103#endif
104#ifdef HAVE_ERRNO_H
105#include <errno.h>
106#endif
107#ifdef HAVE_ERR_H
108#include <err.h>
109#endif
110#ifdef HAVE_TERMIOS_H
111#include <termios.h>
112#endif
113#if defined(HAVE_SYS_IOCTL_H) && SunOS != 40
114#include <sys/ioctl.h>
115#endif
116#ifdef TIME_WITH_SYS_TIME
117#include <sys/time.h>
118#include <time.h>
119#elif defined(HAVE_SYS_TIME_H)
120#include <sys/time.h>
121#else
122#include <time.h>
123#endif
124
125#ifdef HAVE_PATHS_H
126#include <paths.h>
127#endif
128
129
130#ifndef ROKEN_LIB_FUNCTION
131#if defined(__BORLANDC__)
132#define ROKEN_LIB_FUNCTION /* not-ready-definition-yet */
133#elif defined(_MSC_VER)
134#define ROKEN_LIB_FUNCTION /* not-ready-definition-yet2 */
135#else
136#define ROKEN_LIB_FUNCTION
137#endif
138#endif
139
140#include <roken-common.h>
141
142ROKEN_CPP_START
143
144#if !defined(HAVE_SETSID) && defined(HAVE__SETSID)
145#define setsid _setsid
146#endif
147
148#ifndef HAVE_PUTENV
149int putenv(const char *string);
150#endif
151
152#if !defined(HAVE_SETENV) || defined(NEED_SETENV_PROTO)
153int setenv(const char *var, const char *val, int rewrite);
154#endif
155
156#if !defined(HAVE_UNSETENV) || defined(NEED_UNSETENV_PROTO)
157void unsetenv(const char *name);
158#endif
159
160#if !defined(HAVE_GETUSERSHELL) || defined(NEED_GETUSERSHELL_PROTO)
161char *getusershell(void);
162void endusershell(void);
163#endif
164
165#if !defined(HAVE_SNPRINTF) || defined(NEED_SNPRINTF_PROTO)
166int snprintf (char *str, size_t sz, const char *format, ...)
167     __attribute__ ((format (printf, 3, 4)));
168#endif
169
170#if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO)
171int vsnprintf (char *str, size_t sz, const char *format, va_list ap)
172     __attribute__((format (printf, 3, 0)));
173#endif
174
175#if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO)
176int asprintf (char **ret, const char *format, ...)
177     __attribute__ ((format (printf, 2, 3)));
178#endif
179
180#if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO)
181int vasprintf (char **ret, const char *format, va_list ap)
182     __attribute__((format (printf, 2, 0)));
183#endif
184
185#if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO)
186int asnprintf (char **ret, size_t max_sz, const char *format, ...)
187     __attribute__ ((format (printf, 3, 4)));
188#endif
189
190#if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO)
191int vasnprintf (char **ret, size_t max_sz, const char *format, va_list ap)
192     __attribute__((format (printf, 3, 0)));
193#endif
194
195#ifndef HAVE_STRDUP
196char * strdup(const char *old);
197#endif
198
199#ifndef HAVE_STRNDUP
200char * strndup(const char *old, size_t sz);
201#endif
202
203#ifndef HAVE_STRLWR
204char * strlwr(char *);
205#endif
206
207#ifndef HAVE_STRNLEN
208size_t strnlen(const char*, size_t);
209#endif
210
211#if !defined(HAVE_STRSEP) || defined(NEED_STRSEP_PROTO)
212char *strsep(char**, const char*);
213#endif
214
215#if !defined(HAVE_STRSEP_COPY) || defined(NEED_STRSEP_COPY_PROTO)
216ssize_t strsep_copy(const char**, const char*, char*, size_t);
217#endif
218
219#ifndef HAVE_STRCASECMP
220int strcasecmp(const char *s1, const char *s2);
221#endif
222
223#ifdef NEED_FCLOSE_PROTO
224int fclose(FILE *);
225#endif
226
227#ifdef NEED_STRTOK_R_PROTO
228char *strtok_r(char *s1, const char *s2, char **lasts);
229#endif
230
231#ifndef HAVE_STRUPR
232char * strupr(char *);
233#endif
234
235#ifndef HAVE_STRLCPY
236size_t strlcpy (char *dst, const char *src, size_t dst_sz);
237#endif
238
239#ifndef HAVE_STRLCAT
240size_t strlcat (char *dst, const char *src, size_t dst_sz);
241#endif
242
243#ifndef HAVE_GETDTABLESIZE
244int getdtablesize(void);
245#endif
246
247#if !defined(HAVE_STRERROR) && !defined(strerror)
248char *strerror(int eno);
249#endif
250
251#if !defined(HAVE_HSTRERROR) || defined(NEED_HSTRERROR_PROTO)
252/* This causes a fatal error under Psoriasis */
253#if !(defined(SunOS) && (SunOS >= 50))
254const char *hstrerror(int herr);
255#endif
256#endif
257
258#ifndef HAVE_H_ERRNO_DECLARATION
259extern int h_errno;
260#endif
261
262#if !defined(HAVE_INET_ATON) || defined(NEED_INET_ATON_PROTO)
263int inet_aton(const char *cp, struct in_addr *adr);
264#endif
265
266#ifndef HAVE_INET_NTOP
267const char *
268inet_ntop(int af, const void *src, char *dst, size_t size);
269#endif
270
271#ifndef HAVE_INET_PTON
272int
273inet_pton(int af, const char *src, void *dst);
274#endif
275
276#if !defined(HAVE_GETCWD)
277char* getcwd(char *path, size_t size);
278#endif
279
280#ifdef HAVE_PWD_H
281#include <pwd.h>
282struct passwd *k_getpwnam (const char *user);
283struct passwd *k_getpwuid (uid_t uid);
284#endif
285
286const char *get_default_username (void);
287
288#ifndef HAVE_SETEUID
289int seteuid(uid_t euid);
290#endif
291
292#ifndef HAVE_SETEGID
293int setegid(gid_t egid);
294#endif
295
296#ifndef HAVE_LSTAT
297int lstat(const char *path, struct stat *buf);
298#endif
299
300#if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO)
301int mkstemp(char *);
302#endif
303
304#ifndef HAVE_CGETENT
305int cgetent(char **buf, char **db_array, const char *name);
306int cgetstr(char *buf, const char *cap, char **str);
307#endif
308
309#ifndef HAVE_INITGROUPS
310int initgroups(const char *name, gid_t basegid);
311#endif
312
313#ifndef HAVE_FCHOWN
314int fchown(int fd, uid_t owner, gid_t group);
315#endif
316
317#ifndef HAVE_DAEMON
318int daemon(int nochdir, int noclose);
319#endif
320
321#ifndef HAVE_INNETGR
322int innetgr(const char *netgroup, const char *machine, 
323	    const char *user, const char *domain);
324#endif
325
326#ifndef HAVE_CHOWN
327int chown(const char *path, uid_t owner, gid_t group);
328#endif
329
330#ifndef HAVE_RCMD
331int rcmd(char **ahost, unsigned short inport, const char *locuser,
332	 const char *remuser, const char *cmd, int *fd2p);
333#endif
334
335#if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO)
336int innetgr(const char*, const char*, const char*, const char*);
337#endif
338
339#ifndef HAVE_IRUSEROK
340int iruserok(unsigned raddr, int superuser, const char *ruser,
341	     const char *luser);
342#endif
343
344#if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO)
345int gethostname(char *name, int namelen);
346#endif
347
348#ifndef HAVE_WRITEV
349ssize_t
350writev(int d, const struct iovec *iov, int iovcnt);
351#endif
352
353#ifndef HAVE_READV
354ssize_t
355readv(int d, const struct iovec *iov, int iovcnt);
356#endif
357
358#ifndef HAVE_MKSTEMP
359int
360mkstemp(char *template);
361#endif
362
363#ifndef HAVE_PIDFILE
364void pidfile (const char*);
365#endif
366
367#ifndef HAVE_BSWAP32
368unsigned int bswap32(unsigned int);
369#endif
370
371#ifndef HAVE_BSWAP16
372unsigned short bswap16(unsigned short);
373#endif
374
375#ifndef HAVE_FLOCK
376#ifndef LOCK_SH
377#define LOCK_SH   1		/* Shared lock */
378#endif
379#ifndef	LOCK_EX
380#define LOCK_EX   2		/* Exclusive lock */
381#endif
382#ifndef LOCK_NB
383#define LOCK_NB   4		/* Don't block when locking */
384#endif
385#ifndef LOCK_UN
386#define LOCK_UN   8		/* Unlock */
387#endif
388
389int flock(int fd, int operation);
390#endif /* HAVE_FLOCK */
391
392time_t tm2time (struct tm tm, int local);
393
394int unix_verify_user(char *user, char *password);
395
396void mini_inetd (int port);
397
398int roken_concat (char *s, size_t len, ...);
399
400size_t roken_mconcat (char **s, size_t max_len, ...);
401
402int roken_vconcat (char *s, size_t len, va_list args);
403
404size_t roken_vmconcat (char **s, size_t max_len, va_list args);
405
406ssize_t net_write (int fd, const void *buf, size_t nbytes);
407
408ssize_t net_read (int fd, void *buf, size_t nbytes);
409
410int issuid(void);
411
412#ifndef HAVE_STRUCT_WINSIZE
413struct winsize {
414	unsigned short ws_row, ws_col;
415	unsigned short ws_xpixel, ws_ypixel;
416};
417#endif
418
419int get_window_size(int fd, struct winsize *);
420
421#ifndef HAVE_VSYSLOG
422void vsyslog(int pri, const char *fmt, va_list ap);
423#endif
424
425#ifndef HAVE_OPTARG_DECLARATION
426extern char *optarg;
427#endif
428#ifndef HAVE_OPTIND_DECLARATION
429extern int optind;
430#endif
431#ifndef HAVE_OPTERR_DECLARATION
432extern int opterr;
433#endif
434
435#ifndef HAVE___PROGNAME_DECLARATION
436extern const char *__progname;
437#endif
438
439#ifndef HAVE_ENVIRON_DECLARATION
440extern char **environ;
441#endif
442
443#ifndef HAVE_GETIPNODEBYNAME
444struct hostent *
445getipnodebyname (const char *name, int af, int flags, int *error_num);
446#endif
447
448#ifndef HAVE_GETIPNODEBYADDR
449struct hostent *
450getipnodebyaddr (const void *src, size_t len, int af, int *error_num);
451#endif
452
453#ifndef HAVE_FREEHOSTENT
454void
455freehostent (struct hostent *h);
456#endif
457
458#ifndef HAVE_COPYHOSTENT
459struct hostent *
460copyhostent (const struct hostent *h);
461#endif
462
463#ifndef HAVE_SOCKLEN_T
464typedef int socklen_t;
465#endif
466
467#ifndef HAVE_STRUCT_SOCKADDR_STORAGE
468
469#ifndef HAVE_SA_FAMILY_T
470typedef unsigned short sa_family_t;
471#endif
472
473#ifdef HAVE_IPV6
474#define _SS_MAXSIZE sizeof(struct sockaddr_in6)
475#else
476#define _SS_MAXSIZE sizeof(struct sockaddr_in)
477#endif
478
479#define _SS_ALIGNSIZE	sizeof(unsigned long)
480
481#if HAVE_STRUCT_SOCKADDR_SA_LEN
482
483typedef unsigned char roken_sa_family_t;
484
485#define _SS_PAD1SIZE   ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE)
486#define _SS_PAD2SIZE   (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
487
488struct sockaddr_storage {
489    unsigned char	ss_len;
490    roken_sa_family_t	ss_family;
491    char		__ss_pad1[_SS_PAD1SIZE];
492    unsigned long	__ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
493};
494
495#else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
496
497typedef unsigned short roken_sa_family_t;
498
499#define _SS_PAD1SIZE   ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE)
500#define _SS_PAD2SIZE   (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
501
502struct sockaddr_storage {
503    roken_sa_family_t	ss_family;
504    char		__ss_pad1[_SS_PAD1SIZE];
505    unsigned long	__ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
506};
507
508#endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
509
510#endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
511
512#ifndef HAVE_STRUCT_ADDRINFO
513struct addrinfo {
514    int    ai_flags;
515    int    ai_family;
516    int    ai_socktype;
517    int    ai_protocol;
518    size_t ai_addrlen;
519    char  *ai_canonname;
520    struct sockaddr *ai_addr;
521    struct addrinfo *ai_next;
522};
523#endif
524
525#ifndef HAVE_GETADDRINFO
526int
527getaddrinfo(const char *nodename,
528	    const char *servname,
529	    const struct addrinfo *hints,
530	    struct addrinfo **res);
531#endif
532
533#ifndef HAVE_GETNAMEINFO
534int getnameinfo(const struct sockaddr *sa, socklen_t salen,
535		char *host, size_t hostlen,
536		char *serv, size_t servlen,
537		int flags);
538#endif
539
540#ifndef HAVE_FREEADDRINFO
541void
542freeaddrinfo(struct addrinfo *ai);
543#endif
544
545#ifndef HAVE_GAI_STRERROR
546char *
547gai_strerror(int ecode);
548#endif
549
550int
551getnameinfo_verified(const struct sockaddr *sa, socklen_t salen,
552		     char *host, size_t hostlen,
553		     char *serv, size_t servlen,
554		     int flags);
555
556int roken_getaddrinfo_hostspec(const char *, int, struct addrinfo **); 
557int roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo **);
558
559#ifndef HAVE_STRFTIME
560size_t
561strftime (char *buf, size_t maxsize, const char *format,
562	  const struct tm *tm);
563#endif
564
565#ifndef HAVE_STRPTIME
566char *
567strptime (const char *buf, const char *format, struct tm *timeptr);
568#endif
569
570/*
571 * kludges and such
572 */
573
574#if 1
575int roken_gethostby_setup(const char*, const char*);
576struct hostent* roken_gethostbyname(const char*);
577struct hostent* roken_gethostbyaddr(const void*, size_t, int);
578#else
579#ifdef GETHOSTBYNAME_PROTO_COMPATIBLE
580#define roken_gethostbyname(x) gethostbyname(x)
581#else
582#define roken_gethostbyname(x) gethostbyname((char *)x)
583#endif
584
585#ifdef GETHOSTBYADDR_PROTO_COMPATIBLE
586#define roken_gethostbyaddr(a, l, t) gethostbyaddr(a, l, t)
587#else
588#define roken_gethostbyaddr(a, l, t) gethostbyaddr((char *)a, l, t)
589#endif
590#endif
591
592#ifdef GETSERVBYNAME_PROTO_COMPATIBLE
593#define roken_getservbyname(x,y) getservbyname(x,y)
594#else
595#define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y)
596#endif
597
598#ifdef OPENLOG_PROTO_COMPATIBLE
599#define roken_openlog(a,b,c) openlog(a,b,c)
600#else
601#define roken_openlog(a,b,c) openlog((char *)a,b,c)
602#endif
603
604#ifdef GETSOCKNAME_PROTO_COMPATIBLE
605#define roken_getsockname(a,b,c) getsockname(a,b,c)
606#else
607#define roken_getsockname(a,b,c) getsockname(a, b, (void*)c)
608#endif
609
610#ifndef HAVE_SETPROGNAME
611void setprogname(const char *argv0);
612#endif
613
614#ifndef HAVE_GETPROGNAME
615const char *getprogname(void);
616#endif
617
618void set_progname(char *argv0);
619const char *get_progname(void);
620
621ROKEN_CPP_END
622