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