comparison include/dcc_defs.h @ 0:c7f6b056b673

First import of vendor version
author Peter Gervai <grin@grin.hu>
date Tue, 10 Mar 2009 13:49:58 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c7f6b056b673
1 /* Distributed Checksum Clearinghouse
2 *
3 * common definitions internal to client libraries and servers
4 *
5 * Copyright (c) 2008 by Rhyolite Software, LLC
6 *
7 * This agreement is not applicable to any entity which sells anti-spam
8 * solutions to others or provides an anti-spam solution as part of a
9 * security solution sold to other entities, or to a private network
10 * which employs the DCC or uses data provided by operation of the DCC
11 * but does not provide corresponding data to other users.
12 *
13 * Permission to use, copy, modify, and distribute this software without
14 * changes for any purpose with or without fee is hereby granted, provided
15 * that the above copyright notice and this permission notice appear in all
16 * copies and any distributed versions or copies are either unchanged
17 * or not called anything similar to "DCC" or "Distributed Checksum
18 * Clearinghouse".
19 *
20 * Parties not eligible to receive a license under this agreement can
21 * obtain a commercial license to use DCC by contacting Rhyolite Software
22 * at sales@rhyolite.com.
23 *
24 * A commercial license would be for Distributed Checksum and Reputation
25 * Clearinghouse software. That software includes additional features. This
26 * free license for Distributed ChecksumClearinghouse Software does not in any
27 * way grant permision to use Distributed Checksum and Reputation Clearinghouse
28 * software
29 *
30 * THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE, LLC DISCLAIMS ALL
31 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
32 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE, LLC
33 * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
34 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
35 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
36 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
37 * SOFTWARE.
38 *
39 * Rhyolite Software DCC 1.3.103-1.309 $Revision$
40 */
41
42 #ifndef DCC_DEFS_H
43 #define DCC_DEFS_H
44
45 #define DCC_VERSION "1.3.103"
46
47 #include "dcc_config.h"
48
49 /* work on WIN32 and any reasonable UNIX platform */
50 #ifdef UNIX
51 #include <stdarg.h>
52 #include <stdio.h> /* for FreeBSD */
53 #include <stdlib.h>
54 #include <string.h>
55 #include <errno.h>
56 #include <unistd.h>
57 #if TIME_WITH_SYS_TIME
58 # include <sys/time.h>
59 # include <time.h>
60 #else
61 # if HAVE_SYS_TIME_H
62 # include <sys/time.h>
63 # else
64 # include <time.h>
65 # endif
66 #endif
67 #ifdef HAVE_UTIME_H
68 #include <utime.h>
69 #endif
70 #undef EX_OK /* IRIX defines EX_OK in unistd.h */
71 #include <limits.h> /* for FreeBSD */
72 #include <netdb.h>
73 #include <netinet/in.h>
74 #include <sys/param.h> /* for FreeBSD */
75 #include <sys/socket.h>
76 #include <fcntl.h>
77 #include <sys/stat.h>
78 #include <sys/mman.h>
79 #else /* !UNIX or DCC_WIN32 */
80 #define STRICT
81 #define WIN32_LEAN_AND_MEAN
82 #include <stdarg.h>
83 #include <stdio.h>
84 #include <stdlib.h>
85 #include <errno.h>
86 #include <winerror.h>
87 #include <limits.h>
88 #include <winsock2.h>
89 #include <ws2tcpip.h>
90 #include <time.h>
91 #include <sys/types.h>
92 #include <sys/stat.h>
93 #include <fcntl.h>
94 #include <io.h>
95
96 typedef unsigned int u_int32_t;
97 typedef signed int int32_t;
98 typedef unsigned short u_int16_t;
99 #endif /* !UNIX or DCC_WIN32 */
100
101 /* even some UNIX systems have ancient, unusable versions of sysexits.h */
102 #include "sendmail-sysexits.h"
103
104 /* use kludge file if asked */
105 #ifdef NEED_KLUDGE_H
106 #include "kludge.h"
107 #endif
108
109 #ifdef NEED_STRINGS_H
110 #include <strings.h>
111 #endif
112
113 #if !defined(DCC_HAVE_U_INT32_T)
114 #define u_int32_t uint32_t
115 #define u_int16_t uint16_t
116 #endif
117 #if !defined(DCC_HAVE_U_INT64_T)
118 #define u_int64_t uint64_t
119 #endif
120
121 #ifdef HAVE_GCC_ATTRIBUTES
122 #define UATTRIB __attribute__((unused))
123 #define PATTRIB(f,l) __attribute__((format (printf,f,l)))
124 #define NRATTRIB __attribute((__noreturn__))
125 #else
126 #define UATTRIB
127 #define PATTRIB(f,l)
128 #define NRATTRIB
129 #endif
130
131 #ifndef HAVE_GCC_INLINE
132 #define inline
133 #endif
134
135 typedef char DCC_PASSWD[32];
136 #define DCC_PASSWD_PAT "%.32s"
137
138 typedef char DCC_EMSG[120];
139
140 /* deal with ancient UNIX */
141 #ifndef STDIN_FILENO
142 #define STDIN_FILENO 0
143 #endif
144 #ifndef STDOUT_FILENO
145 #define STDOUT_FILENO 1
146 #endif
147 #ifndef STDERR_FILENO
148 #define STDERR_FILENO 2
149 #endif
150
151 #ifdef UNIX
152 #ifndef MAP_FAILED
153 #define MAP_FAILED ((void *)-1)
154 #endif
155 #ifdef HAVE_OLD_MSYNC
156 #define MSYNC(addr,len,flags) msync((void *)(addr),(len))
157 #else
158 #define MSYNC(addr,len,flags) msync((void *)(addr),(len),(flags))
159 #endif
160
161 #ifndef FD_CLOEXEC
162 #define FD_CLOEXEC 1
163 #endif
164
165 #define WIN32_SOC_CAST
166
167 typedef int SOCKET;
168 #define INVALID_SOCKET (-1)
169 #define SOCKET_ERROR (-1)
170 #define WSAAPI
171 #define closesocket close
172 #define ERROR_STR() ERROR_STR1(errno)
173 #define ERROR_STR1(e) strerror(e)
174 /* at least some filters including IPFW say EACCES on hits,
175 * so treat EACCES like Unreachables */
176 #define UNREACHABLE_ERRORS() (errno == ECONNREFUSED \
177 || errno == EHOSTUNREACH \
178 || errno == ENETUNREACH \
179 || errno == EHOSTDOWN \
180 || errno == ENETDOWN \
181 || errno == EACCES)
182 #define DCC_SELECT_NERROR() (errno == EINTR || errno == EAGAIN)
183 /* EWOULDBLOCK and EAGAIN differ on HP-UX */
184 #define DCC_BLOCK_ERROR() (errno == EWOULDBLOCK || errno == EAGAIN)
185
186 /* PATH_MAX is an over generous 1024 on many UNIX varients,
187 * but an incredible, ridiculous waste of 4096 on some Linux flavors.
188 * Each of the hundreds of dccm and dccifd recipient structures contain
189 * 2 paths. Then there are the 8 paths in .dccw files. So this matters . */
190 typedef char DCC_PATH[768];
191
192 #else /* !UNIX or DCC_WIN32 */
193 extern void win32_init(void);
194
195 #undef errno
196 #define errno WSAGetLastError()
197 #define h_errno WSAGetLastError()
198 #define ERROR_STR() ERROR_STR1(errno)
199 #define ERROR_STR1(e) ws_strerror(e)
200 const char *ws_strerror(int);
201 #define UNREACHABLE_ERRORS() ((errno) == WSAECONNREFUSED \
202 || (errno) == WSAEHOSTUNREACH \
203 || (errno) == WSAENETUNREACH \
204 || (errno) == WSAEHOSTDOWN \
205 || (errno) == WSAENETDOWN)
206 #define DCC_SELECT_NERROR() (errno == WSAEINTR)
207 #define DCC_BLOCK_ERROR() (errno == WSAEWOULDBLOCK || errno == WSAEINTR)
208 #define EADDRINUSE WSAEADDRINUSE
209
210 typedef char DCC_PATH[MAX_PATH+1];
211
212 #define MAXHOSTNAMELEN 256
213
214 /* Microsoft sendto(), recvfrom() want char *buffers */
215 #define WIN32_SOC_CAST (char *)
216
217 /* some WIN32 versions lack snprintf() */
218 #define snprintf dcc_snprintf
219 extern int dcc_snprintf(char *, int, const char *, ...);
220 #define vsnprintf dcc_vsnprintf
221 extern int dcc_vsnprintf(char *, int, const char *, va_list);
222
223 extern char *optarg;
224 extern int optind, opterr, optopt;
225 extern int getopt(int, char * const [], const char *);
226
227 #define strcasecmp stricmp
228 #define strncasecmp strnicmp
229 extern int getpid(void);
230 #define usleep(us) Sleep((us+500)/1000)
231
232 #define LOG_ERR 0
233 #define LOG_MAIL 0
234 #define LOG_NOTICE 0
235 #define LOG_PID 0
236 extern void openlog(const char *, int, int);
237 extern void syslog(int, const char *, ...);
238 extern void closelog(void);
239
240 struct timezone {
241 int tz_minuteswest; /* minutes west of Greenwich */
242 int tz_dsttime; /* type of dst correction */
243 };
244 extern int gettimeofday(struct timeval *, struct timezone *);
245
246 #ifndef HAVE_PID_T
247 #undef pid_t
248 #define pid_t int
249 #endif
250
251 /* FlushViewOfFile() on Win98 sometimes returns 0 with GetLastError()==0 */
252 #define MSYNC(addr,len,flags) (FlushViewOfFile(addr,0), 0)
253
254 #define R_OK 04
255 #define W_OK 02
256 #ifndef S_ISDIR
257 #define S_ISDIR(mode) (mode & _S_IFDIR)
258 #endif
259
260 extern u_char win32_lock(HANDLE, DWORD);
261 extern u_char win32_unlock(HANDLE);
262
263 extern void win32_unmap(HANDLE *, void *, const char *);
264 extern void *win32_map(DCC_EMSG, HANDLE *, const char *, int, int);
265 #endif /* !UNIX or DCC_WIN32 */
266
267
268 #ifndef HAVE_DAEMON
269 #define daemon dcc_daemon
270 extern int daemon(int, int);
271 #endif
272 extern void dcc_daemon_restart(const char *, void(*)(void));
273 extern void dcc_daemon_su(const char *);
274 extern void dcc_pidfile(DCC_PATH, const char *);
275
276 /* AIX is missing some prototypes or has them #ifdef'ed with strange switches */
277 #ifdef _AIX41
278 #include <sys/select.h>
279 typedef unsigned long long int uint64_t;
280 typedef unsigned int uint32_t;
281 typedef int int32_t;
282 typedef unsigned short uint16_t;
283
284 extern void openlog(const char *, int, int);
285 extern int snprintf(char *, int, const char *, ...);
286 extern int vsnprintf(char *, int, const char *, const char *, ...);
287 extern int seteuid(uid_t);
288 extern int flock(int, int);
289 #define AF_LOCAL AF_UNIX
290 #endif /* _AIX41 */
291
292 #ifdef __hpux
293 #define seteuid(euid) setresuid(-1,euid,-1)
294 #define setegid(egid) setresgid(-1,egid,-1)
295 #endif /* __hpux */
296
297
298 #define DCC_MAXDOMAINLEN 256 /* limit host names; with \0 */
299
300 /* 4.4BSD sockets */
301 #ifdef HAVE_SA_LEN
302 #define DCC_SU_LEN(s) ((s)->sa.sa_len)
303 #else
304 #define DCC_SU_LEN(s) (((s)->sa.sa_family == AF_INET) \
305 ? sizeof((s)->ipv4) : sizeof((s)->ipv6))
306 #endif
307 #ifdef HAVE_SOCKLEN_T
308 /* use #define to avoid problems with SOCKS prototypes */
309 #define DCC_SOCKLEN_T socklen_t
310 #else
311 #define DCC_SOCKLEN_T int
312 #endif
313 #if !defined(HAVE_AF_LOCAL) && !defined(AF_LOCAL)
314 #define AF_LOCAL AF_UNIX
315 #endif
316
317 /* these are needed even when IPV6 is available to handle old map file
318 * formats in dcc_clnt.h */
319 struct dcc_in6_addr {
320 u_int32_t dcc_s6_addr32[4];
321 };
322 struct dcc_sockaddr_in6 {
323 u_char sin6_len;
324 u_char sin6_family;
325 u_int16_t sin6_port;
326 u_int32_t sin6_flowinfo;
327 struct dcc_in6_addr sin6_addr;
328 };
329 /* define in6_addr here after u_int32_t has been seen in sys/types.h */
330 #ifdef NO_IPV6
331 #undef in6_addr
332 #define in6_addr dcc_in6_addr /* defend against lurking definitions */
333 #undef s6_addr32
334 #define s6_addr32 dcc_s6_addr32
335 #define sockaddr_in6 dcc_sockaddr_in6 /* defend against lurking definitions */
336 #endif /* NO_IPV6 */
337
338
339 #include "dcc_proto.h"
340
341
342 /* see if an address is in an IPv6 CIDR block */
343 #define DCC_IN_BLOCK(a,b,m) ((((a).s6_addr32[3] & (m).s6_addr32[3]) \
344 == (b).s6_addr32[3]) \
345 && (((a).s6_addr32[2] & (m).s6_addr32[2]) \
346 == (b).s6_addr32[2]) \
347 && (((a).s6_addr32[1] & (m).s6_addr32[1]) \
348 == (b).s6_addr32[1]) \
349 && (((a).s6_addr32[0] & (m).s6_addr32[0]) \
350 == (b).s6_addr32[0]))
351
352
353 /* puzzle out something for s6_addr32 */
354 #if !defined(s6_addr32) && defined(CONF_S6_ADDR32)
355 #define s6_addr32 CONF_S6_ADDR32
356 #endif
357
358 #ifdef NO_AF_INET6
359 #define AF_INET6 24
360 #endif
361
362 #ifndef INET6_ADDRSTRLEN
363 #define INET6_ADDRSTRLEN 46
364 #endif
365 #ifndef INET_ADDRSTRLEN
366 #define INET_ADDRSTRLEN 16
367 #endif
368
369 #define MAXPORTNAMELEN 64
370
371 #ifndef INADDR_NONE
372 #define INADDR_NONE 0xffffffff
373 #endif
374
375 #define DCC_SU_EQ(a,b) ((a)->sa.sa_family == (b)->sa.sa_family \
376 && (((a)->sa.sa_family == AF_INET) \
377 ? ((a)->ipv4.sin_addr.s_addr \
378 == (b)->ipv4.sin_addr.s_addr) \
379 : !memcmp(&(a)->ipv6.sin6_addr, \
380 &(b)->ipv6.sin6_addr, \
381 sizeof((a)->ipv6.sin6_addr))))
382
383 /* zero port number if sa_family is AF_UNSPEC */
384 #define DCC_SU_PORT(su) ((su)->sa.sa_family == AF_INET \
385 ? (su)->ipv4.sin_port \
386 : (su)->sa.sa_family == AF_INET6 \
387 ? (su)->ipv6.sin6_port \
388 : 0)
389
390 /* use IPv4 port number if sa_family is AF_UNSPEC */
391 #define DCC_SU_PORTP(su) ((su)->sa.sa_family == AF_INET6 \
392 ? &(su)->ipv6.sin6_port \
393 : &(su)->ipv4.sin_port)
394
395 #define DCC_IN6_ADDR_V4MAPPED(ap) ((ap)->s6_addr32[0] == 0 \
396 && (ap)->s6_addr32[1] == 0 \
397 && (ap)->s6_addr32[2] == ntohl(0x0000ffff))
398
399 #define DCC_IN6_ADDR_V4COMPAT(ap) ((ap)->s6_addr32[0] == 0 \
400 && (ap)->s6_addr32[1] == 0 \
401 && (ap)->s6_addr32[2] == 0 \
402 && (ap)->s6_addr32[3] == 0 \
403 && (ap)->s6_addr32[3] == ntohl(1))
404
405
406
407 /* printf patterns for 64-bit values */
408 #ifdef HAVE_64BIT_LONG
409 #define LL_PAT "l"
410 #else
411 #define LL_PAT "ll"
412 #endif
413 #define L_HPAT "%#"LL_PAT"x"
414 #define L_HWPAT(w) "%#"#w LL_PAT"x" /* hex with specified width */
415 #define L_DPAT "%"LL_PAT"d"
416 #define L_DWPAT(w) "%"#w LL_PAT"d" /* decimal with specified width */
417
418 /* printf pattern for size_t and off_t */
419 #ifdef HAVE_BIG_FILES
420 #define OFF_HPAT L_HPAT
421 #define OFF_DPAT L_DPAT
422 #else
423 #define OFF_HPAT "%#lx"
424 #define OFF_DPAT "%ld"
425 #endif
426
427 #define DIM(_a) ((int)(sizeof(_a) / sizeof((_a)[0])))
428 #define LAST(_a) (&(_a)[DIM(_a)-1])
429 /* abbreviation to silence common compiler warnings */
430 #define ISZ(_s) ((int)sizeof(_s))
431
432 #ifdef HAVE_STRLCPY
433 #define STRLCPY(d,s,lim) strlcpy(d,s,lim)
434 #else
435 #define STRLCPY(d,s,lim) ((lim)<=0 ? d \
436 : ((d)[(lim)-1] = '\0', strncpy(d,s,(lim)-1)))
437 #endif
438 #define BUFCPY(d,s) STRLCPY(d,s,sizeof(d))
439 #ifdef HAVE_STRLCAT
440 #define STRLCAT(d,s,lim) strlcat(d,s,lim)
441 #else
442 #define STRLCAT(d,s,lim) dcc_strlcat(d,s,lim)
443 extern int dcc_strlcat(char *, const char *, int);
444 #endif
445
446 #define LITZ(_s) ((int)sizeof(_s)-1)
447 #define CLITCMP(b,_s) strncasecmp(b, _s, LITZ(_s))
448 #define LITCMP(b,_s) strncmp(b, _s, LITZ(_s))
449
450
451 #ifndef HAVE___PROGNAME
452 #define __progname dcc_progname
453 #endif
454
455 #undef max
456 #define max(a,b) ((a) > (b) ? (a) : (b))
457 #undef min
458 #define min(a,b) ((a) < (b) ? (a) : (b))
459
460 /* Is it time or has the local clock been changed?
461 * Is the clock after the target date or earlier than the original date? */
462 #define DCC_IS_TIME(now,tgt,lim) ((now) >= (tgt) || (now)+(lim) < (tgt))
463
464 #define DCC_ADJ_TIMER(now,tgt,lim,new_lim) { \
465 if (*(tgt) > (now)+(new_lim)) \
466 *(tgt) = (now)+(new_lim); \
467 *(lim) = (new_lim); \
468 }
469
470 #define FOREVER_SECS 1000
471 #define FOREVER_US (FOREVER_SECS*DCC_US)
472 #define us2tv(tvp,us) ((tvp)->tv_sec = (us) / DCC_US, \
473 (tvp)->tv_usec = (us) % DCC_US)
474 extern time_t tv_diff2us(const struct timeval *, const struct timeval *);
475 extern void tv_add(struct timeval *,
476 const struct timeval *, const struct timeval *);
477 extern void tv_add_us(struct timeval *, time_t);
478
479 /* prefer gmtime_r even where we don't really care */
480 #ifdef HAVE_GMTIME_R
481 #define DCC_GMTIME_R(src,tgt) gmtime_r(src,tgt)
482 #else
483 #define DCC_GMTIME_R(src,tgt) memcpy(tgt,gmtime(src),sizeof(struct tm))
484 #endif
485
486 #define DCC_WHITESPACE " \t\n\r"
487
488 /* ctype() is now a slow mess that does not give constant results on all
489 * systems */
490 #define DCC_IS_WHITE(c) ((c) == ' ' || (c) == '\t' || (c) == '\r' || (c)== '\n')
491 #define DCC_IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
492 #define DCC_IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
493 #define DCC_TO_LOWER(c) (DCC_IS_UPPER(c) ? ((c) + ('a'-'A')) : (c))
494 #define DCC_TO_UPPER(c) (DCC_IS_LOWER(c) ? ((c) - ('a'-'A')) : (c))
495
496 typedef union {
497 struct sockaddr sa;
498 struct sockaddr_in ipv4;
499 struct sockaddr_in6 ipv6;
500 } DCC_SOCKU;
501
502 /* we cannot always use DCC_SOCKU because sizeof(sockaddr_in6) is not defined
503 * on systems without IPv6 and when they do get IPv6, the native sockaddr_in
504 * often differs in size from the work-around version in the DCC source */
505 typedef struct {
506 union {
507 struct in_addr v4;
508 struct in6_addr v6;
509 } u;
510 u_int16_t port;
511 u_char family;
512 } DCC_IP;
513
514 #ifdef HAVE_RSENDTO
515 extern int Rconnect(int, const struct sockaddr *, DCC_SOCKLEN_T);
516 extern ssize_t Rsend(int, const void *, size_t, int);
517 extern ssize_t Rsendto(int, const void *, size_t, int,
518 const struct sockaddr *, size_t);
519 extern ssize_t Rrecv(int, void *, size_t, int);
520 extern ssize_t Rrecvfrom(int, void *, size_t, int,
521 struct sockaddr *, DCC_SOCKLEN_T *);
522 extern struct hostent *Rgethostbyname(const char *);
523 #else
524 #define Rconnect connect
525 #define Rsend send
526 #define Rsendto sendto
527 #define Rrecv recv
528 #define Rrecvfrom recvfrom
529 #define Rgethostbyname gethostbyname
530 #endif
531
532 /* use very old fashioned gethostbyname() if we are not doing any IPv6 */
533 #ifdef NO_IPV6
534 #undef HAVE_GETIPNODEBYNAME
535 #undef HAVE_GETADDRINFO
536 #endif
537
538 #if !defined(HAVE_GETIPNODEBYNAME) || !defined(HAVE_FREEHOSTENT) || !defined(HAVE_GETIPNODEBYADDR)
539 #undef HAVE_GETIPNODEBYNAME
540 #endif
541
542 #if !defined(HAVE_GETADDRINFO) || !defined(HAVE_FREEADDRINFO) || !defined(HAVE_GAI_STRERROR) || !defined(HAVE_GETNAMEINFO)
543 #undef HAVE_GETADDRINFO
544 #endif
545
546 /* prefer getaddrinfo() for IPv6 resolution */
547 #if defined(HAVE_GETADDRINFO)
548 #define USE_GETADDRINFO
549 #undef HAVE_GETIPNODEBYNAME
550 #endif
551 #ifdef HAVE_GETIPNODEBYNAME
552 #define USE_GETIPNODEBYNAME
553 #undef HAVE_GETADDRINFO
554 #endif
555
556 #undef DCC_HSTRERROR
557 #ifdef UNIX
558 #ifdef USE_GETADDRINFO
559 #define DCC_HSTRERROR(e) gai_strerror(e)
560 #endif
561 #if !defined(DCC_HSTRERROR) && defined(HAVE_HSTRERROR)
562 #define DCC_HSTRERROR(e) hstrerror(e)
563 #endif
564 #ifndef DCC_HSTRERROR
565 #define DCC_HSTRERROR(e) dcc_hstrerror(e)
566 #endif
567 #else /* !UNIX or DCC_WIN32 */
568 #define DCC_HSTRERROR(e) ws_strerror(e)
569 #endif /* !UNIX or DCC_WIN32 */
570
571
572 #ifndef HAVE_POLL
573 #undef USE_POLL
574 #endif
575
576 #define LOGBUF_SIZE (DCC_MAXDOMAINLEN*2)
577
578 extern int dcc_ex_code; /* not thread safe */
579 extern void dcc_pemsg(int, DCC_EMSG, const char *, ...) PATTRIB(3,4);
580 extern void dcc_vpemsg(int, DCC_EMSG, const char *, va_list);
581 #define DCC_FNM_LNO_PAT " in line %d of %s"
582 typedef struct {
583 char b[sizeof(DCC_PATH)+sizeof(DCC_FNM_LNO_PAT)+8];
584 } DCC_FNM_LNO_BUF;
585 extern const char *fnm_lno(DCC_FNM_LNO_BUF *, const char *, int);
586
587
588 #define DCC_MAX_HDR_LINE 78 /* by RFC 2822 */
589 #define DCC_MAX_XHDR_LEN 240 /* largest possible X-DCC header */
590 typedef struct {
591 u_int start_len; /* length of start up to ':' */
592 u_int used; /* bytes of buffer used */
593 int col; /* current column */
594 char buf[DCC_MAX_XHDR_LEN];
595 } DCC_HEADER_BUF;
596
597 #define DCC_MAP_NM_DEF "map"
598
599
600 #ifndef HAVE_PTHREADS
601 #undef HAVE_HELPERS
602 #else
603 #define HAVE_HELPERS 1
604 #endif
605
606
607 typedef void(*LOG_WRITE_FNC)(void *context, const char *buf, u_int buflen);
608
609 extern void dcc_sign(const char *, int, void *, u_int);
610 extern u_char dcc_ck_signature(const char *, int, const void *, u_int);
611
612 extern DCC_PATH dcc_homedir;
613 extern u_char fnm2rel(DCC_PATH, const char *, const char *);
614 extern void fnm2rel_good(DCC_PATH, const char *, const char *);
615 extern u_char fnm2abs(DCC_PATH, const char *, const char *);
616 extern const char *fnm2abs_err(DCC_PATH, const char *);
617 extern const char *path2fnm(const char *);
618 extern u_char dcc_cdhome(DCC_EMSG, const char *, u_char);
619
620 extern uid_t dcc_real_uid, dcc_effective_uid;
621 extern gid_t dcc_real_gid, dcc_effective_gid;
622 extern void dcc_get_priv(void);
623 extern u_char dcc_get_priv_home(const char *);
624 extern void dcc_rel_priv(void);
625 extern void dcc_init_priv(void);
626 extern u_char dcc_ck_private(DCC_EMSG, struct stat *, const char *, int);
627 extern int dcc_lock_open(DCC_EMSG, const char *, int, u_char, int, u_char *);
628 # define DCC_LOCK_OPEN_NOWAIT 0x1 /* don't wait to get lock */
629 # define DCC_LOCK_OPEN_NOLOCK 0x2 /* already locked */
630 # define DCC_LOCK_OPEN_SHARE 0x4
631 #define DCC_LOCK_ALL_FILE (-1)
632 extern u_char dcc_unlock_fd(DCC_EMSG, int, int, const char *, const char *);
633 extern u_char dcc_exlock_fd(DCC_EMSG, int, int, int,
634 const char *, const char *);
635 extern u_char dcc_set_mtime(DCC_EMSG, const char *, int,
636 const struct timeval *);
637
638 extern DCC_PATH dcc_main_logdir;
639 extern void tmp_path_init(const char *, const char *);
640 #define DCC_TMP_LOG_PREFIX "/tmp." /* must be the same length */
641 #define DCC_FIN_LOG_PREFIX "/msg."
642 #define DCC_MKSTEMP_LEN 6 /* characters added by dcc_mkstemp() */
643 #define DCC_MKSTEMP_LEN_STR "6"
644 extern int dcc_mkstemp(DCC_EMSG, char *, int, char *, int,
645 const char *, const char *, const char *, u_char, int);
646 extern u_char dcc_main_logdir_init(DCC_EMSG, const char *);
647 typedef enum { /* type of log subdirector */
648 LOG_MODE_FLAT, /* logdir/ */
649 LOG_MODE_DAY, /* logdir/ddd/ */
650 LOG_MODE_HOUR, /* logdir/ddd/hh/ */
651 LOG_MODE_MINUTE /* logdir/ddd/hh/mm/ */
652 } LOG_MODE;
653 extern int dcc_log_open(DCC_EMSG, DCC_PATH, char *, int,
654 const char *, const char *, const char *, LOG_MODE);
655 extern int dcc_main_log_open(DCC_EMSG, DCC_PATH log_path, char *, int);
656 extern u_char dcc_log_keep(DCC_EMSG, char *);
657 extern u_char dcc_log_close(DCC_EMSG, const char *, int,
658 const struct timeval *);
659 #define DCC_LOG_DATE_PAT "VERSION: 3\nDATE: %s"
660 #define DCC_LOG_DATE_FMT "%x %X %Z"
661 #define DCC_LOG_MSG_SEP "\n### end of message body ########################\n"
662 #define DCC_LOG_TRN_MSG0 "### log truncated ######################"
663 #define DCC_LOG_TRN_MSG "\n"DCC_LOG_TRN_MSG0"\n"
664 #define DCC_LOG_TRN_MSG_CR "\r\n"DCC_LOG_TRN_MSG0"\r\n"
665 typedef struct {
666 int len;
667 char buf[500];
668 } EARLY_LOG;
669 extern int dcc_vearly_log(EARLY_LOG *, const char *, va_list);
670 extern const char *optopt2str(int);
671
672
673 #define DCC_US (1000*1000)
674
675 extern const struct tm *dcc_localtime(time_t, struct tm *);
676 #ifndef HAVE_LOCALTIME_R
677 extern void dcc_localtime_lock(void);
678 extern void dcc_localtime_unlock(void);
679 #endif
680 const char *dcc_time2str(char *, size_t, const char *, time_t);
681 #ifdef HAVE_TIMEGM
682 #define DCC_TIMEGM(tm) timegm(tm)
683 #else
684 #ifdef HAVE_ALTZONE
685 #define DCC_TIMEGM(tm) ((tm)->tm_isdst=-1, mktime(tm) - altzone)
686 #else
687 #define DCC_TIMEGM(tm) ((tm)->tm_isdst=-1, mktime(tm))
688 #endif
689 #endif
690
691 extern int dcc_get_secs(const char *, const char **, int, int, int);
692 #define DCC_MAX_SECS 0x7fffffff
693 extern u_int dcc_get_port(DCC_EMSG, const char *, u_int, const char *, int);
694 #define DCC_GET_PORT_INVALID 0x10000
695 extern u_char dcc_host_locked;
696 #define MAX_DCC_HOSTADDRS 20
697 extern DCC_SOCKU dcc_hostaddrs[MAX_DCC_HOSTADDRS];
698 extern char dcc_host_canonname[DCC_MAXDOMAINLEN];
699 extern DCC_SOCKU *dcc_hostaddrs_end;
700 extern void dcc_host_lock(void);
701 extern void dcc_host_unlock(void);
702 extern u_char dcc_get_host(const char *, u_char, int *);
703 extern u_char dcc_get_host_SOCKS(const char *, u_char, int *);
704 extern const char *dcc_hstrerror(int);
705 extern DCC_SOCKU *dcc_mk_su(DCC_SOCKU *, int, const void *, u_short);
706 extern u_char dcc_str2ip(DCC_SOCKU *, const char *);
707 extern void dcc_bits2mask(struct in6_addr *, int);
708 extern int dcc_str2cidr(DCC_EMSG, struct in6_addr *, struct in6_addr *,
709 u_char *, const char *, const char *, int);
710 extern int dcc_udp_bind(DCC_EMSG, SOCKET *, const DCC_SOCKU *, int *);
711 extern DCC_CLNT_ID dcc_get_id(DCC_EMSG, const char *, const char *, int);
712 extern const char *dcc_get_srvr_id(DCC_EMSG, DCC_SRVR_ID *,
713 const char *, const char *,
714 const char *, int);
715 extern const char *dcc_parse_word(DCC_EMSG, char *, int,
716 const char *, const char *,
717 const char *, int);
718 extern const char *parse_passwd(DCC_EMSG, DCC_PASSWD, const char *,
719 const char *, const char *, int);
720 extern u_char dcc_ck_word_comma(const char **, const char *);
721
722 extern void dcc_ipv4toipv6(struct in6_addr *, const struct in_addr);
723 extern u_char dcc_ipv6toipv4(struct in_addr *, const struct in6_addr *);
724 extern void dcc_su2ip(DCC_IP *, const DCC_SOCKU *);
725 extern u_char dcc_ipv6sutoipv4(DCC_SOCKU *, const DCC_SOCKU *);
726 extern u_char dcc_ipv4sutoipv6(DCC_SOCKU *, const DCC_SOCKU *);
727
728 const char *dcc_trim_ffff(const char *);
729 #define DCC_SU2STR_SIZE (INET6_ADDRSTRLEN+1+6+1)
730 extern const char *dcc_ipv4tostr(char *, int, const struct in_addr *);
731 extern const char *dcc_ipv6tostr(char *, int, const struct in6_addr *);
732 extern const char *dcc_ipv6tostr2(char *, int, const struct in6_addr *);
733 const char *dcc_ip2str(char *, int, const DCC_IP *);
734 extern const char *dcc_su2str(char *, int, const DCC_SOCKU *);
735 extern const char *dcc_su2str2(char *, int, const DCC_SOCKU *);
736 extern const char *dcc_su2str3(char *, int, const DCC_SOCKU *, u_short);
737 extern const char *dcc_su2str_err(const DCC_SOCKU *);
738 extern const char * dcc_host_portname(char *, int, const char *, const char *);
739 extern const char *dcc_su2name(char *, int, const DCC_SOCKU *);
740
741 extern void clean_stdio(void);
742 extern u_char dcc_no_syslog;
743 extern int dcc_error_priority, dcc_trace_priority;
744 extern u_char dcc_parse_log_opt(const char *);
745 extern void dcc_syslog_init(u_char, const char *, const char *);
746 extern DCC_PATH dcc_progname;
747 extern int dcc_progname_len;
748 extern void dcc_vfatal_msg(const char *, va_list);
749 extern int dcc_verror_msg(const char *, va_list);
750 extern void dcc_error_msg(const char *, ...) PATTRIB(1,2);
751 extern void dcc_vtrace_msg(const char *, va_list);
752 extern void dcc_trace_msg(const char *, ...) PATTRIB(1,2);
753 extern u_char trace_quiet;
754 extern void quiet_trace_msg(const char *p, ...) PATTRIB(1,2);
755 #ifndef HAVE_VSYSLOG
756 #define vsyslog dcc_vsyslog
757 extern void vsyslog(int, const char *, va_list);
758 #endif
759
760 extern void NRATTRIB dcc_logbad(int, const char *, ...) PATTRIB(2,3);
761 #define DCC_ASSERT(c) ((c) ? 0 : dcc_logbad(EX_SOFTWARE, #c))
762
763 extern const char *id2str(char *, u_int, DCC_CLNT_ID);
764 extern char *dcc_ck2str(char *, u_int, DCC_CK_TYPES, const DCC_SUM, u_int32_t);
765 #define DCC_CK2STR_LEN (sizeof(DCC_SUM)*2+sizeof(DCC_SUM)/4+1)
766 extern const char *dcc_ck2str_err(DCC_CK_TYPES, const DCC_SUM, u_int32_t);
767 extern char *dcc_tgts2str(char *, u_int, DCC_TGTS, u_char);
768 extern char *dcc_thold2str(char *, u_int, DCC_CK_TYPES, DCC_TGTS);
769 extern char *dcc_type2str(char *, u_int, DCC_CK_TYPES,
770 const char *, u_char, u_char);
771 extern const char *dcc_type2str_err(DCC_CK_TYPES,
772 const char *, u_char, u_char);
773 #define SET_ALL_THOLDS (DCC_CK_TYPE_LAST+1)
774 #define SET_CMN_THOLDS (SET_ALL_THOLDS+1)
775 extern DCC_CK_TYPES dcc_str2type_del(const char *, int);
776 extern DCC_CK_TYPES dcc_str2type_db(const char *, int);
777 extern DCC_CK_TYPES dcc_str2type_thold(const char *, int);
778 extern DCC_CK_TYPES dcc_str2type_wf(const char *, int);
779 extern DCC_TGTS dcc_str2cnt(const char *);
780
781 extern const char *dcc_aop2str(char *, int, DCC_AOPS, u_int32_t);
782 extern const char *dcc_hdr_op2str(char *, int, const DCC_HDR *);
783 #define DCC_OPBUF 32
784
785
786 #endif /* DCC_DEFS_H */