xref: /freebsd/crypto/heimdal/lib/roken/roken.h.in (revision 9336e0699bda8a301cd2bfa37106b6ec5e32012e)
1/* -*- C -*- */
2/*
3 * Copyright (c) 1995 - 2002 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.169 2002/08/26 21:43:38 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_ARPA_NAMESER_H
96#include <arpa/nameser.h>
97#endif
98#ifdef HAVE_RESOLV_H
99#include <resolv.h>
100#endif
101#ifdef HAVE_SYSLOG_H
102#include <syslog.h>
103#endif
104#ifdef HAVE_FCNTL_H
105#include <fcntl.h>
106#endif
107#ifdef HAVE_ERRNO_H
108#include <errno.h>
109#endif
110#ifdef HAVE_ERR_H
111#include <err.h>
112#endif
113#ifdef HAVE_TERMIOS_H
114#include <termios.h>
115#endif
116#if defined(HAVE_SYS_IOCTL_H) && SunOS != 40
117#include <sys/ioctl.h>
118#endif
119#ifdef TIME_WITH_SYS_TIME
120#include <sys/time.h>
121#include <time.h>
122#elif defined(HAVE_SYS_TIME_H)
123#include <sys/time.h>
124#else
125#include <time.h>
126#endif
127
128#ifdef HAVE_PATHS_H
129#include <paths.h>
130#endif
131
132
133#ifndef ROKEN_LIB_FUNCTION
134#if defined(__BORLANDC__)
135#define ROKEN_LIB_FUNCTION /* not-ready-definition-yet */
136#elif defined(_MSC_VER)
137#define ROKEN_LIB_FUNCTION /* not-ready-definition-yet2 */
138#else
139#define ROKEN_LIB_FUNCTION
140#endif
141#endif
142
143#ifndef HAVE_SSIZE_T
144typedef int ssize_t;
145#endif
146
147#include <roken-common.h>
148
149ROKEN_CPP_START
150
151#if !defined(HAVE_SETSID) && defined(HAVE__SETSID)
152#define setsid _setsid
153#endif
154
155#ifndef HAVE_PUTENV
156int putenv(const char *string);
157#endif
158
159#if !defined(HAVE_SETENV) || defined(NEED_SETENV_PROTO)
160int setenv(const char *var, const char *val, int rewrite);
161#endif
162
163#if !defined(HAVE_UNSETENV) || defined(NEED_UNSETENV_PROTO)
164void unsetenv(const char *name);
165#endif
166
167#if !defined(HAVE_GETUSERSHELL) || defined(NEED_GETUSERSHELL_PROTO)
168char *getusershell(void);
169void endusershell(void);
170#endif
171
172#if !defined(HAVE_SNPRINTF) || defined(NEED_SNPRINTF_PROTO)
173int snprintf (char *str, size_t sz, const char *format, ...)
174     __attribute__ ((format (printf, 3, 4)));
175#endif
176
177#if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO)
178int vsnprintf (char *str, size_t sz, const char *format, va_list ap)
179     __attribute__((format (printf, 3, 0)));
180#endif
181
182#if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO)
183int asprintf (char **ret, const char *format, ...)
184     __attribute__ ((format (printf, 2, 3)));
185#endif
186
187#if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO)
188int vasprintf (char **ret, const char *format, va_list ap)
189     __attribute__((format (printf, 2, 0)));
190#endif
191
192#if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO)
193int asnprintf (char **ret, size_t max_sz, const char *format, ...)
194     __attribute__ ((format (printf, 3, 4)));
195#endif
196
197#if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO)
198int vasnprintf (char **ret, size_t max_sz, const char *format, va_list ap)
199     __attribute__((format (printf, 3, 0)));
200#endif
201
202#ifndef HAVE_STRDUP
203char * strdup(const char *old);
204#endif
205
206#if !defined(HAVE_STRNDUP) || defined(NEED_STRNDUP_PROTO)
207char * strndup(const char *old, size_t sz);
208#endif
209
210#ifndef HAVE_STRLWR
211char * strlwr(char *);
212#endif
213
214#ifndef HAVE_STRNLEN
215size_t strnlen(const char*, size_t);
216#endif
217
218#if !defined(HAVE_STRSEP) || defined(NEED_STRSEP_PROTO)
219char *strsep(char**, const char*);
220#endif
221
222#if !defined(HAVE_STRSEP_COPY) || defined(NEED_STRSEP_COPY_PROTO)
223ssize_t strsep_copy(const char**, const char*, char*, size_t);
224#endif
225
226#ifndef HAVE_STRCASECMP
227int strcasecmp(const char *s1, const char *s2);
228#endif
229
230#ifdef NEED_FCLOSE_PROTO
231int fclose(FILE *);
232#endif
233
234#ifdef NEED_STRTOK_R_PROTO
235char *strtok_r(char *s1, const char *s2, char **lasts);
236#endif
237
238#ifndef HAVE_STRUPR
239char * strupr(char *);
240#endif
241
242#ifndef HAVE_STRLCPY
243size_t strlcpy (char *dst, const char *src, size_t dst_sz);
244#endif
245
246#ifndef HAVE_STRLCAT
247size_t strlcat (char *dst, const char *src, size_t dst_sz);
248#endif
249
250#ifndef HAVE_GETDTABLESIZE
251int getdtablesize(void);
252#endif
253
254#if !defined(HAVE_STRERROR) && !defined(strerror)
255char *strerror(int eno);
256#endif
257
258#if !defined(HAVE_HSTRERROR) || defined(NEED_HSTRERROR_PROTO)
259/* This causes a fatal error under Psoriasis */
260#if !(defined(SunOS) && (SunOS >= 50))
261const char *hstrerror(int herr);
262#endif
263#endif
264
265#ifndef HAVE_H_ERRNO_DECLARATION
266extern int h_errno;
267#endif
268
269#if !defined(HAVE_INET_ATON) || defined(NEED_INET_ATON_PROTO)
270int inet_aton(const char *cp, struct in_addr *adr);
271#endif
272
273#ifndef HAVE_INET_NTOP
274const char *
275inet_ntop(int af, const void *src, char *dst, size_t size);
276#endif
277
278#ifndef HAVE_INET_PTON
279int
280inet_pton(int af, const char *src, void *dst);
281#endif
282
283#if !defined(HAVE_GETCWD)
284char* getcwd(char *path, size_t size);
285#endif
286
287#ifdef HAVE_PWD_H
288#include <pwd.h>
289struct passwd *k_getpwnam (const char *user);
290struct passwd *k_getpwuid (uid_t uid);
291#endif
292
293const char *get_default_username (void);
294
295#ifndef HAVE_SETEUID
296int seteuid(uid_t euid);
297#endif
298
299#ifndef HAVE_SETEGID
300int setegid(gid_t egid);
301#endif
302
303#ifndef HAVE_LSTAT
304int lstat(const char *path, struct stat *buf);
305#endif
306
307#if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO)
308int mkstemp(char *);
309#endif
310
311#ifndef HAVE_CGETENT
312int cgetent(char **buf, char **db_array, const char *name);
313int cgetstr(char *buf, const char *cap, char **str);
314#endif
315
316#ifndef HAVE_INITGROUPS
317int initgroups(const char *name, gid_t basegid);
318#endif
319
320#ifndef HAVE_FCHOWN
321int fchown(int fd, uid_t owner, gid_t group);
322#endif
323
324#ifndef HAVE_DAEMON
325int daemon(int nochdir, int noclose);
326#endif
327
328#ifndef HAVE_INNETGR
329int innetgr(const char *netgroup, const char *machine,
330	    const char *user, const char *domain);
331#endif
332
333#ifndef HAVE_CHOWN
334int chown(const char *path, uid_t owner, gid_t group);
335#endif
336
337#ifndef HAVE_RCMD
338int rcmd(char **ahost, unsigned short inport, const char *locuser,
339	 const char *remuser, const char *cmd, int *fd2p);
340#endif
341
342#if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO)
343int innetgr(const char*, const char*, const char*, const char*);
344#endif
345
346#ifndef HAVE_IRUSEROK
347int iruserok(unsigned raddr, int superuser, const char *ruser,
348	     const char *luser);
349#endif
350
351#if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO)
352int gethostname(char *name, int namelen);
353#endif
354
355#ifndef HAVE_WRITEV
356ssize_t
357writev(int d, const struct iovec *iov, int iovcnt);
358#endif
359
360#ifndef HAVE_READV
361ssize_t
362readv(int d, const struct iovec *iov, int iovcnt);
363#endif
364
365#ifndef HAVE_MKSTEMP
366int
367mkstemp(char *template);
368#endif
369
370#ifndef HAVE_PIDFILE
371void pidfile (const char*);
372#endif
373
374#ifndef HAVE_BSWAP32
375unsigned int bswap32(unsigned int);
376#endif
377
378#ifndef HAVE_BSWAP16
379unsigned short bswap16(unsigned short);
380#endif
381
382#ifndef HAVE_FLOCK
383#ifndef LOCK_SH
384#define LOCK_SH   1		/* Shared lock */
385#endif
386#ifndef	LOCK_EX
387#define LOCK_EX   2		/* Exclusive lock */
388#endif
389#ifndef LOCK_NB
390#define LOCK_NB   4		/* Don't block when locking */
391#endif
392#ifndef LOCK_UN
393#define LOCK_UN   8		/* Unlock */
394#endif
395
396int flock(int fd, int operation);
397#endif /* HAVE_FLOCK */
398
399time_t tm2time (struct tm tm, int local);
400
401int unix_verify_user(char *user, char *password);
402
403int roken_concat (char *s, size_t len, ...);
404
405size_t roken_mconcat (char **s, size_t max_len, ...);
406
407int roken_vconcat (char *s, size_t len, va_list args);
408
409size_t roken_vmconcat (char **s, size_t max_len, va_list args);
410
411ssize_t net_write (int fd, const void *buf, size_t nbytes);
412
413ssize_t net_read (int fd, void *buf, size_t nbytes);
414
415int issuid(void);
416
417#ifndef HAVE_STRUCT_WINSIZE
418struct winsize {
419	unsigned short ws_row, ws_col;
420	unsigned short ws_xpixel, ws_ypixel;
421};
422#endif
423
424int get_window_size(int fd, struct winsize *);
425
426#ifndef HAVE_VSYSLOG
427void vsyslog(int pri, const char *fmt, va_list ap);
428#endif
429
430#ifndef HAVE_OPTARG_DECLARATION
431extern char *optarg;
432#endif
433#ifndef HAVE_OPTIND_DECLARATION
434extern int optind;
435#endif
436#ifndef HAVE_OPTERR_DECLARATION
437extern int opterr;
438#endif
439
440#ifndef HAVE___PROGNAME_DECLARATION
441extern const char *__progname;
442#endif
443
444#ifndef HAVE_ENVIRON_DECLARATION
445extern char **environ;
446#endif
447
448#ifndef HAVE_GETIPNODEBYNAME
449struct hostent *
450getipnodebyname (const char *name, int af, int flags, int *error_num);
451#endif
452
453#ifndef HAVE_GETIPNODEBYADDR
454struct hostent *
455getipnodebyaddr (const void *src, size_t len, int af, int *error_num);
456#endif
457
458#ifndef HAVE_FREEHOSTENT
459void
460freehostent (struct hostent *h);
461#endif
462
463#ifndef HAVE_COPYHOSTENT
464struct hostent *
465copyhostent (const struct hostent *h);
466#endif
467
468#ifndef HAVE_SOCKLEN_T
469typedef int socklen_t;
470#endif
471
472#ifndef HAVE_STRUCT_SOCKADDR_STORAGE
473
474#ifndef HAVE_SA_FAMILY_T
475typedef unsigned short sa_family_t;
476#endif
477
478#ifdef HAVE_IPV6
479#define _SS_MAXSIZE sizeof(struct sockaddr_in6)
480#else
481#define _SS_MAXSIZE sizeof(struct sockaddr_in)
482#endif
483
484#define _SS_ALIGNSIZE	sizeof(unsigned long)
485
486#if HAVE_STRUCT_SOCKADDR_SA_LEN
487
488typedef unsigned char roken_sa_family_t;
489
490#define _SS_PAD1SIZE   ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE)
491#define _SS_PAD2SIZE   (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
492
493struct sockaddr_storage {
494    unsigned char	ss_len;
495    roken_sa_family_t	ss_family;
496    char		__ss_pad1[_SS_PAD1SIZE];
497    unsigned long	__ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
498};
499
500#else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
501
502typedef unsigned short roken_sa_family_t;
503
504#define _SS_PAD1SIZE   ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE)
505#define _SS_PAD2SIZE   (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
506
507struct sockaddr_storage {
508    roken_sa_family_t	ss_family;
509    char		__ss_pad1[_SS_PAD1SIZE];
510    unsigned long	__ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
511};
512
513#endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
514
515#endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
516
517#ifndef HAVE_STRUCT_ADDRINFO
518struct addrinfo {
519    int    ai_flags;
520    int    ai_family;
521    int    ai_socktype;
522    int    ai_protocol;
523    size_t ai_addrlen;
524    char  *ai_canonname;
525    struct sockaddr *ai_addr;
526    struct addrinfo *ai_next;
527};
528#endif
529
530#ifndef HAVE_GETADDRINFO
531int
532getaddrinfo(const char *nodename,
533	    const char *servname,
534	    const struct addrinfo *hints,
535	    struct addrinfo **res);
536#endif
537
538#ifndef HAVE_GETNAMEINFO
539int getnameinfo(const struct sockaddr *sa, socklen_t salen,
540		char *host, size_t hostlen,
541		char *serv, size_t servlen,
542		int flags);
543#endif
544
545#ifndef HAVE_FREEADDRINFO
546void
547freeaddrinfo(struct addrinfo *ai);
548#endif
549
550#ifndef HAVE_GAI_STRERROR
551char *
552gai_strerror(int ecode);
553#endif
554
555int
556getnameinfo_verified(const struct sockaddr *sa, socklen_t salen,
557		     char *host, size_t hostlen,
558		     char *serv, size_t servlen,
559		     int flags);
560
561int roken_getaddrinfo_hostspec(const char *, int, struct addrinfo **);
562int roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo **);
563
564#ifndef HAVE_STRFTIME
565size_t
566strftime (char *buf, size_t maxsize, const char *format,
567	  const struct tm *tm);
568#endif
569
570#ifndef HAVE_STRPTIME
571char *
572strptime (const char *buf, const char *format, struct tm *timeptr);
573#endif
574
575#ifndef HAVE_EMALLOC
576void *emalloc (size_t);
577#endif
578#ifndef HAVE_ECALLOC
579void *ecalloc(size_t num, size_t sz);
580#endif
581#ifndef HAVE_EREALLOC
582void *erealloc (void *, size_t);
583#endif
584#ifndef HAVE_ESTRDUP
585char *estrdup (const char *);
586#endif
587
588/*
589 * kludges and such
590 */
591
592#if 1
593int roken_gethostby_setup(const char*, const char*);
594struct hostent* roken_gethostbyname(const char*);
595struct hostent* roken_gethostbyaddr(const void*, size_t, int);
596#else
597#ifdef GETHOSTBYNAME_PROTO_COMPATIBLE
598#define roken_gethostbyname(x) gethostbyname(x)
599#else
600#define roken_gethostbyname(x) gethostbyname((char *)x)
601#endif
602
603#ifdef GETHOSTBYADDR_PROTO_COMPATIBLE
604#define roken_gethostbyaddr(a, l, t) gethostbyaddr(a, l, t)
605#else
606#define roken_gethostbyaddr(a, l, t) gethostbyaddr((char *)a, l, t)
607#endif
608#endif
609
610#ifdef GETSERVBYNAME_PROTO_COMPATIBLE
611#define roken_getservbyname(x,y) getservbyname(x,y)
612#else
613#define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y)
614#endif
615
616#ifdef OPENLOG_PROTO_COMPATIBLE
617#define roken_openlog(a,b,c) openlog(a,b,c)
618#else
619#define roken_openlog(a,b,c) openlog((char *)a,b,c)
620#endif
621
622#ifdef GETSOCKNAME_PROTO_COMPATIBLE
623#define roken_getsockname(a,b,c) getsockname(a,b,c)
624#else
625#define roken_getsockname(a,b,c) getsockname(a, b, (void*)c)
626#endif
627
628#ifndef HAVE_SETPROGNAME
629void setprogname(const char *argv0);
630#endif
631
632#ifndef HAVE_GETPROGNAME
633const char *getprogname(void);
634#endif
635
636void mini_inetd_addrinfo (struct addrinfo*);
637void mini_inetd (int port);
638
639void set_progname(char *argv0);
640const char *get_progname(void);
641
642#ifndef HAVE_LOCALTIME_R
643struct tm *
644localtime_r(const time_t *timer, struct tm *result);
645#endif
646
647#if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO)
648int
649strsvis(char *dst, const char *src, int flag, const char *extra);
650#endif
651
652#if !defined(HAVE_STRUNVIS) || defined(NEED_STRUNVIS_PROTO)
653int
654strunvis(char *dst, const char *src);
655#endif
656
657#if !defined(HAVE_STRVIS) || defined(NEED_STRVIS_PROTO)
658int
659strvis(char *dst, const char *src, int flag);
660#endif
661
662#if !defined(HAVE_STRVISX) || defined(NEED_STRVISX_PROTO)
663int
664strvisx(char *dst, const char *src, size_t len, int flag);
665#endif
666
667#if !defined(HAVE_SVIS) || defined(NEED_SVIS_PROTO)
668char *
669svis(char *dst, int c, int flag, int nextc, const char *extra);
670#endif
671
672#if !defined(HAVE_UNVIS) || defined(NEED_UNVIS_PROTO)
673int
674unvis(char *cp, int c, int *astate, int flag);
675#endif
676
677#if !defined(HAVE_VIS) || defined(NEED_VIS_PROTO)
678char *
679vis(char *dst, int c, int flag, int nextc);
680#endif
681
682ROKEN_CPP_END
683