diff -BbrurN sendmail-8.12.7/cf/domain/cdb.m4 sendmail-8.12.7-cdb-testbuild/cf/domain/cdb.m4 --- sendmail-8.12.7/cf/domain/cdb.m4 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/cf/domain/cdb.m4 2003-01-29 01:41:23.000000000 +0800 @@ -0,0 +1,26 @@ +divert(-1) +# +# Copyright (c) 1998, 1999 Sendmail, Inc. and its suppliers. +# All rights reserved. +# Copyright (c) 1983 Eric P. Allman. All rights reserved. +# Copyright (c) 1988, 1993 +# The Regents of the University of California. All rights reserved. +# +# By using this file, you agree to the terms and conditions set +# forth in the LICENSE file which can be found at the top level of +# the sendmail distribution. +# +# + +# +# The following is a generic domain file. You should be able to +# use it anywhere. If you want to customize it, copy it to a file +# named with your domain and make the edits; then, copy the appropriate +# .mc files and change `DOMAIN(generic)' to reference your updated domain +# files. +# +divert(0) +VERSIONID(`$Id: generic.m4,v 8.15 1999/04/04 00:51:09 ca Exp $') +FEATURE(`mailertable')dnl +FEATURE(`access_db')dnl +FEATURE(`use_cw_file')dnl diff -BbrurN sendmail-8.12.7/devtools/Site/site.config.m4 sendmail-8.12.7-cdb-testbuild/devtools/Site/site.config.m4 --- sendmail-8.12.7/devtools/Site/site.config.m4 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/devtools/Site/site.config.m4 2003-01-30 12:22:13.000000000 +0800 @@ -0,0 +1,3 @@ +define(`confMAPDEF', `-DCDB') +APPENDDEF(`confSMOBJADD', `alloc.o alloc_re.o buffer_2.o byte_copy.o seek_cur.o buffer.o byte_cr.o cdb_hash.o error.o seek_set.o buffer_0.o buffer_copy.o byte_diff.o cdb_make.o error_str.o open_read.o strerr_die.o buffer_1.o buffer_get.o cdb.o fmt_ulong.o open_trunc.o strerr_sys.o uint32_pack.o buffer_1s.o buffer_put.o scan_ulong.o str_len.o uint32_unpack.o stralloc_arts.o stralloc_cat.o stralloc_copy.o stralloc_opyb.o stralloc_pend.o stralloc_catb.o stralloc_cats.o stralloc_eady.o stralloc_opys.o') +APPENDDEF(`confSMSRCADD', `alloc.c alloc_re.c buffer_2.c byte_copy.c seek_cur.c buffer.c byte_cr.c cdb_hash.c error.c seek_set.c buffer_0.c buffer_copy.c byte_diff.c cdb_make.c error_str.c open_read.c strerr_die.c buffer_1.c buffer_get.c cdb.c fmt_ulong.c open_trunc.c strerr_sys.c uint32_pack.c buffer_1s.c buffer_put.c scan_ulong.c str_len.c uint32_unpack.c stralloc_arts.c stralloc_cat.c stralloc_copy.c stralloc_opyb.c stralloc_pend.c stralloc_catb.c stralloc_cats.c stralloc_eady.c stralloc_opys.c') diff -BbrurN sendmail-8.12.7/libsmdb/alloc.c sendmail-8.12.7-cdb-testbuild/libsmdb/alloc.c --- sendmail-8.12.7/libsmdb/alloc.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/alloc.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,32 @@ +#include "alloc.h" +#include "error.h" +extern char *malloc(); +extern void free(); + +#define ALIGNMENT 16 /* XXX: assuming that this alignment is enough */ +#define SPACE 4096 /* must be multiple of ALIGNMENT */ + +typedef union { char irrelevant[ALIGNMENT]; double d; } aligned; +static aligned realspace[SPACE / ALIGNMENT]; +#define space ((char *) realspace) +static unsigned int avail = SPACE; /* multiple of ALIGNMENT; 0<=avail<=SPACE */ + +/*@null@*//*@out@*/char *alloc(n) +unsigned int n; +{ + char *x; + n = ALIGNMENT + n - (n & (ALIGNMENT - 1)); /* XXX: could overflow */ + if (n <= avail) { avail -= n; return space + avail; } + x = malloc(n); + if (!x) errno = error_nomem; + return x; +} + +void alloc_free(x) +char *x; +{ + if (x >= space) + if (x < space + SPACE) + return; /* XXX: assuming that pointers are flat */ + free(x); +} diff -BbrurN sendmail-8.12.7/libsmdb/alloc.h sendmail-8.12.7-cdb-testbuild/libsmdb/alloc.h --- sendmail-8.12.7/libsmdb/alloc.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/alloc.h 2003-01-29 01:23:51.000000000 +0800 @@ -0,0 +1,8 @@ +#ifndef ALLOC_H +#define ALLOC_H + +extern /*@null@*//*@out@*/char *alloc(); +extern void alloc_free(); +extern int alloc_re(); + +#endif diff -BbrurN sendmail-8.12.7/libsmdb/auto_home.c sendmail-8.12.7-cdb-testbuild/libsmdb/auto_home.c --- sendmail-8.12.7/libsmdb/auto_home.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/auto_home.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,3 @@ +char auto_home[] = "\ +\057\165\163\162\057\154\157\143\141\154\ +"; diff -BbrurN sendmail-8.12.7/libsmdb/auto_home.h sendmail-8.12.7-cdb-testbuild/libsmdb/auto_home.h --- sendmail-8.12.7/libsmdb/auto_home.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/auto_home.h 2003-01-29 01:23:51.000000000 +0800 @@ -0,0 +1,6 @@ +#ifndef AUTO_HOME_H +#define AUTO_HOME_H + +extern char auto_home[]; + +#endif diff -BbrurN sendmail-8.12.7/libsmdb/auto-str.c sendmail-8.12.7-cdb-testbuild/libsmdb/auto-str.c --- sendmail-8.12.7/libsmdb/auto-str.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/auto-str.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,44 @@ +#include "buffer.h" +#include "readwrite.h" +#include "exit.h" + +char buf1[256]; +buffer ss1 = BUFFER_INIT(write,1,buf1,sizeof(buf1)); + +void puts(s) +char *s; +{ + if (buffer_puts(&ss1,s) == -1) _exit(111); +} + +main(argc,argv) +int argc; +char **argv; +{ + char *name; + char *value; + unsigned char ch; + char octal[4]; + + name = argv[1]; + if (!name) _exit(100); + value = argv[2]; + if (!value) _exit(100); + + puts("char "); + puts(name); + puts("[] = \"\\\n"); + + while (ch = *value++) { + puts("\\"); + octal[3] = 0; + octal[2] = '0' + (ch & 7); ch >>= 3; + octal[1] = '0' + (ch & 7); ch >>= 3; + octal[0] = '0' + (ch & 7); + puts(octal); + } + + puts("\\\n\";\n"); + if (buffer_flush(&ss1) == -1) _exit(111); + _exit(0); +} diff -BbrurN sendmail-8.12.7/libsmdb/buffer_0.c sendmail-8.12.7-cdb-testbuild/libsmdb/buffer_0.c --- sendmail-8.12.7/libsmdb/buffer_0.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/buffer_0.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,12 @@ +#include "readwrite.h" +#include "buffer.h" + +int buffer_0_read(fd,buf,len) int fd; char *buf; int len; +{ + if (buffer_flush(buffer_1) == -1) return -1; + return read(fd,buf,len); +} + +char buffer_0_space[BUFFER_INSIZE]; +static buffer it = BUFFER_INIT(buffer_0_read,0,buffer_0_space,sizeof buffer_0_space); +buffer *buffer_0 = ⁢ diff -BbrurN sendmail-8.12.7/libsmdb/buffer_1.c sendmail-8.12.7-cdb-testbuild/libsmdb/buffer_1.c --- sendmail-8.12.7/libsmdb/buffer_1.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/buffer_1.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,6 @@ +#include "readwrite.h" +#include "buffer.h" + +char buffer_1_space[BUFFER_OUTSIZE]; +static buffer it = BUFFER_INIT(write,1,buffer_1_space,sizeof buffer_1_space); +buffer *buffer_1 = ⁢ diff -BbrurN sendmail-8.12.7/libsmdb/buffer_1s.c sendmail-8.12.7-cdb-testbuild/libsmdb/buffer_1s.c --- sendmail-8.12.7/libsmdb/buffer_1s.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/buffer_1s.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,6 @@ +#include "readwrite.h" +#include "buffer.h" + +char buffer_1small_space[256]; +static buffer it = BUFFER_INIT(write,1,buffer_1small_space,sizeof buffer_1small_space); +buffer *buffer_1small = ⁢ diff -BbrurN sendmail-8.12.7/libsmdb/buffer_2.c sendmail-8.12.7-cdb-testbuild/libsmdb/buffer_2.c --- sendmail-8.12.7/libsmdb/buffer_2.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/buffer_2.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,6 @@ +#include "readwrite.h" +#include "buffer.h" + +char buffer_2_space[256]; +static buffer it = BUFFER_INIT(write,2,buffer_2_space,sizeof buffer_2_space); +buffer *buffer_2 = ⁢ diff -BbrurN sendmail-8.12.7/libsmdb/buffer.c sendmail-8.12.7-cdb-testbuild/libsmdb/buffer.c --- sendmail-8.12.7/libsmdb/buffer.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/buffer.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,10 @@ +#include "buffer.h" + +void buffer_init(buffer *s,int (*op)(),int fd,char *buf,unsigned int len) +{ + s->x = buf; + s->fd = fd; + s->op = op; + s->p = 0; + s->n = len; +} diff -BbrurN sendmail-8.12.7/libsmdb/buffer_copy.c sendmail-8.12.7-cdb-testbuild/libsmdb/buffer_copy.c --- sendmail-8.12.7/libsmdb/buffer_copy.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/buffer_copy.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,16 @@ +#include "buffer.h" + +int buffer_copy(buffer *bout,buffer *bin) +{ + int n; + char *x; + + for (;;) { + n = buffer_feed(bin); + if (n < 0) return -2; + if (!n) return 0; + x = buffer_PEEK(bin); + if (buffer_put(bout,x,n) == -1) return -3; + buffer_SEEK(bin,n); + } +} diff -BbrurN sendmail-8.12.7/libsmdb/buffer_get.c sendmail-8.12.7-cdb-testbuild/libsmdb/buffer_get.c --- sendmail-8.12.7/libsmdb/buffer_get.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/buffer_get.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,67 @@ +#include "buffer.h" +#include "byte.h" +#include "error.h" + +static int oneread(int (*op)(),int fd,char *buf,unsigned int len) +{ + int r; + + for (;;) { + r = op(fd,buf,len); + if (r == -1) if (errno == error_intr) continue; + return r; + } +} + +static int getthis(buffer *s,char *buf,unsigned int len) +{ + if (len > s->p) len = s->p; + s->p -= len; + byte_copy(buf,len,s->x + s->n); + s->n += len; + return len; +} + +int buffer_feed(buffer *s) +{ + int r; + + if (s->p) return s->p; + r = oneread(s->op,s->fd,s->x,s->n); + if (r <= 0) return r; + s->p = r; + s->n -= r; + if (s->n > 0) byte_copyr(s->x + s->n,r,s->x); + return r; +} + +int buffer_bget(buffer *s,char *buf,unsigned int len) +{ + int r; + + if (s->p > 0) return getthis(s,buf,len); + if (s->n <= len) return oneread(s->op,s->fd,buf,s->n); + r = buffer_feed(s); if (r <= 0) return r; + return getthis(s,buf,len); +} + +int buffer_get(buffer *s,char *buf,unsigned int len) +{ + int r; + + if (s->p > 0) return getthis(s,buf,len); + if (s->n <= len) return oneread(s->op,s->fd,buf,len); + r = buffer_feed(s); if (r <= 0) return r; + return getthis(s,buf,len); +} + +char *buffer_peek(buffer *s) +{ + return s->x + s->n; +} + +void buffer_seek(buffer *s,unsigned int len) +{ + s->n += len; + s->p -= len; +} diff -BbrurN sendmail-8.12.7/libsmdb/buffer.h sendmail-8.12.7-cdb-testbuild/libsmdb/buffer.h --- sendmail-8.12.7/libsmdb/buffer.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/buffer.h 2003-01-29 01:23:51.000000000 +0800 @@ -0,0 +1,56 @@ +#ifndef BUFFER_H +#define BUFFER_H + +typedef struct buffer { + char *x; + unsigned int p; + unsigned int n; + int fd; + int (*op)(); +} buffer; + +#define BUFFER_INIT(op,fd,buf,len) { (buf), 0, (len), (fd), (op) } +#define BUFFER_INSIZE 8192 +#define BUFFER_OUTSIZE 8192 + +extern void buffer_init(buffer *,int (*)(),int,char *,unsigned int); + +extern int buffer_flush(buffer *); +extern int buffer_put(buffer *,char *,unsigned int); +extern int buffer_putalign(buffer *,char *,unsigned int); +extern int buffer_putflush(buffer *,char *,unsigned int); +extern int buffer_puts(buffer *,char *); +extern int buffer_putsalign(buffer *,char *); +extern int buffer_putsflush(buffer *,char *); + +#define buffer_PUTC(s,c) \ + ( ((s)->n != (s)->p) \ + ? ( (s)->x[(s)->p++] = (c), 0 ) \ + : buffer_put((s),&(c),1) \ + ) + +extern int buffer_get(buffer *,char *,unsigned int); +extern int buffer_bget(buffer *,char *,unsigned int); +extern int buffer_feed(buffer *); + +extern char *buffer_peek(buffer *); +extern void buffer_seek(buffer *,unsigned int); + +#define buffer_PEEK(s) ( (s)->x + (s)->n ) +#define buffer_SEEK(s,len) ( ( (s)->p -= (len) ) , ( (s)->n += (len) ) ) + +#define buffer_GETC(s,c) \ + ( ((s)->p > 0) \ + ? ( *(c) = (s)->x[(s)->n], buffer_SEEK((s),1), 1 ) \ + : buffer_get((s),(c),1) \ + ) + +extern int buffer_copy(buffer *,buffer *); + +extern buffer *buffer_0; +extern buffer *buffer_0small; +extern buffer *buffer_1; +extern buffer *buffer_1small; +extern buffer *buffer_2; + +#endif diff -BbrurN sendmail-8.12.7/libsmdb/buffer_put.c sendmail-8.12.7-cdb-testbuild/libsmdb/buffer_put.c --- sendmail-8.12.7/libsmdb/buffer_put.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/buffer_put.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,88 @@ +#include "buffer.h" +#include "str.h" +#include "byte.h" +#include "error.h" + +static int allwrite(int (*op)(),int fd,char *buf,unsigned int len) +{ + int w; + + while (len) { + w = op(fd,buf,len); + if (w == -1) { + if (errno == error_intr) continue; + return -1; /* note that some data may have been written */ + } + if (w == 0) ; /* luser's fault */ + buf += w; + len -= w; + } + return 0; +} + +int buffer_flush(buffer *s) +{ + int p; + + p = s->p; + if (!p) return 0; + s->p = 0; + return allwrite(s->op,s->fd,s->x,p); +} + +int buffer_putalign(buffer *s,char *buf,unsigned int len) +{ + unsigned int n; + + while (len > (n = s->n - s->p)) { + byte_copy(s->x + s->p,n,buf); s->p += n; buf += n; len -= n; + if (buffer_flush(s) == -1) return -1; + } + /* now len <= s->n - s->p */ + byte_copy(s->x + s->p,len,buf); + s->p += len; + return 0; +} + +int buffer_put(buffer *s,char *buf,unsigned int len) +{ + unsigned int n; + + n = s->n; + if (len > n - s->p) { + if (buffer_flush(s) == -1) return -1; + /* now s->p == 0 */ + if (n < BUFFER_OUTSIZE) n = BUFFER_OUTSIZE; + while (len > s->n) { + if (n > len) n = len; + if (allwrite(s->op,s->fd,buf,n) == -1) return -1; + buf += n; + len -= n; + } + } + /* now len <= s->n - s->p */ + byte_copy(s->x + s->p,len,buf); + s->p += len; + return 0; +} + +int buffer_putflush(buffer *s,char *buf,unsigned int len) +{ + if (buffer_flush(s) == -1) return -1; + return allwrite(s->op,s->fd,buf,len); +} + +int buffer_putsalign(buffer *s,char *buf) +{ + return buffer_putalign(s,buf,str_len(buf)); +} + +int buffer_puts(buffer *s,char *buf) +{ + return buffer_put(s,buf,str_len(buf)); +} + +int buffer_putsflush(buffer *s,char *buf) +{ + return buffer_putflush(s,buf,str_len(buf)); +} diff -BbrurN sendmail-8.12.7/libsmdb/byte_copy.c sendmail-8.12.7-cdb-testbuild/libsmdb/byte_copy.c --- sendmail-8.12.7/libsmdb/byte_copy.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/byte_copy.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,14 @@ +#include "byte.h" + +void byte_copy(to,n,from) +register char *to; +register unsigned int n; +register char *from; +{ + for (;;) { + if (!n) return; *to++ = *from++; --n; + if (!n) return; *to++ = *from++; --n; + if (!n) return; *to++ = *from++; --n; + if (!n) return; *to++ = *from++; --n; + } +} diff -BbrurN sendmail-8.12.7/libsmdb/byte_cr.c sendmail-8.12.7-cdb-testbuild/libsmdb/byte_cr.c --- sendmail-8.12.7/libsmdb/byte_cr.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/byte_cr.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,16 @@ +#include "byte.h" + +void byte_copyr(to,n,from) +register char *to; +register unsigned int n; +register char *from; +{ + to += n; + from += n; + for (;;) { + if (!n) return; *--to = *--from; --n; + if (!n) return; *--to = *--from; --n; + if (!n) return; *--to = *--from; --n; + if (!n) return; *--to = *--from; --n; + } +} diff -BbrurN sendmail-8.12.7/libsmdb/byte_diff.c sendmail-8.12.7-cdb-testbuild/libsmdb/byte_diff.c --- sendmail-8.12.7/libsmdb/byte_diff.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/byte_diff.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,16 @@ +#include "byte.h" + +int byte_diff(s,n,t) +register char *s; +register unsigned int n; +register char *t; +{ + for (;;) { + if (!n) return 0; if (*s != *t) break; ++s; ++t; --n; + if (!n) return 0; if (*s != *t) break; ++s; ++t; --n; + if (!n) return 0; if (*s != *t) break; ++s; ++t; --n; + if (!n) return 0; if (*s != *t) break; ++s; ++t; --n; + } + return ((int)(unsigned int)(unsigned char) *s) + - ((int)(unsigned int)(unsigned char) *t); +} diff -BbrurN sendmail-8.12.7/libsmdb/byte.h sendmail-8.12.7-cdb-testbuild/libsmdb/byte.h --- sendmail-8.12.7/libsmdb/byte.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/byte.h 2003-01-29 01:23:51.000000000 +0800 @@ -0,0 +1,13 @@ +#ifndef BYTE_H +#define BYTE_H + +extern unsigned int byte_chr(); +extern unsigned int byte_rchr(); +extern void byte_copy(); +extern void byte_copyr(); +extern int byte_diff(); +extern void byte_zero(); + +#define byte_equal(s,n,t) (!byte_diff((s),(n),(t))) + +#endif diff -BbrurN sendmail-8.12.7/libsmdb/cdb.c sendmail-8.12.7-cdb-testbuild/libsmdb/cdb.c --- sendmail-8.12.7/libsmdb/cdb.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/cdb.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,136 @@ +/* Public domain. */ + +#include +#include +#include +#include "readwrite.h" +#include "error.h" +#include "seek.h" +#include "byte.h" +#include "cdb.h" + +void cdb_free(struct cdb *c) +{ + if (c->map) { + munmap(c->map,c->size); + c->map = 0; + } +} + +void cdb_findstart(struct cdb *c) +{ + c->loop = 0; +} + +void cdb_init(struct cdb *c,int fd) +{ + struct stat st; + char *x; + + cdb_free(c); + cdb_findstart(c); + c->fd = fd; + + if (fstat(fd,&st) == 0) + if (st.st_size <= 0xffffffff) { + x = mmap(0,st.st_size,PROT_READ,MAP_SHARED,fd,0); + if (x + 1) { + c->size = st.st_size; + c->map = x; + } + } +} + +int cdb_read(struct cdb *c,char *buf,unsigned int len,uint32 pos) +{ + if (c->map) { + if ((pos > c->size) || (c->size - pos < len)) goto FORMAT; + byte_copy(buf,len,c->map + pos); + } + else { + if (seek_set(c->fd,pos) == -1) return -1; + while (len > 0) { + int r; + do + r = read(c->fd,buf,len); + while ((r == -1) && (errno == error_intr)); + if (r == -1) return -1; + if (r == 0) goto FORMAT; + buf += r; + len -= r; + } + } + return 0; + + FORMAT: + errno = error_proto; + return -1; +} + +static int match(struct cdb *c,char *key,unsigned int len,uint32 pos) +{ + char buf[32]; + int n; + + while (len > 0) { + n = sizeof buf; + if (n > len) n = len; + if (cdb_read(c,buf,n,pos) == -1) return -1; + if (byte_diff(buf,n,key)) return 0; + pos += n; + key += n; + len -= n; + } + return 1; +} + +int cdb_findnext(struct cdb *c,char *key,unsigned int len) +{ + char buf[8]; + uint32 pos; + uint32 u; + + if (!c->loop) { + u = cdb_hash(key,len); + if (cdb_read(c,buf,8,(u << 3) & 2047) == -1) return -1; + uint32_unpack(buf + 4,&c->hslots); + if (!c->hslots) return 0; + uint32_unpack(buf,&c->hpos); + c->khash = u; + u >>= 8; + u %= c->hslots; + u <<= 3; + c->kpos = c->hpos + u; + } + + while (c->loop < c->hslots) { + if (cdb_read(c,buf,8,c->kpos) == -1) return -1; + uint32_unpack(buf + 4,&pos); + if (!pos) return 0; + c->loop += 1; + c->kpos += 8; + if (c->kpos == c->hpos + (c->hslots << 3)) c->kpos = c->hpos; + uint32_unpack(buf,&u); + if (u == c->khash) { + if (cdb_read(c,buf,8,pos) == -1) return -1; + uint32_unpack(buf,&u); + if (u == len) + switch(match(c,key,len,pos + 8)) { + case -1: + return -1; + case 1: + uint32_unpack(buf + 4,&c->dlen); + c->dpos = pos + 8 + len; + return 1; + } + } + } + + return 0; +} + +int cdb_find(struct cdb *c,char *key,unsigned int len) +{ + cdb_findstart(c); + return cdb_findnext(c,key,len); +} diff -BbrurN sendmail-8.12.7/libsmdb/cdbdump.c sendmail-8.12.7-cdb-testbuild/libsmdb/cdbdump.c --- sendmail-8.12.7/libsmdb/cdbdump.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/cdbdump.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,83 @@ +#include "uint32.h" +#include "fmt.h" +#include "buffer.h" +#include "strerr.h" + +#define FATAL "cdbdump: fatal: " + +void die_write(void) +{ + strerr_die2sys(111,FATAL,"unable to write output: "); +} +void put(char *buf,unsigned int len) +{ + if (buffer_put(buffer_1,buf,len) == -1) die_write(); +} +void putflush(void) +{ + if (buffer_flush(buffer_1) == -1) die_write(); +} + +uint32 pos = 0; + +void get(char *buf,unsigned int len) +{ + int r; + while (len > 0) { + r = buffer_get(buffer_0,buf,len); + if (r == -1) + strerr_die2sys(111,FATAL,"unable to read input: "); + if (r == 0) + strerr_die2x(111,FATAL,"unable to read input: truncated file"); + pos += r; + buf += r; + len -= r; + } +} + +char buf[512]; + +void copy(uint32 len) +{ + unsigned int x; + + while (len) { + x = sizeof buf; + if (len < x) x = len; + get(buf,x); + put(buf,x); + len -= x; + } +} + +void getnum(uint32 *num) +{ + get(buf,4); + uint32_unpack(buf,num); +} + +char strnum[FMT_ULONG]; + +main() +{ + uint32 eod; + uint32 klen; + uint32 dlen; + + getnum(&eod); + while (pos < 2048) getnum(&dlen); + + while (pos < eod) { + getnum(&klen); + getnum(&dlen); + put("+",1); put(strnum,fmt_ulong(strnum,klen)); + put(",",1); put(strnum,fmt_ulong(strnum,dlen)); + put(":",1); copy(klen); + put("->",2); copy(dlen); + put("\n",1); + } + + put("\n",1); + putflush(); + _exit(0); +} diff -BbrurN sendmail-8.12.7/libsmdb/cdbget.c sendmail-8.12.7-cdb-testbuild/libsmdb/cdbget.c --- sendmail-8.12.7/libsmdb/cdbget.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/cdbget.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,67 @@ +#include "exit.h" +#include "scan.h" +#include "str.h" +#include "buffer.h" +#include "strerr.h" +#include "cdb.h" + +#define FATAL "cdbget: fatal: " + +void die_read(void) +{ + strerr_die2sys(111,FATAL,"unable to read input: "); +} +void die_write(void) +{ + strerr_die2sys(111,FATAL,"unable to write output: "); +} +void die_usage(void) +{ + strerr_die1x(111,"cdbget: usage: cdbget key [skip]"); +} + +static struct cdb c; +char buf[1024]; + +main(int argc,char **argv) +{ + char *key; + int r; + uint32 pos; + uint32 len; + unsigned long u = 0; + + if (!*argv) die_usage(); + + if (!*++argv) die_usage(); + key = *argv; + + if (*++argv) { + scan_ulong(*argv,&u); + } + + cdb_init(&c,0); + cdb_findstart(&c); + + for (;;) { + r = cdb_findnext(&c,key,str_len(key)); + if (r == -1) die_read(); + if (!r) _exit(100); + if (!u) break; + --u; + } + + pos = cdb_datapos(&c); + len = cdb_datalen(&c); + + while (len > 0) { + r = sizeof buf; + if (r > len) r = len; + if (cdb_read(&c,buf,r,pos) == -1) die_read(); + if (buffer_put(buffer_1small,buf,r) == -1) die_write(); + pos += r; + len -= r; + } + if (buffer_flush(buffer_1small) == -1) die_write(); + _exit(0); +} diff -BbrurN sendmail-8.12.7/libsmdb/cdb.h sendmail-8.12.7-cdb-testbuild/libsmdb/cdb.h --- sendmail-8.12.7/libsmdb/cdb.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/cdb.h 2003-01-29 01:23:51.000000000 +0800 @@ -0,0 +1,37 @@ +/* Public domain. */ + +#ifndef CDB_H +#define CDB_H + +#include "uint32.h" + +#define CDB_HASHSTART 5381 +extern uint32 cdb_hashadd(uint32,unsigned char); +extern uint32 cdb_hash(char *,unsigned int); + +struct cdb { + char *map; /* 0 if no map is available */ + int fd; + uint32 size; /* initialized if map is nonzero */ + uint32 loop; /* number of hash slots searched under this key */ + uint32 khash; /* initialized if loop is nonzero */ + uint32 kpos; /* initialized if loop is nonzero */ + uint32 hpos; /* initialized if loop is nonzero */ + uint32 hslots; /* initialized if loop is nonzero */ + uint32 dpos; /* initialized if cdb_findnext() returns 1 */ + uint32 dlen; /* initialized if cdb_findnext() returns 1 */ +} ; + +extern void cdb_free(struct cdb *); +extern void cdb_init(struct cdb *,int fd); + +extern int cdb_read(struct cdb *,char *,unsigned int,uint32); + +extern void cdb_findstart(struct cdb *); +extern int cdb_findnext(struct cdb *,char *,unsigned int); +extern int cdb_find(struct cdb *,char *,unsigned int); + +#define cdb_datapos(c) ((c)->dpos) +#define cdb_datalen(c) ((c)->dlen) + +#endif diff -BbrurN sendmail-8.12.7/libsmdb/cdb_hash.c sendmail-8.12.7-cdb-testbuild/libsmdb/cdb_hash.c --- sendmail-8.12.7/libsmdb/cdb_hash.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/cdb_hash.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,21 @@ +/* Public domain. */ + +#include "cdb.h" + +uint32 cdb_hashadd(uint32 h,unsigned char c) +{ + h += (h << 5); + return h ^ c; +} + +uint32 cdb_hash(char *buf,unsigned int len) +{ + uint32 h; + + h = CDB_HASHSTART; + while (len) { + h = cdb_hashadd(h,*buf++); + --len; + } + return h; +} diff -BbrurN sendmail-8.12.7/libsmdb/cdb_make.c sendmail-8.12.7-cdb-testbuild/libsmdb/cdb_make.c --- sendmail-8.12.7/libsmdb/cdb_make.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/cdb_make.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,153 @@ +/* Public domain. */ + +#include "readwrite.h" +#include "seek.h" +#include "error.h" +#include "alloc.h" +#include "cdb.h" +#include "cdb_make.h" + +int cdb_make_start(struct cdb_make *c,int fd) +{ + c->head = 0; + c->split = 0; + c->hash = 0; + c->numentries = 0; + c->fd = fd; + c->pos = sizeof c->final; + buffer_init(&c->b,write,fd,c->bspace,sizeof c->bspace); + return seek_set(fd,c->pos); +} + +static int posplus(struct cdb_make *c,uint32 len) +{ + uint32 newpos = c->pos + len; + if (newpos < len) { errno = error_nomem; return -1; } + c->pos = newpos; + return 0; +} + +int cdb_make_addend(struct cdb_make *c,unsigned int keylen,unsigned int datalen,uint32 h) +{ + struct cdb_hplist *head; + + head = c->head; + if (!head || (head->num >= CDB_HPLIST)) { + head = (struct cdb_hplist *) alloc(sizeof(struct cdb_hplist)); + if (!head) return -1; + head->num = 0; + head->next = c->head; + c->head = head; + } + head->hp[head->num].h = h; + head->hp[head->num].p = c->pos; + ++head->num; + ++c->numentries; + if (posplus(c,8) == -1) return -1; + if (posplus(c,keylen) == -1) return -1; + if (posplus(c,datalen) == -1) return -1; + return 0; +} + +int cdb_make_addbegin(struct cdb_make *c,unsigned int keylen,unsigned int datalen) +{ + char buf[8]; + + if (keylen > 0xffffffff) { errno = error_nomem; return -1; } + if (datalen > 0xffffffff) { errno = error_nomem; return -1; } + + uint32_pack(buf,keylen); + uint32_pack(buf + 4,datalen); + if (buffer_putalign(&c->b,buf,8) == -1) return -1; + return 0; +} + +int cdb_make_add(struct cdb_make *c,char *key,unsigned int keylen,char *data,unsigned int datalen) +{ + if (cdb_make_addbegin(c,keylen,datalen) == -1) return -1; + if (buffer_putalign(&c->b,key,keylen) == -1) return -1; + if (buffer_putalign(&c->b,data,datalen) == -1) return -1; + return cdb_make_addend(c,keylen,datalen,cdb_hash(key,keylen)); +} + +int cdb_make_finish(struct cdb_make *c) +{ + char buf[8]; + int i; + uint32 len; + uint32 u; + uint32 memsize; + uint32 count; + uint32 where; + struct cdb_hplist *x; + struct cdb_hp *hp; + + for (i = 0;i < 256;++i) + c->count[i] = 0; + + for (x = c->head;x;x = x->next) { + i = x->num; + while (i--) + ++c->count[255 & x->hp[i].h]; + } + + memsize = 1; + for (i = 0;i < 256;++i) { + u = c->count[i] * 2; + if (u > memsize) + memsize = u; + } + + memsize += c->numentries; /* no overflow possible up to now */ + u = (uint32) 0 - (uint32) 1; + u /= sizeof(struct cdb_hp); + if (memsize > u) { errno = error_nomem; return -1; } + + c->split = (struct cdb_hp *) alloc(memsize * sizeof(struct cdb_hp)); + if (!c->split) return -1; + + c->hash = c->split + c->numentries; + + u = 0; + for (i = 0;i < 256;++i) { + u += c->count[i]; /* bounded by numentries, so no overflow */ + c->start[i] = u; + } + + for (x = c->head;x;x = x->next) { + i = x->num; + while (i--) + c->split[--c->start[255 & x->hp[i].h]] = x->hp[i]; + } + + for (i = 0;i < 256;++i) { + count = c->count[i]; + + len = count + count; /* no overflow possible */ + uint32_pack(c->final + 8 * i,c->pos); + uint32_pack(c->final + 8 * i + 4,len); + + for (u = 0;u < len;++u) + c->hash[u].h = c->hash[u].p = 0; + + hp = c->split + c->start[i]; + for (u = 0;u < count;++u) { + where = (hp->h >> 8) % len; + while (c->hash[where].p) + if (++where == len) + where = 0; + c->hash[where] = *hp++; + } + + for (u = 0;u < len;++u) { + uint32_pack(buf,c->hash[u].h); + uint32_pack(buf + 4,c->hash[u].p); + if (buffer_putalign(&c->b,buf,8) == -1) return -1; + if (posplus(c,8) == -1) return -1; + } + } + + if (buffer_flush(&c->b) == -1) return -1; + if (seek_begin(c->fd) == -1) return -1; + return buffer_putflush(&c->b,c->final,sizeof c->final); +} diff -BbrurN sendmail-8.12.7/libsmdb/cdbmake.c sendmail-8.12.7-cdb-testbuild/libsmdb/cdbmake.c --- sendmail-8.12.7/libsmdb/cdbmake.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/cdbmake.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,110 @@ +#include "error.h" +#include "open.h" +#include "strerr.h" +#include "cdb_make.h" +#include "cdb.h" + +#define FATAL "cdbmake: fatal: " + +char *fn; +char *fntmp; + +void die_usage(void) +{ + strerr_die1x(100,"cdbmake: usage: cdbmake f ftmp"); +} +void die_write(void) +{ + strerr_die4sys(111,FATAL,"unable to create ",fntmp,": "); +} +void die_read(void) +{ + strerr_die2sys(111,FATAL,"unable to read input: "); +} +void die_readformat(void) +{ + strerr_die2x(111,FATAL,"unable to read input: bad format"); +} + +inline void get(char *ch) +{ + switch(buffer_GETC(buffer_0,ch)) { + case 0: die_readformat(); + case -1: die_read(); + } +} + +static struct cdb_make c; + +main(int argc,char **argv) +{ + unsigned int klen; + unsigned int dlen; + unsigned int i; + uint32 h; + int fd; + char ch; + + if (!*argv) die_usage(); + + if (!*++argv) die_usage(); + fn = *argv; + + if (!*++argv) die_usage(); + fntmp = *argv; + + fd = open_trunc(fntmp); + if (fd == -1) die_write(); + + if (cdb_make_start(&c,fd) == -1) die_write(); + + for (;;) { + get(&ch); + if (ch == '\n') break; + if (ch != '+') die_readformat(); + klen = 0; + for (;;) { + get(&ch); + if (ch == ',') break; + if ((ch < '0') || (ch > '9')) die_readformat(); + if (klen > 429496720) { errno = error_nomem; die_write(); } + klen = klen * 10 + (ch - '0'); + } + dlen = 0; + for (;;) { + get(&ch); + if (ch == ':') break; + if ((ch < '0') || (ch > '9')) die_readformat(); + if (dlen > 429496720) { errno = error_nomem; die_write(); } + dlen = dlen * 10 + (ch - '0'); + } + + if (cdb_make_addbegin(&c,klen,dlen) == -1) die_write(); + h = CDB_HASHSTART; + for (i = 0;i < klen;++i) { + get(&ch); + if (buffer_PUTC(&c.b,ch) == -1) die_write(); + h = cdb_hashadd(h,ch); + } + get(&ch); + if (ch != '-') die_readformat(); + get(&ch); + if (ch != '>') die_readformat(); + for (i = 0;i < dlen;++i) { + get(&ch); + if (buffer_PUTC(&c.b,ch) == -1) die_write(); + } + if (cdb_make_addend(&c,klen,dlen,h) == -1) die_write(); + + get(&ch); + if (ch != '\n') die_readformat(); + } + + if (cdb_make_finish(&c) == -1) die_write(); + if (fsync(fd) == -1) die_write(); + if (close(fd) == -1) die_write(); /* NFS silliness */ + if (rename(fntmp,fn) == -1) + strerr_die6sys(111,FATAL,"unable to rename ",fntmp," to ",fn,": "); + + _exit(0); +} diff -BbrurN sendmail-8.12.7/libsmdb/cdb_make.h sendmail-8.12.7-cdb-testbuild/libsmdb/cdb_make.h --- sendmail-8.12.7/libsmdb/cdb_make.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/cdb_make.h 2003-01-29 01:23:51.000000000 +0800 @@ -0,0 +1,39 @@ +/* Public domain. */ + +#ifndef CDB_MAKE_H +#define CDB_MAKE_H + +#include "buffer.h" +#include "uint32.h" + +#define CDB_HPLIST 1000 + +struct cdb_hp { uint32 h; uint32 p; } ; + +struct cdb_hplist { + struct cdb_hp hp[CDB_HPLIST]; + struct cdb_hplist *next; + int num; +} ; + +struct cdb_make { + char bspace[8192]; + char final[2048]; + uint32 count[256]; + uint32 start[256]; + struct cdb_hplist *head; + struct cdb_hp *split; /* includes space for hash */ + struct cdb_hp *hash; + uint32 numentries; + buffer b; + uint32 pos; + int fd; +} ; + +extern int cdb_make_start(struct cdb_make *,int); +extern int cdb_make_addbegin(struct cdb_make *,unsigned int,unsigned int); +extern int cdb_make_addend(struct cdb_make *,unsigned int,unsigned int,uint32); +extern int cdb_make_add(struct cdb_make *,char *,unsigned int,char *,unsigned int); +extern int cdb_make_finish(struct cdb_make *); + +#endif diff -BbrurN sendmail-8.12.7/libsmdb/cdbstats.c sendmail-8.12.7-cdb-testbuild/libsmdb/cdbstats.c --- sendmail-8.12.7/libsmdb/cdbstats.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/cdbstats.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,125 @@ +#include "uint32.h" +#include "fmt.h" +#include "buffer.h" +#include "strerr.h" +#include "seek.h" +#include "cdb.h" + +#define FATAL "cdbstats: fatal: " + +void die_read(void) +{ + strerr_die2sys(111,FATAL,"unable to read input: "); +} +void die_readformat(void) +{ + strerr_die2x(111,FATAL,"unable to read input: truncated file"); +} +void die_write(void) +{ + strerr_die2sys(111,FATAL,"unable to write output: "); +} +void put(char *buf,unsigned int len) +{ + if (buffer_put(buffer_1small,buf,len) == -1) die_write(); +} +void putflush(void) +{ + if (buffer_flush(buffer_1small) == -1) die_write(); +} + +uint32 pos = 0; + +void get(char *buf,unsigned int len) +{ + int r; + while (len > 0) { + r = buffer_get(buffer_0,buf,len); + if (r == -1) die_read(); + if (r == 0) die_readformat(); + pos += r; + buf += r; + len -= r; + } +} + +void getnum(uint32 *num) +{ + char buf[4]; + get(buf,4); + uint32_unpack(buf,num); +} + +char strnum[FMT_ULONG]; + +void putnum(char *label,unsigned long count) +{ + unsigned int i; + put(label,str_len(label)); + for (i = fmt_ulong(0,count);i < 10;++i) put(" ",1); + put(strnum,fmt_ulong(strnum,count)); + put("\n",1); +} + +char key[1024]; + +static struct cdb c; + +static unsigned long numrecords; +static unsigned long numd[11]; + +main() +{ + uint32 eod; + uint32 klen; + uint32 dlen; + seek_pos rest; + int r; + + cdb_init(&c,0); + + getnum(&eod); + while (pos < 2048) getnum(&dlen); + + while (pos < eod) { + getnum(&klen); + getnum(&dlen); + if (klen > sizeof key) { + while (klen) { get(key,1); --klen; } + } + else { + get(key,klen); + rest = seek_cur(0); + cdb_findstart(&c); + do { + switch(cdb_findnext(&c,key,klen)) { + case -1: die_read(); + case 0: die_readformat(); + } + } while (cdb_datapos(&c) != pos); + if (!c.loop) die_readformat(); + ++numrecords; + if (c.loop > 10) + ++numd[10]; + else + ++numd[c.loop - 1]; + if (seek_set(0,rest) == -1) die_read(); + } + while (dlen) { get(key,1); --dlen; } + } + + putnum("records ",numrecords); + putnum("d0 ",numd[0]); + putnum("d1 ",numd[1]); + putnum("d2 ",numd[2]); + putnum("d3 ",numd[3]); + putnum("d4 ",numd[4]); + putnum("d5 ",numd[5]); + putnum("d6 ",numd[6]); + putnum("d7 ",numd[7]); + putnum("d8 ",numd[8]); + putnum("d9 ",numd[9]); + putnum(">9 ",numd[10]); + putflush(); + _exit(0); +} diff -BbrurN sendmail-8.12.7/libsmdb/cdbtest.c sendmail-8.12.7-cdb-testbuild/libsmdb/cdbtest.c --- sendmail-8.12.7/libsmdb/cdbtest.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/cdbtest.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,119 @@ +#include "uint32.h" +#include "fmt.h" +#include "buffer.h" +#include "strerr.h" +#include "seek.h" +#include "cdb.h" + +#define FATAL "cdbtest: fatal: " + +void die_read(void) +{ + strerr_die2sys(111,FATAL,"unable to read input: "); +} +void die_write(void) +{ + strerr_die2sys(111,FATAL,"unable to write output: "); +} +void put(char *buf,unsigned int len) +{ + if (buffer_put(buffer_1small,buf,len) == -1) die_write(); +} +void putflush(void) +{ + if (buffer_flush(buffer_1small) == -1) die_write(); +} + +uint32 pos = 0; + +void get(char *buf,unsigned int len) +{ + int r; + while (len > 0) { + r = buffer_get(buffer_0,buf,len); + if (r == -1) die_read(); + if (r == 0) + strerr_die2x(111,FATAL,"unable to read input: truncated file"); + pos += r; + buf += r; + len -= r; + } +} + +void getnum(uint32 *num) +{ + char buf[4]; + get(buf,4); + uint32_unpack(buf,num); +} + +char strnum[FMT_ULONG]; + +void putnum(char *label,unsigned long count) +{ + put(label,str_len(label)); + put(strnum,fmt_ulong(strnum,count)); + put("\n",1); +} + +char key[1024]; + +unsigned long numuntested = 0; +unsigned long numnotfound = 0; +unsigned long numotherpos = 0; +unsigned long numbadlen = 0; +unsigned long numfound = 0; + +static struct cdb c; + +main() +{ + uint32 eod; + uint32 klen; + uint32 dlen; + seek_pos rest; + int r; + + cdb_init(&c,0); + + getnum(&eod); + while (pos < 2048) getnum(&dlen); + + while (pos < eod) { + getnum(&klen); + getnum(&dlen); + if (klen > sizeof key) { + ++numuntested; + while (klen) { get(key,1); --klen; } + } + else { + get(key,klen); + rest = seek_cur(0); + switch(cdb_find(&c,key,klen)) { + case -1: + die_read(); + case 0: + ++numnotfound; + break; + default: + if (cdb_datapos(&c) != pos) + ++numotherpos; + else + if (cdb_datalen(&c) != dlen) + ++numbadlen; + else + ++numfound; + } + if (seek_set(0,rest) == -1) die_read(); + } + while (dlen) { get(key,1); --dlen; } + } + + putnum("found: ",numfound); + putnum("different record: ",numotherpos); + putnum("bad length: ",numbadlen); + putnum("not found: ",numnotfound); + putnum("untested: ",numuntested); + putflush(); + _exit(0); +} diff -BbrurN sendmail-8.12.7/libsmdb/error.c sendmail-8.12.7-cdb-testbuild/libsmdb/error.c --- sendmail-8.12.7/libsmdb/error.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/error.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,109 @@ +#include +#include "error.h" + +/* warning: as coverage improves here, should update error_{str,temp} */ + +int error_intr = +#ifdef EINTR +EINTR; +#else +-1; +#endif + +int error_nomem = +#ifdef ENOMEM +ENOMEM; +#else +-2; +#endif + +int error_noent = +#ifdef ENOENT +ENOENT; +#else +-3; +#endif + +int error_txtbsy = +#ifdef ETXTBSY +ETXTBSY; +#else +-4; +#endif + +int error_io = +#ifdef EIO +EIO; +#else +-5; +#endif + +int error_exist = +#ifdef EEXIST +EEXIST; +#else +-6; +#endif + +int error_timeout = +#ifdef ETIMEDOUT +ETIMEDOUT; +#else +-7; +#endif + +int error_inprogress = +#ifdef EINPROGRESS +EINPROGRESS; +#else +-8; +#endif + +int error_wouldblock = +#ifdef EWOULDBLOCK +EWOULDBLOCK; +#else +-9; +#endif + +int error_again = +#ifdef EAGAIN +EAGAIN; +#else +-10; +#endif + +int error_pipe = +#ifdef EPIPE +EPIPE; +#else +-11; +#endif + +int error_perm = +#ifdef EPERM +EPERM; +#else +-12; +#endif + +int error_acces = +#ifdef EACCES +EACCES; +#else +-13; +#endif + +int error_nodevice = +#ifdef ENXIO +ENXIO; +#else +-14; +#endif + +int error_proto = +#ifdef EPROTO +EPROTO; +#else +-15; +#endif diff -BbrurN sendmail-8.12.7/libsmdb/error.h sendmail-8.12.7-cdb-testbuild/libsmdb/error.h --- sendmail-8.12.7/libsmdb/error.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/error.h 2003-01-29 01:23:51.000000000 +0800 @@ -0,0 +1,25 @@ +#ifndef ERROR_H +#define ERROR_H + +extern int errno; + +extern int error_intr; +extern int error_nomem; +extern int error_noent; +extern int error_txtbsy; +extern int error_io; +extern int error_exist; +extern int error_timeout; +extern int error_inprogress; +extern int error_wouldblock; +extern int error_again; +extern int error_pipe; +extern int error_perm; +extern int error_acces; +extern int error_nodevice; +extern int error_proto; + +extern char *error_str(int); +extern int error_temp(int); + +#endif diff -BbrurN sendmail-8.12.7/libsmdb/error_str.c sendmail-8.12.7-cdb-testbuild/libsmdb/error_str.c --- sendmail-8.12.7/libsmdb/error_str.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/error_str.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,271 @@ +#include +#include "error.h" + +#define X(e,s) if (i == e) return s; + +char *error_str(int i) +{ + X(0,"no error") + X(error_intr,"interrupted system call") + X(error_nomem,"out of memory") + X(error_noent,"file does not exist") + X(error_txtbsy,"text busy") + X(error_io,"input/output error") + X(error_exist,"file already exists") + X(error_timeout,"timed out") + X(error_inprogress,"operation in progress") + X(error_again,"temporary failure") + X(error_wouldblock,"input/output would block") + X(error_pipe,"broken pipe") + X(error_perm,"permission denied") + X(error_acces,"access denied") + X(error_nodevice,"device not configured") + X(error_proto,"protocol error") +#ifdef ESRCH + X(ESRCH,"no such process") +#endif +#ifdef E2BIG + X(E2BIG,"argument list too long") +#endif +#ifdef ENOEXEC + X(ENOEXEC,"exec format error") +#endif +#ifdef EBADF + X(EBADF,"file descriptor not open") +#endif +#ifdef ECHILD + X(ECHILD,"no child processes") +#endif +#ifdef EDEADLK + X(EDEADLK,"operation would cause deadlock") +#endif +#ifdef EFAULT + X(EFAULT,"bad address") +#endif +#ifdef ENOTBLK + X(ENOTBLK,"not a block device") +#endif +#ifdef EBUSY + X(EBUSY,"device busy") +#endif +#ifdef EXDEV + X(EXDEV,"cross-device link") +#endif +#ifdef ENODEV + X(ENODEV,"device does not support operation") +#endif +#ifdef ENOTDIR + X(ENOTDIR,"not a directory") +#endif +#ifdef EISDIR + X(EISDIR,"is a directory") +#endif +#ifdef EINVAL + X(EINVAL,"invalid argument") +#endif +#ifdef ENFILE + X(ENFILE,"system cannot open more files") +#endif +#ifdef EMFILE + X(EMFILE,"process cannot open more files") +#endif +#ifdef ENOTTY + X(ENOTTY,"not a tty") +#endif +#ifdef EFBIG + X(EFBIG,"file too big") +#endif +#ifdef ENOSPC + X(ENOSPC,"out of disk space") +#endif +#ifdef ESPIPE + X(ESPIPE,"unseekable descriptor") +#endif +#ifdef EROFS + X(EROFS,"read-only file system") +#endif +#ifdef EMLINK + X(EMLINK,"too many links") +#endif +#ifdef EDOM + X(EDOM,"input out of range") +#endif +#ifdef ERANGE + X(ERANGE,"output out of range") +#endif +#ifdef EALREADY + X(EALREADY,"operation already in progress") +#endif +#ifdef ENOTSOCK + X(ENOTSOCK,"not a socket") +#endif +#ifdef EDESTADDRREQ + X(EDESTADDRREQ,"destination address required") +#endif +#ifdef EMSGSIZE + X(EMSGSIZE,"message too long") +#endif +#ifdef EPROTOTYPE + X(EPROTOTYPE,"incorrect protocol type") +#endif +#ifdef ENOPROTOOPT + X(ENOPROTOOPT,"protocol not available") +#endif +#ifdef EPROTONOSUPPORT + X(EPROTONOSUPPORT,"protocol not supported") +#endif +#ifdef ESOCKTNOSUPPORT + X(ESOCKTNOSUPPORT,"socket type not supported") +#endif +#ifdef EOPNOTSUPP + X(EOPNOTSUPP,"operation not supported") +#endif +#ifdef EPFNOSUPPORT + X(EPFNOSUPPORT,"protocol family not supported") +#endif +#ifdef EAFNOSUPPORT + X(EAFNOSUPPORT,"address family not supported") +#endif +#ifdef EADDRINUSE + X(EADDRINUSE,"address already used") +#endif +#ifdef EADDRNOTAVAIL + X(EADDRNOTAVAIL,"address not available") +#endif +#ifdef ENETDOWN + X(ENETDOWN,"network down") +#endif +#ifdef ENETUNREACH + X(ENETUNREACH,"network unreachable") +#endif +#ifdef ENETRESET + X(ENETRESET,"network reset") +#endif +#ifdef ECONNABORTED + X(ECONNABORTED,"connection aborted") +#endif +#ifdef ECONNRESET + X(ECONNRESET,"connection reset") +#endif +#ifdef ENOBUFS + X(ENOBUFS,"out of buffer space") +#endif +#ifdef EISCONN + X(EISCONN,"already connected") +#endif +#ifdef ENOTCONN + X(ENOTCONN,"not connected") +#endif +#ifdef ESHUTDOWN + X(ESHUTDOWN,"socket shut down") +#endif +#ifdef ETOOMANYREFS + X(ETOOMANYREFS,"too many references") +#endif +#ifdef ECONNREFUSED + X(ECONNREFUSED,"connection refused") +#endif +#ifdef ELOOP + X(ELOOP,"symbolic link loop") +#endif +#ifdef ENAMETOOLONG + X(ENAMETOOLONG,"file name too long") +#endif +#ifdef EHOSTDOWN + X(EHOSTDOWN,"host down") +#endif +#ifdef EHOSTUNREACH + X(EHOSTUNREACH,"host unreachable") +#endif +#ifdef ENOTEMPTY + X(ENOTEMPTY,"directory not empty") +#endif +#ifdef EPROCLIM + X(EPROCLIM,"too many processes") +#endif +#ifdef EUSERS + X(EUSERS,"too many users") +#endif +#ifdef EDQUOT + X(EDQUOT,"disk quota exceeded") +#endif +#ifdef ESTALE + X(ESTALE,"stale NFS file handle") +#endif +#ifdef EREMOTE + X(EREMOTE,"too many levels of remote in path") +#endif +#ifdef EBADRPC + X(EBADRPC,"RPC structure is bad") +#endif +#ifdef ERPCMISMATCH + X(ERPCMISMATCH,"RPC version mismatch") +#endif +#ifdef EPROGUNAVAIL + X(EPROGUNAVAIL,"RPC program unavailable") +#endif +#ifdef EPROGMISMATCH + X(EPROGMISMATCH,"program version mismatch") +#endif +#ifdef EPROCUNAVAIL + X(EPROCUNAVAIL,"bad procedure for program") +#endif +#ifdef ENOLCK + X(ENOLCK,"no locks available") +#endif +#ifdef ENOSYS + X(ENOSYS,"system call not available") +#endif +#ifdef EFTYPE + X(EFTYPE,"bad file type") +#endif +#ifdef EAUTH + X(EAUTH,"authentication error") +#endif +#ifdef ENEEDAUTH + X(ENEEDAUTH,"not authenticated") +#endif +#ifdef ENOSTR + X(ENOSTR,"not a stream device") +#endif +#ifdef ETIME + X(ETIME,"timer expired") +#endif +#ifdef ENOSR + X(ENOSR,"out of stream resources") +#endif +#ifdef ENOMSG + X(ENOMSG,"no message of desired type") +#endif +#ifdef EBADMSG + X(EBADMSG,"bad message type") +#endif +#ifdef EIDRM + X(EIDRM,"identifier removed") +#endif +#ifdef ENONET + X(ENONET,"machine not on network") +#endif +#ifdef ERREMOTE + X(ERREMOTE,"object not local") +#endif +#ifdef ENOLINK + X(ENOLINK,"link severed") +#endif +#ifdef EADV + X(EADV,"advertise error") +#endif +#ifdef ESRMNT + X(ESRMNT,"srmount error") +#endif +#ifdef ECOMM + X(ECOMM,"communication error") +#endif +#ifdef EMULTIHOP + X(EMULTIHOP,"multihop attempted") +#endif +#ifdef EREMCHG + X(EREMCHG,"remote address changed") +#endif + return "unknown error"; +} diff -BbrurN sendmail-8.12.7/libsmdb/exit.h sendmail-8.12.7-cdb-testbuild/libsmdb/exit.h --- sendmail-8.12.7/libsmdb/exit.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/exit.h 2003-01-29 01:23:51.000000000 +0800 @@ -0,0 +1,6 @@ +#ifndef EXIT_H +#define EXIT_H + +extern void _exit(); + +#endif diff -BbrurN sendmail-8.12.7/libsmdb/fmt.h sendmail-8.12.7-cdb-testbuild/libsmdb/fmt.h --- sendmail-8.12.7/libsmdb/fmt.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/fmt.h 2003-01-29 01:23:51.000000000 +0800 @@ -0,0 +1,25 @@ +#ifndef FMT_H +#define FMT_H + +#define FMT_ULONG 40 /* enough space to hold 2^128 - 1 in decimal, plus \0 */ +#define FMT_LEN ((char *) 0) /* convenient abbreviation */ + +extern unsigned int fmt_uint(char *,unsigned int); +extern unsigned int fmt_uint0(char *,unsigned int,unsigned int); +extern unsigned int fmt_xint(char *,unsigned int); +extern unsigned int fmt_nbbint(char *,unsigned int,unsigned int,unsigned int,unsigned int); +extern unsigned int fmt_ushort(char *,unsigned short); +extern unsigned int fmt_xshort(char *,unsigned short); +extern unsigned int fmt_nbbshort(char *,unsigned int,unsigned int,unsigned int,unsigned short); +extern unsigned int fmt_ulong(char *,unsigned long); +extern unsigned int fmt_xlong(char *,unsigned long); +extern unsigned int fmt_nbblong(char *,unsigned int,unsigned int,unsigned int,unsigned long); + +extern unsigned int fmt_plusminus(char *,int); +extern unsigned int fmt_minus(char *,int); +extern unsigned int fmt_0x(char *,int); + +extern unsigned int fmt_str(char *,char *); +extern unsigned int fmt_strn(char *,char *,unsigned int); + +#endif diff -BbrurN sendmail-8.12.7/libsmdb/fmt_ulong.c sendmail-8.12.7-cdb-testbuild/libsmdb/fmt_ulong.c --- sendmail-8.12.7/libsmdb/fmt_ulong.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/fmt_ulong.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,13 @@ +#include "fmt.h" + +unsigned int fmt_ulong(register char *s,register unsigned long u) +{ + register unsigned int len; register unsigned long q; + len = 1; q = u; + while (q > 9) { ++len; q /= 10; } + if (s) { + s += len; + do { *--s = '0' + (u % 10); u /= 10; } while(u); /* handles u == 0 */ + } + return len; +} diff -BbrurN sendmail-8.12.7/libsmdb/hier.c sendmail-8.12.7-cdb-testbuild/libsmdb/hier.c --- sendmail-8.12.7/libsmdb/hier.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/hier.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,15 @@ +#include "auto_home.h" + +void hier() +{ + h(auto_home,-1,-1,02755); + d(auto_home,"bin",-1,-1,02755); + + c(auto_home,"bin","cdbget",-1,-1,0755); + c(auto_home,"bin","cdbmake",-1,-1,0755); + c(auto_home,"bin","cdbdump",-1,-1,0755); + c(auto_home,"bin","cdbstats",-1,-1,0755); + c(auto_home,"bin","cdbtest",-1,-1,0755); + c(auto_home,"bin","cdbmake-12",-1,-1,0755); + c(auto_home,"bin","cdbmake-sv",-1,-1,0755); +} diff -BbrurN sendmail-8.12.7/libsmdb/install.c sendmail-8.12.7-cdb-testbuild/libsmdb/install.c --- sendmail-8.12.7/libsmdb/install.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/install.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,149 @@ +#include "buffer.h" +#include "strerr.h" +#include "error.h" +#include "open.h" +#include "readwrite.h" +#include "exit.h" + +extern void hier(); + +#define FATAL "install: fatal: " + +int fdsourcedir = -1; + +void h(home,uid,gid,mode) +char *home; +int uid; +int gid; +int mode; +{ + if (mkdir(home,0700) == -1) + if (errno != error_exist) + strerr_die4sys(111,FATAL,"unable to mkdir ",home,": "); + if (chown(home,uid,gid) == -1) + strerr_die4sys(111,FATAL,"unable to chown ",home,": "); + if (chmod(home,mode) == -1) + strerr_die4sys(111,FATAL,"unable to chmod ",home,": "); +} + +void d(home,subdir,uid,gid,mode) +char *home; +char *subdir; +int uid; +int gid; +int mode; +{ + if (chdir(home) == -1) + strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); + if (mkdir(subdir,0700) == -1) + if (errno != error_exist) + strerr_die6sys(111,FATAL,"unable to mkdir ",home,"/",subdir,": "); + if (chown(subdir,uid,gid) == -1) + strerr_die6sys(111,FATAL,"unable to chown ",home,"/",subdir,": "); + if (chmod(subdir,mode) == -1) + strerr_die6sys(111,FATAL,"unable to chmod ",home,"/",subdir,": "); +} + +char inbuf[BUFFER_INSIZE]; +char outbuf[BUFFER_OUTSIZE]; +buffer ssin; +buffer ssout; + +void c(home,subdir,file,uid,gid,mode) +char *home; +char *subdir; +char *file; +int uid; +int gid; +int mode; +{ + int fdin; + int fdout; + + if (fchdir(fdsourcedir) == -1) + strerr_die2sys(111,FATAL,"unable to switch back to source directory: "); + + fdin = open_read(file); + if (fdin == -1) + strerr_die4sys(111,FATAL,"unable to read ",file,": "); + buffer_init(&ssin,read,fdin,inbuf,sizeof inbuf); + + if (chdir(home) == -1) + strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); + if (chdir(subdir) == -1) + strerr_die6sys(111,FATAL,"unable to switch to ",home,"/",subdir,": "); + + fdout = open_trunc(file); + if (fdout == -1) + strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); + buffer_init(&ssout,write,fdout,outbuf,sizeof outbuf); + + switch(buffer_copy(&ssout,&ssin)) { + case -2: + strerr_die4sys(111,FATAL,"unable to read ",file,": "); + case -3: + strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); + } + + close(fdin); + if (buffer_flush(&ssout) == -1) + strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); + if (fsync(fdout) == -1) + strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); + if (close(fdout) == -1) /* NFS silliness */ + strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); + + if (chown(file,uid,gid) == -1) + strerr_die6sys(111,FATAL,"unable to chown .../",subdir,"/",file,": "); + if (chmod(file,mode) == -1) + strerr_die6sys(111,FATAL,"unable to chmod .../",subdir,"/",file,": "); +} + +void z(home,subdir,file,len,uid,gid,mode) +char *home; +char *subdir; +char *file; +int len; +int uid; +int gid; +int mode; +{ + int fdout; + + if (chdir(home) == -1) + strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); + if (chdir(subdir) == -1) + strerr_die6sys(111,FATAL,"unable to switch to ",home,"/",subdir,": "); + + fdout = open_trunc(file); + if (fdout == -1) + strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); + buffer_init(&ssout,write,fdout,outbuf,sizeof outbuf); + + while (len-- > 0) + if (buffer_put(&ssout,"",1) == -1) + strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); + + if (buffer_flush(&ssout) == -1) + strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); + if (fsync(fdout) == -1) + strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); + if (close(fdout) == -1) /* NFS silliness */ + strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); + + if (chown(file,uid,gid) == -1) + strerr_die6sys(111,FATAL,"unable to chown .../",subdir,"/",file,": "); + if (chmod(file,mode) == -1) + strerr_die6sys(111,FATAL,"unable to chmod .../",subdir,"/",file,": "); +} + +main() +{ + fdsourcedir = open_read("."); + if (fdsourcedir == -1) + strerr_die2sys(111,FATAL,"unable to open current directory: "); + + umask(077); + hier(); + _exit(0); +} diff -BbrurN sendmail-8.12.7/libsmdb/instcheck.c sendmail-8.12.7-cdb-testbuild/libsmdb/instcheck.c --- sendmail-8.12.7/libsmdb/instcheck.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/instcheck.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,108 @@ +#include +#include +#include "strerr.h" +#include "error.h" +#include "readwrite.h" +#include "exit.h" + +extern void hier(); + +#define FATAL "instcheck: fatal: " +#define WARNING "instcheck: warning: " + +void perm(prefix1,prefix2,prefix3,file,type,uid,gid,mode) +char *prefix1; +char *prefix2; +char *prefix3; +char *file; +int type; +int uid; +int gid; +int mode; +{ + struct stat st; + + if (stat(file,&st) == -1) { + if (errno == error_noent) + strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," does not exist",0); + else + strerr_warn4(WARNING,"unable to stat .../",file,": ",&strerr_sys); + return; + } + + if ((uid != -1) && (st.st_uid != uid)) + strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong owner",0); + if ((gid != -1) && (st.st_gid != gid)) + strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong group",0); + if ((st.st_mode & 07777) != mode) + strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong permissions",0); + if ((st.st_mode & S_IFMT) != type) + strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong type",0); +} + +void h(home,uid,gid,mode) +char *home; +int uid; +int gid; +int mode; +{ + perm("","","",home,S_IFDIR,uid,gid,mode); +} + +void d(home,subdir,uid,gid,mode) +char *home; +char *subdir; +int uid; +int gid; +int mode; +{ + if (chdir(home) == -1) + strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); + perm("",home,"/",subdir,S_IFDIR,uid,gid,mode); +} + +void p(home,fifo,uid,gid,mode) +char *home; +char *fifo; +int uid; +int gid; +int mode; +{ + if (chdir(home) == -1) + strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); + perm("",home,"/",fifo,S_IFIFO,uid,gid,mode); +} + +void c(home,subdir,file,uid,gid,mode) +char *home; +char *subdir; +char *file; +int uid; +int gid; +int mode; +{ + if (chdir(home) == -1) + strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); + if (chdir(subdir) == -1) + strerr_die6sys(111,FATAL,"unable to switch to ",home,"/",subdir,": "); + perm(".../",subdir,"/",file,S_IFREG,uid,gid,mode); +} + +void z(home,file,len,uid,gid,mode) +char *home; +char *file; +int len; +int uid; +int gid; +int mode; +{ + if (chdir(home) == -1) + strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); + perm("",home,"/",file,S_IFREG,uid,gid,mode); +} + +main() +{ + hier(); + _exit(0); +} diff -BbrurN sendmail-8.12.7/libsmdb/open.h sendmail-8.12.7-cdb-testbuild/libsmdb/open.h --- sendmail-8.12.7/libsmdb/open.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/open.h 2003-01-29 01:23:51.000000000 +0800 @@ -0,0 +1,10 @@ +#ifndef OPEN_H +#define OPEN_H + +extern int open_read(char *); +extern int open_excl(char *); +extern int open_append(char *); +extern int open_trunc(char *); +extern int open_write(char *); + +#endif diff -BbrurN sendmail-8.12.7/libsmdb/open_read.c sendmail-8.12.7-cdb-testbuild/libsmdb/open_read.c --- sendmail-8.12.7/libsmdb/open_read.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/open_read.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,6 @@ +#include +#include +#include "open.h" + +int open_read(char *fn) +{ return open(fn,O_RDONLY | O_NDELAY); } diff -BbrurN sendmail-8.12.7/libsmdb/open_trunc.c sendmail-8.12.7-cdb-testbuild/libsmdb/open_trunc.c --- sendmail-8.12.7/libsmdb/open_trunc.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/open_trunc.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,6 @@ +#include +#include +#include "open.h" + +int open_trunc(char *fn) +{ return open(fn,O_WRONLY | O_NDELAY | O_TRUNC | O_CREAT,0644); } diff -BbrurN sendmail-8.12.7/libsmdb/readwrite.h sendmail-8.12.7-cdb-testbuild/libsmdb/readwrite.h --- sendmail-8.12.7/libsmdb/readwrite.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/readwrite.h 2003-01-29 01:23:51.000000000 +0800 @@ -0,0 +1,7 @@ +#ifndef READWRITE_H +#define READWRITE_H + +extern int read(); +extern int write(); + +#endif diff -BbrurN sendmail-8.12.7/libsmdb/scan.h sendmail-8.12.7-cdb-testbuild/libsmdb/scan.h --- sendmail-8.12.7/libsmdb/scan.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/scan.h 2003-01-29 01:23:51.000000000 +0800 @@ -0,0 +1,28 @@ +#ifndef SCAN_H +#define SCAN_H + +extern unsigned int scan_uint(char *,unsigned int *); +extern unsigned int scan_xint(char *,unsigned int *); +extern unsigned int scan_nbbint(char *,unsigned int,unsigned int,unsigned int,unsigned int *); +extern unsigned int scan_ushort(char *,unsigned short *); +extern unsigned int scan_xshort(char *,unsigned short *); +extern unsigned int scan_nbbshort(char *,unsigned int,unsigned int,unsigned int,unsigned short *); +extern unsigned int scan_ulong(char *,unsigned long *); +extern unsigned int scan_xlong(char *,unsigned long *); +extern unsigned int scan_nbblong(char *,unsigned int,unsigned int,unsigned int,unsigned long *); + +extern unsigned int scan_plusminus(char *,int *); +extern unsigned int scan_0x(char *,unsigned int *); + +extern unsigned int scan_whitenskip(char *,unsigned int); +extern unsigned int scan_nonwhitenskip(char *,unsigned int); +extern unsigned int scan_charsetnskip(char *,char *,unsigned int); +extern unsigned int scan_noncharsetnskip(char *,char *,unsigned int); + +extern unsigned int scan_strncmp(char *,char *,unsigned int); +extern unsigned int scan_memcmp(char *,char *,unsigned int); + +extern unsigned int scan_long(char *,long *); +extern unsigned int scan_8long(char *,unsigned long *); + +#endif diff -BbrurN sendmail-8.12.7/libsmdb/scan_ulong.c sendmail-8.12.7-cdb-testbuild/libsmdb/scan_ulong.c --- sendmail-8.12.7/libsmdb/scan_ulong.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/scan_ulong.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,11 @@ +#include "scan.h" + +unsigned int scan_ulong(register char *s,register unsigned long *u) +{ + register unsigned int pos; register unsigned long result; + register unsigned long c; + pos = 0; result = 0; + while ((c = (unsigned long) (unsigned char) (s[pos] - '0')) < 10) + { result = result * 10 + c; ++pos; } + *u = result; return pos; +} diff -BbrurN sendmail-8.12.7/libsmdb/seek_cur.c sendmail-8.12.7-cdb-testbuild/libsmdb/seek_cur.c --- sendmail-8.12.7/libsmdb/seek_cur.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/seek_cur.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,7 @@ +#include +#include "seek.h" + +#define CUR 1 /* sigh */ + +seek_pos seek_cur(int fd) +{ return lseek(fd,(off_t) 0,CUR); } diff -BbrurN sendmail-8.12.7/libsmdb/seek.h sendmail-8.12.7-cdb-testbuild/libsmdb/seek.h --- sendmail-8.12.7/libsmdb/seek.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/seek.h 2003-01-29 01:23:51.000000000 +0800 @@ -0,0 +1,15 @@ +#ifndef SEEK_H +#define SEEK_H + +typedef unsigned long seek_pos; + +extern seek_pos seek_cur(int); + +extern int seek_set(int,seek_pos); +extern int seek_end(int); + +extern int seek_trunc(int,seek_pos); + +#define seek_begin(fd) (seek_set((fd),(seek_pos) 0)) + +#endif diff -BbrurN sendmail-8.12.7/libsmdb/seek_set.c sendmail-8.12.7-cdb-testbuild/libsmdb/seek_set.c --- sendmail-8.12.7/libsmdb/seek_set.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/seek_set.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,7 @@ +#include +#include "seek.h" + +#define SET 0 /* sigh */ + +int seek_set(int fd,seek_pos pos) +{ if (lseek(fd,(off_t) pos,SET) == -1) return -1; return 0; } diff -BbrurN sendmail-8.12.7/libsmdb/strerr_die.c sendmail-8.12.7-cdb-testbuild/libsmdb/strerr_die.c --- sendmail-8.12.7/libsmdb/strerr_die.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/strerr_die.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,31 @@ +#include "buffer.h" +#include "exit.h" +#include "strerr.h" + +void strerr_warn(char *x1,char *x2,char *x3,char *x4,char *x5,char *x6,struct strerr *se) +{ + strerr_sysinit(); + + if (x1) buffer_puts(buffer_2,x1); + if (x2) buffer_puts(buffer_2,x2); + if (x3) buffer_puts(buffer_2,x3); + if (x4) buffer_puts(buffer_2,x4); + if (x5) buffer_puts(buffer_2,x5); + if (x6) buffer_puts(buffer_2,x6); + + while(se) { + if (se->x) buffer_puts(buffer_2,se->x); + if (se->y) buffer_puts(buffer_2,se->y); + if (se->z) buffer_puts(buffer_2,se->z); + se = se->who; + } + + buffer_puts(buffer_2,"\n"); + buffer_flush(buffer_2); +} + +void strerr_die(int e,char *x1,char *x2,char *x3,char *x4,char *x5,char *x6,struct strerr *se) +{ + strerr_warn(x1,x2,x3,x4,x5,x6,se); + _exit(e); +} diff -BbrurN sendmail-8.12.7/libsmdb/strerr.h sendmail-8.12.7-cdb-testbuild/libsmdb/strerr.h --- sendmail-8.12.7/libsmdb/strerr.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/strerr.h 2003-01-29 01:23:51.000000000 +0800 @@ -0,0 +1,78 @@ +#ifndef STRERR_H +#define STRERR_H + +struct strerr { + struct strerr *who; + char *x; + char *y; + char *z; +} ; + +extern struct strerr strerr_sys; +extern void strerr_sysinit(void); + +extern char *strerr(struct strerr *); +extern void strerr_warn(char *,char *,char *,char *,char *,char *,struct strerr *); +extern void strerr_die(int,char *,char *,char *,char *,char *,char *,struct strerr *); + +#define STRERR(r,se,a) \ +{ se.who = 0; se.x = a; se.y = 0; se.z = 0; return r; } + +#define STRERR_SYS(r,se,a) \ +{ se.who = &strerr_sys; se.x = a; se.y = 0; se.z = 0; return r; } +#define STRERR_SYS3(r,se,a,b,c) \ +{ se.who = &strerr_sys; se.x = a; se.y = b; se.z = c; return r; } + +#define strerr_warn6(x1,x2,x3,x4,x5,x6,se) \ +strerr_warn((x1),(x2),(x3),(x4),(x5),(x6),(se)) +#define strerr_warn5(x1,x2,x3,x4,x5,se) \ +strerr_warn((x1),(x2),(x3),(x4),(x5),0,(se)) +#define strerr_warn4(x1,x2,x3,x4,se) \ +strerr_warn((x1),(x2),(x3),(x4),0,0,(se)) +#define strerr_warn3(x1,x2,x3,se) \ +strerr_warn((x1),(x2),(x3),0,0,0,(se)) +#define strerr_warn2(x1,x2,se) \ +strerr_warn((x1),(x2),0,0,0,0,(se)) +#define strerr_warn1(x1,se) \ +strerr_warn((x1),0,0,0,0,0,(se)) + +#define strerr_die6(e,x1,x2,x3,x4,x5,x6,se) \ +strerr_die((e),(x1),(x2),(x3),(x4),(x5),(x6),(se)) +#define strerr_die5(e,x1,x2,x3,x4,x5,se) \ +strerr_die((e),(x1),(x2),(x3),(x4),(x5),0,(se)) +#define strerr_die4(e,x1,x2,x3,x4,se) \ +strerr_die((e),(x1),(x2),(x3),(x4),0,0,(se)) +#define strerr_die3(e,x1,x2,x3,se) \ +strerr_die((e),(x1),(x2),(x3),0,0,0,(se)) +#define strerr_die2(e,x1,x2,se) \ +strerr_die((e),(x1),(x2),0,0,0,0,(se)) +#define strerr_die1(e,x1,se) \ +strerr_die((e),(x1),0,0,0,0,0,(se)) + +#define strerr_die6sys(e,x1,x2,x3,x4,x5,x6) \ +strerr_die((e),(x1),(x2),(x3),(x4),(x5),(x6),&strerr_sys) +#define strerr_die5sys(e,x1,x2,x3,x4,x5) \ +strerr_die((e),(x1),(x2),(x3),(x4),(x5),0,&strerr_sys) +#define strerr_die4sys(e,x1,x2,x3,x4) \ +strerr_die((e),(x1),(x2),(x3),(x4),0,0,&strerr_sys) +#define strerr_die3sys(e,x1,x2,x3) \ +strerr_die((e),(x1),(x2),(x3),0,0,0,&strerr_sys) +#define strerr_die2sys(e,x1,x2) \ +strerr_die((e),(x1),(x2),0,0,0,0,&strerr_sys) +#define strerr_die1sys(e,x1) \ +strerr_die((e),(x1),0,0,0,0,0,&strerr_sys) + +#define strerr_die6x(e,x1,x2,x3,x4,x5,x6) \ +strerr_die((e),(x1),(x2),(x3),(x4),(x5),(x6),0) +#define strerr_die5x(e,x1,x2,x3,x4,x5) \ +strerr_die((e),(x1),(x2),(x3),(x4),(x5),0,0) +#define strerr_die4x(e,x1,x2,x3,x4) \ +strerr_die((e),(x1),(x2),(x3),(x4),0,0,0) +#define strerr_die3x(e,x1,x2,x3) \ +strerr_die((e),(x1),(x2),(x3),0,0,0,0) +#define strerr_die2x(e,x1,x2) \ +strerr_die((e),(x1),(x2),0,0,0,0,0) +#define strerr_die1x(e,x1) \ +strerr_die((e),(x1),0,0,0,0,0,0) + +#endif diff -BbrurN sendmail-8.12.7/libsmdb/strerr_sys.c sendmail-8.12.7-cdb-testbuild/libsmdb/strerr_sys.c --- sendmail-8.12.7/libsmdb/strerr_sys.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/strerr_sys.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,12 @@ +#include "error.h" +#include "strerr.h" + +struct strerr strerr_sys; + +void strerr_sysinit(void) +{ + strerr_sys.who = 0; + strerr_sys.x = error_str(errno); + strerr_sys.y = ""; + strerr_sys.z = ""; +} diff -BbrurN sendmail-8.12.7/libsmdb/str.h sendmail-8.12.7-cdb-testbuild/libsmdb/str.h --- sendmail-8.12.7/libsmdb/str.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/str.h 2003-01-29 01:23:51.000000000 +0800 @@ -0,0 +1,14 @@ +#ifndef STR_H +#define STR_H + +extern unsigned int str_copy(char *,char *); +extern int str_diff(char *,char *); +extern int str_diffn(char *,char *,unsigned int); +extern unsigned int str_len(char *); +extern unsigned int str_chr(char *,int); +extern unsigned int str_rchr(char *,int); +extern int str_start(char *,char *); + +#define str_equal(s,t) (!str_diff((s),(t))) + +#endif diff -BbrurN sendmail-8.12.7/libsmdb/str_len.c sendmail-8.12.7-cdb-testbuild/libsmdb/str_len.c --- sendmail-8.12.7/libsmdb/str_len.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/str_len.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,14 @@ +#include "str.h" + +unsigned int str_len(char *s) +{ + register char *t; + + t = s; + for (;;) { + if (!*t) return t - s; ++t; + if (!*t) return t - s; ++t; + if (!*t) return t - s; ++t; + if (!*t) return t - s; ++t; + } +} diff -BbrurN sendmail-8.12.7/libsmdb/testzero.c sendmail-8.12.7-cdb-testbuild/libsmdb/testzero.c --- sendmail-8.12.7/libsmdb/testzero.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/testzero.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,35 @@ +#include "uint32.h" +#include "scan.h" +#include "strerr.h" +#include "cdb_make.h" + +#define FATAL "testzero: fatal: " + +void die_write(void) +{ + strerr_die2sys(111,FATAL,"unable to write: "); +} + +static char key[4]; +static char data[65536]; +struct cdb_make c; + +main(int argc,char **argv) +{ + int fd; + unsigned long loop; + + if (!*argv) _exit(0); + if (!*++argv) _exit(0); + scan_ulong(*argv,&loop); + + if (cdb_make_start(&c,1) == -1) die_write(); + + while (loop) { + uint32_pack(key,--loop); + if (cdb_make_add(&c,key,4,data,sizeof data) == -1) die_write(); + } + + if (cdb_make_finish(&c) == -1) die_write(); + _exit(0); +} diff -BbrurN sendmail-8.12.7/libsmdb/trycpp.c sendmail-8.12.7-cdb-testbuild/libsmdb/trycpp.c --- sendmail-8.12.7/libsmdb/trycpp.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/trycpp.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,7 @@ +main() +{ +#ifdef NeXT + printf("nextstep\n"); exit(0); +#endif + printf("unknown\n"); exit(0); +} diff -BbrurN sendmail-8.12.7/libsmdb/tryulong32.c sendmail-8.12.7-cdb-testbuild/libsmdb/tryulong32.c --- sendmail-8.12.7/libsmdb/tryulong32.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/tryulong32.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,11 @@ +void main() +{ + unsigned long u; + u = 1; + u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; + u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; + u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; + u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; + if (!u) _exit(0); + _exit(1); +} diff -BbrurN sendmail-8.12.7/libsmdb/uint32.h sendmail-8.12.7-cdb-testbuild/libsmdb/uint32.h --- sendmail-8.12.7/libsmdb/uint32.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/uint32.h 2003-01-29 01:23:51.000000000 +0800 @@ -0,0 +1,11 @@ +#ifndef UINT32_H +#define UINT32_H + +typedef unsigned long uint32; + +extern void uint32_pack(char *,uint32); +extern void uint32_pack_big(char *,uint32); +extern void uint32_unpack(char *,uint32 *); +extern void uint32_unpack_big(char *,uint32 *); + +#endif diff -BbrurN sendmail-8.12.7/libsmdb/uint32_pack.c sendmail-8.12.7-cdb-testbuild/libsmdb/uint32_pack.c --- sendmail-8.12.7/libsmdb/uint32_pack.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/uint32_pack.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,21 @@ +#include "uint32.h" + +void uint32_pack(char s[4],uint32 u) +{ + s[0] = u & 255; + u >>= 8; + s[1] = u & 255; + u >>= 8; + s[2] = u & 255; + s[3] = u >> 8; +} + +void uint32_pack_big(char s[4],uint32 u) +{ + s[3] = u & 255; + u >>= 8; + s[2] = u & 255; + u >>= 8; + s[1] = u & 255; + s[0] = u >> 8; +} diff -BbrurN sendmail-8.12.7/libsmdb/uint32_unpack.c sendmail-8.12.7-cdb-testbuild/libsmdb/uint32_unpack.c --- sendmail-8.12.7/libsmdb/uint32_unpack.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/uint32_unpack.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,31 @@ +#include "uint32.h" + +void uint32_unpack(char s[4],uint32 *u) +{ + uint32 result; + + result = (unsigned char) s[3]; + result <<= 8; + result += (unsigned char) s[2]; + result <<= 8; + result += (unsigned char) s[1]; + result <<= 8; + result += (unsigned char) s[0]; + + *u = result; +} + +void uint32_unpack_big(char s[4],uint32 *u) +{ + uint32 result; + + result = (unsigned char) s[0]; + result <<= 8; + result += (unsigned char) s[1]; + result <<= 8; + result += (unsigned char) s[2]; + result <<= 8; + result += (unsigned char) s[3]; + + *u = result; +} diff -BbrurN sendmail-8.12.7/libsmdb/x86cpuid.c sendmail-8.12.7-cdb-testbuild/libsmdb/x86cpuid.c --- sendmail-8.12.7/libsmdb/x86cpuid.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/libsmdb/x86cpuid.c 2003-01-29 01:23:56.000000000 +0800 @@ -0,0 +1,38 @@ +#include + +void nope() +{ + exit(1); +} + +main() +{ + unsigned long x[4]; + unsigned long y[4]; + int i; + int j; + char c; + + signal(SIGILL,nope); + + x[0] = 0; + x[1] = 0; + x[2] = 0; + x[3] = 0; + + asm volatile(".byte 15;.byte 162" : "=a"(x[0]),"=b"(x[1]),"=c"(x[3]),"=d"(x[2]) : "0"(0) ); + if (!x[0]) return 0; + asm volatile(".byte 15;.byte 162" : "=a"(y[0]),"=b"(y[1]),"=c"(y[2]),"=d"(y[3]) : "0"(1) ); + + for (i = 1;i < 4;++i) + for (j = 0;j < 4;++j) { + c = x[i] >> (8 * j); + if (c < 32) c = 32; + if (c > 126) c = 126; + putchar(c); + } + + printf("-%08x-%08x\n",y[0],y[3]); + + return 0; +} diff -BbrurN sendmail-8.12.7/makemap/alloc.c sendmail-8.12.7-cdb-testbuild/makemap/alloc.c --- sendmail-8.12.7/makemap/alloc.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/alloc.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,32 @@ +#include "alloc.h" +#include "error.h" +extern char *malloc(); +extern void free(); + +#define ALIGNMENT 16 /* XXX: assuming that this alignment is enough */ +#define SPACE 4096 /* must be multiple of ALIGNMENT */ + +typedef union { char irrelevant[ALIGNMENT]; double d; } aligned; +static aligned realspace[SPACE / ALIGNMENT]; +#define space ((char *) realspace) +static unsigned int avail = SPACE; /* multiple of ALIGNMENT; 0<=avail<=SPACE */ + +/*@null@*//*@out@*/char *alloc(n) +unsigned int n; +{ + char *x; + n = ALIGNMENT + n - (n & (ALIGNMENT - 1)); /* XXX: could overflow */ + if (n <= avail) { avail -= n; return space + avail; } + x = malloc(n); + if (!x) errno = error_nomem; + return x; +} + +void alloc_free(x) +char *x; +{ + if (x >= space) + if (x < space + SPACE) + return; /* XXX: assuming that pointers are flat */ + free(x); +} diff -BbrurN sendmail-8.12.7/makemap/alloc.h sendmail-8.12.7-cdb-testbuild/makemap/alloc.h --- sendmail-8.12.7/makemap/alloc.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/alloc.h 2003-01-29 01:23:17.000000000 +0800 @@ -0,0 +1,8 @@ +#ifndef ALLOC_H +#define ALLOC_H + +extern /*@null@*//*@out@*/char *alloc(); +extern void alloc_free(); +extern int alloc_re(); + +#endif diff -BbrurN sendmail-8.12.7/makemap/auto_home.c sendmail-8.12.7-cdb-testbuild/makemap/auto_home.c --- sendmail-8.12.7/makemap/auto_home.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/auto_home.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,3 @@ +char auto_home[] = "\ +\057\165\163\162\057\154\157\143\141\154\ +"; diff -BbrurN sendmail-8.12.7/makemap/auto_home.h sendmail-8.12.7-cdb-testbuild/makemap/auto_home.h --- sendmail-8.12.7/makemap/auto_home.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/auto_home.h 2003-01-29 01:23:17.000000000 +0800 @@ -0,0 +1,6 @@ +#ifndef AUTO_HOME_H +#define AUTO_HOME_H + +extern char auto_home[]; + +#endif diff -BbrurN sendmail-8.12.7/makemap/auto-str.c sendmail-8.12.7-cdb-testbuild/makemap/auto-str.c --- sendmail-8.12.7/makemap/auto-str.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/auto-str.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,44 @@ +#include "buffer.h" +#include "readwrite.h" +#include "exit.h" + +char buf1[256]; +buffer ss1 = BUFFER_INIT(write,1,buf1,sizeof(buf1)); + +void puts(s) +char *s; +{ + if (buffer_puts(&ss1,s) == -1) _exit(111); +} + +main(argc,argv) +int argc; +char **argv; +{ + char *name; + char *value; + unsigned char ch; + char octal[4]; + + name = argv[1]; + if (!name) _exit(100); + value = argv[2]; + if (!value) _exit(100); + + puts("char "); + puts(name); + puts("[] = \"\\\n"); + + while (ch = *value++) { + puts("\\"); + octal[3] = 0; + octal[2] = '0' + (ch & 7); ch >>= 3; + octal[1] = '0' + (ch & 7); ch >>= 3; + octal[0] = '0' + (ch & 7); + puts(octal); + } + + puts("\\\n\";\n"); + if (buffer_flush(&ss1) == -1) _exit(111); + _exit(0); +} diff -BbrurN sendmail-8.12.7/makemap/buffer_0.c sendmail-8.12.7-cdb-testbuild/makemap/buffer_0.c --- sendmail-8.12.7/makemap/buffer_0.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/buffer_0.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,12 @@ +#include "readwrite.h" +#include "buffer.h" + +int buffer_0_read(fd,buf,len) int fd; char *buf; int len; +{ + if (buffer_flush(buffer_1) == -1) return -1; + return read(fd,buf,len); +} + +char buffer_0_space[BUFFER_INSIZE]; +static buffer it = BUFFER_INIT(buffer_0_read,0,buffer_0_space,sizeof buffer_0_space); +buffer *buffer_0 = ⁢ diff -BbrurN sendmail-8.12.7/makemap/buffer_1.c sendmail-8.12.7-cdb-testbuild/makemap/buffer_1.c --- sendmail-8.12.7/makemap/buffer_1.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/buffer_1.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,6 @@ +#include "readwrite.h" +#include "buffer.h" + +char buffer_1_space[BUFFER_OUTSIZE]; +static buffer it = BUFFER_INIT(write,1,buffer_1_space,sizeof buffer_1_space); +buffer *buffer_1 = ⁢ diff -BbrurN sendmail-8.12.7/makemap/buffer_1s.c sendmail-8.12.7-cdb-testbuild/makemap/buffer_1s.c --- sendmail-8.12.7/makemap/buffer_1s.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/buffer_1s.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,6 @@ +#include "readwrite.h" +#include "buffer.h" + +char buffer_1small_space[256]; +static buffer it = BUFFER_INIT(write,1,buffer_1small_space,sizeof buffer_1small_space); +buffer *buffer_1small = ⁢ diff -BbrurN sendmail-8.12.7/makemap/buffer_2.c sendmail-8.12.7-cdb-testbuild/makemap/buffer_2.c --- sendmail-8.12.7/makemap/buffer_2.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/buffer_2.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,6 @@ +#include "readwrite.h" +#include "buffer.h" + +char buffer_2_space[256]; +static buffer it = BUFFER_INIT(write,2,buffer_2_space,sizeof buffer_2_space); +buffer *buffer_2 = ⁢ diff -BbrurN sendmail-8.12.7/makemap/buffer.c sendmail-8.12.7-cdb-testbuild/makemap/buffer.c --- sendmail-8.12.7/makemap/buffer.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/buffer.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,10 @@ +#include "buffer.h" + +void buffer_init(buffer *s,int (*op)(),int fd,char *buf,unsigned int len) +{ + s->x = buf; + s->fd = fd; + s->op = op; + s->p = 0; + s->n = len; +} diff -BbrurN sendmail-8.12.7/makemap/buffer_copy.c sendmail-8.12.7-cdb-testbuild/makemap/buffer_copy.c --- sendmail-8.12.7/makemap/buffer_copy.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/buffer_copy.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,16 @@ +#include "buffer.h" + +int buffer_copy(buffer *bout,buffer *bin) +{ + int n; + char *x; + + for (;;) { + n = buffer_feed(bin); + if (n < 0) return -2; + if (!n) return 0; + x = buffer_PEEK(bin); + if (buffer_put(bout,x,n) == -1) return -3; + buffer_SEEK(bin,n); + } +} diff -BbrurN sendmail-8.12.7/makemap/buffer_get.c sendmail-8.12.7-cdb-testbuild/makemap/buffer_get.c --- sendmail-8.12.7/makemap/buffer_get.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/buffer_get.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,67 @@ +#include "buffer.h" +#include "byte.h" +#include "error.h" + +static int oneread(int (*op)(),int fd,char *buf,unsigned int len) +{ + int r; + + for (;;) { + r = op(fd,buf,len); + if (r == -1) if (errno == error_intr) continue; + return r; + } +} + +static int getthis(buffer *s,char *buf,unsigned int len) +{ + if (len > s->p) len = s->p; + s->p -= len; + byte_copy(buf,len,s->x + s->n); + s->n += len; + return len; +} + +int buffer_feed(buffer *s) +{ + int r; + + if (s->p) return s->p; + r = oneread(s->op,s->fd,s->x,s->n); + if (r <= 0) return r; + s->p = r; + s->n -= r; + if (s->n > 0) byte_copyr(s->x + s->n,r,s->x); + return r; +} + +int buffer_bget(buffer *s,char *buf,unsigned int len) +{ + int r; + + if (s->p > 0) return getthis(s,buf,len); + if (s->n <= len) return oneread(s->op,s->fd,buf,s->n); + r = buffer_feed(s); if (r <= 0) return r; + return getthis(s,buf,len); +} + +int buffer_get(buffer *s,char *buf,unsigned int len) +{ + int r; + + if (s->p > 0) return getthis(s,buf,len); + if (s->n <= len) return oneread(s->op,s->fd,buf,len); + r = buffer_feed(s); if (r <= 0) return r; + return getthis(s,buf,len); +} + +char *buffer_peek(buffer *s) +{ + return s->x + s->n; +} + +void buffer_seek(buffer *s,unsigned int len) +{ + s->n += len; + s->p -= len; +} diff -BbrurN sendmail-8.12.7/makemap/buffer.h sendmail-8.12.7-cdb-testbuild/makemap/buffer.h --- sendmail-8.12.7/makemap/buffer.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/buffer.h 2003-01-29 01:23:17.000000000 +0800 @@ -0,0 +1,56 @@ +#ifndef BUFFER_H +#define BUFFER_H + +typedef struct buffer { + char *x; + unsigned int p; + unsigned int n; + int fd; + int (*op)(); +} buffer; + +#define BUFFER_INIT(op,fd,buf,len) { (buf), 0, (len), (fd), (op) } +#define BUFFER_INSIZE 8192 +#define BUFFER_OUTSIZE 8192 + +extern void buffer_init(buffer *,int (*)(),int,char *,unsigned int); + +extern int buffer_flush(buffer *); +extern int buffer_put(buffer *,char *,unsigned int); +extern int buffer_putalign(buffer *,char *,unsigned int); +extern int buffer_putflush(buffer *,char *,unsigned int); +extern int buffer_puts(buffer *,char *); +extern int buffer_putsalign(buffer *,char *); +extern int buffer_putsflush(buffer *,char *); + +#define buffer_PUTC(s,c) \ + ( ((s)->n != (s)->p) \ + ? ( (s)->x[(s)->p++] = (c), 0 ) \ + : buffer_put((s),&(c),1) \ + ) + +extern int buffer_get(buffer *,char *,unsigned int); +extern int buffer_bget(buffer *,char *,unsigned int); +extern int buffer_feed(buffer *); + +extern char *buffer_peek(buffer *); +extern void buffer_seek(buffer *,unsigned int); + +#define buffer_PEEK(s) ( (s)->x + (s)->n ) +#define buffer_SEEK(s,len) ( ( (s)->p -= (len) ) , ( (s)->n += (len) ) ) + +#define buffer_GETC(s,c) \ + ( ((s)->p > 0) \ + ? ( *(c) = (s)->x[(s)->n], buffer_SEEK((s),1), 1 ) \ + : buffer_get((s),(c),1) \ + ) + +extern int buffer_copy(buffer *,buffer *); + +extern buffer *buffer_0; +extern buffer *buffer_0small; +extern buffer *buffer_1; +extern buffer *buffer_1small; +extern buffer *buffer_2; + +#endif diff -BbrurN sendmail-8.12.7/makemap/buffer_put.c sendmail-8.12.7-cdb-testbuild/makemap/buffer_put.c --- sendmail-8.12.7/makemap/buffer_put.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/buffer_put.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,88 @@ +#include "buffer.h" +#include "str.h" +#include "byte.h" +#include "error.h" + +static int allwrite(int (*op)(),int fd,char *buf,unsigned int len) +{ + int w; + + while (len) { + w = op(fd,buf,len); + if (w == -1) { + if (errno == error_intr) continue; + return -1; /* note that some data may have been written */ + } + if (w == 0) ; /* luser's fault */ + buf += w; + len -= w; + } + return 0; +} + +int buffer_flush(buffer *s) +{ + int p; + + p = s->p; + if (!p) return 0; + s->p = 0; + return allwrite(s->op,s->fd,s->x,p); +} + +int buffer_putalign(buffer *s,char *buf,unsigned int len) +{ + unsigned int n; + + while (len > (n = s->n - s->p)) { + byte_copy(s->x + s->p,n,buf); s->p += n; buf += n; len -= n; + if (buffer_flush(s) == -1) return -1; + } + /* now len <= s->n - s->p */ + byte_copy(s->x + s->p,len,buf); + s->p += len; + return 0; +} + +int buffer_put(buffer *s,char *buf,unsigned int len) +{ + unsigned int n; + + n = s->n; + if (len > n - s->p) { + if (buffer_flush(s) == -1) return -1; + /* now s->p == 0 */ + if (n < BUFFER_OUTSIZE) n = BUFFER_OUTSIZE; + while (len > s->n) { + if (n > len) n = len; + if (allwrite(s->op,s->fd,buf,n) == -1) return -1; + buf += n; + len -= n; + } + } + /* now len <= s->n - s->p */ + byte_copy(s->x + s->p,len,buf); + s->p += len; + return 0; +} + +int buffer_putflush(buffer *s,char *buf,unsigned int len) +{ + if (buffer_flush(s) == -1) return -1; + return allwrite(s->op,s->fd,buf,len); +} + +int buffer_putsalign(buffer *s,char *buf) +{ + return buffer_putalign(s,buf,str_len(buf)); +} + +int buffer_puts(buffer *s,char *buf) +{ + return buffer_put(s,buf,str_len(buf)); +} + +int buffer_putsflush(buffer *s,char *buf) +{ + return buffer_putflush(s,buf,str_len(buf)); +} diff -BbrurN sendmail-8.12.7/makemap/byte_copy.c sendmail-8.12.7-cdb-testbuild/makemap/byte_copy.c --- sendmail-8.12.7/makemap/byte_copy.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/byte_copy.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,14 @@ +#include "byte.h" + +void byte_copy(to,n,from) +register char *to; +register unsigned int n; +register char *from; +{ + for (;;) { + if (!n) return; *to++ = *from++; --n; + if (!n) return; *to++ = *from++; --n; + if (!n) return; *to++ = *from++; --n; + if (!n) return; *to++ = *from++; --n; + } +} diff -BbrurN sendmail-8.12.7/makemap/byte_cr.c sendmail-8.12.7-cdb-testbuild/makemap/byte_cr.c --- sendmail-8.12.7/makemap/byte_cr.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/byte_cr.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,16 @@ +#include "byte.h" + +void byte_copyr(to,n,from) +register char *to; +register unsigned int n; +register char *from; +{ + to += n; + from += n; + for (;;) { + if (!n) return; *--to = *--from; --n; + if (!n) return; *--to = *--from; --n; + if (!n) return; *--to = *--from; --n; + if (!n) return; *--to = *--from; --n; + } +} diff -BbrurN sendmail-8.12.7/makemap/byte_diff.c sendmail-8.12.7-cdb-testbuild/makemap/byte_diff.c --- sendmail-8.12.7/makemap/byte_diff.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/byte_diff.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,16 @@ +#include "byte.h" + +int byte_diff(s,n,t) +register char *s; +register unsigned int n; +register char *t; +{ + for (;;) { + if (!n) return 0; if (*s != *t) break; ++s; ++t; --n; + if (!n) return 0; if (*s != *t) break; ++s; ++t; --n; + if (!n) return 0; if (*s != *t) break; ++s; ++t; --n; + if (!n) return 0; if (*s != *t) break; ++s; ++t; --n; + } + return ((int)(unsigned int)(unsigned char) *s) + - ((int)(unsigned int)(unsigned char) *t); +} diff -BbrurN sendmail-8.12.7/makemap/byte.h sendmail-8.12.7-cdb-testbuild/makemap/byte.h --- sendmail-8.12.7/makemap/byte.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/byte.h 2003-01-29 01:23:17.000000000 +0800 @@ -0,0 +1,13 @@ +#ifndef BYTE_H +#define BYTE_H + +extern unsigned int byte_chr(); +extern unsigned int byte_rchr(); +extern void byte_copy(); +extern void byte_copyr(); +extern int byte_diff(); +extern void byte_zero(); + +#define byte_equal(s,n,t) (!byte_diff((s),(n),(t))) + +#endif diff -BbrurN sendmail-8.12.7/makemap/cdb.c sendmail-8.12.7-cdb-testbuild/makemap/cdb.c --- sendmail-8.12.7/makemap/cdb.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/cdb.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,136 @@ +/* Public domain. */ + +#include +#include +#include +#include "readwrite.h" +#include "error.h" +#include "seek.h" +#include "byte.h" +#include "cdb.h" + +void cdb_free(struct cdb *c) +{ + if (c->map) { + munmap(c->map,c->size); + c->map = 0; + } +} + +void cdb_findstart(struct cdb *c) +{ + c->loop = 0; +} + +void cdb_init(struct cdb *c,int fd) +{ + struct stat st; + char *x; + + cdb_free(c); + cdb_findstart(c); + c->fd = fd; + + if (fstat(fd,&st) == 0) + if (st.st_size <= 0xffffffff) { + x = mmap(0,st.st_size,PROT_READ,MAP_SHARED,fd,0); + if (x + 1) { + c->size = st.st_size; + c->map = x; + } + } +} + +int cdb_read(struct cdb *c,char *buf,unsigned int len,uint32 pos) +{ + if (c->map) { + if ((pos > c->size) || (c->size - pos < len)) goto FORMAT; + byte_copy(buf,len,c->map + pos); + } + else { + if (seek_set(c->fd,pos) == -1) return -1; + while (len > 0) { + int r; + do + r = read(c->fd,buf,len); + while ((r == -1) && (errno == error_intr)); + if (r == -1) return -1; + if (r == 0) goto FORMAT; + buf += r; + len -= r; + } + } + return 0; + + FORMAT: + errno = error_proto; + return -1; +} + +static int match(struct cdb *c,char *key,unsigned int len,uint32 pos) +{ + char buf[32]; + int n; + + while (len > 0) { + n = sizeof buf; + if (n > len) n = len; + if (cdb_read(c,buf,n,pos) == -1) return -1; + if (byte_diff(buf,n,key)) return 0; + pos += n; + key += n; + len -= n; + } + return 1; +} + +int cdb_findnext(struct cdb *c,char *key,unsigned int len) +{ + char buf[8]; + uint32 pos; + uint32 u; + + if (!c->loop) { + u = cdb_hash(key,len); + if (cdb_read(c,buf,8,(u << 3) & 2047) == -1) return -1; + uint32_unpack(buf + 4,&c->hslots); + if (!c->hslots) return 0; + uint32_unpack(buf,&c->hpos); + c->khash = u; + u >>= 8; + u %= c->hslots; + u <<= 3; + c->kpos = c->hpos + u; + } + + while (c->loop < c->hslots) { + if (cdb_read(c,buf,8,c->kpos) == -1) return -1; + uint32_unpack(buf + 4,&pos); + if (!pos) return 0; + c->loop += 1; + c->kpos += 8; + if (c->kpos == c->hpos + (c->hslots << 3)) c->kpos = c->hpos; + uint32_unpack(buf,&u); + if (u == c->khash) { + if (cdb_read(c,buf,8,pos) == -1) return -1; + uint32_unpack(buf,&u); + if (u == len) + switch(match(c,key,len,pos + 8)) { + case -1: + return -1; + case 1: + uint32_unpack(buf + 4,&c->dlen); + c->dpos = pos + 8 + len; + return 1; + } + } + } + + return 0; +} + +int cdb_find(struct cdb *c,char *key,unsigned int len) +{ + cdb_findstart(c); + return cdb_findnext(c,key,len); +} diff -BbrurN sendmail-8.12.7/makemap/cdbdump.c sendmail-8.12.7-cdb-testbuild/makemap/cdbdump.c --- sendmail-8.12.7/makemap/cdbdump.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/cdbdump.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,83 @@ +#include "uint32.h" +#include "fmt.h" +#include "buffer.h" +#include "strerr.h" + +#define FATAL "cdbdump: fatal: " + +void die_write(void) +{ + strerr_die2sys(111,FATAL,"unable to write output: "); +} +void put(char *buf,unsigned int len) +{ + if (buffer_put(buffer_1,buf,len) == -1) die_write(); +} +void putflush(void) +{ + if (buffer_flush(buffer_1) == -1) die_write(); +} + +uint32 pos = 0; + +void get(char *buf,unsigned int len) +{ + int r; + while (len > 0) { + r = buffer_get(buffer_0,buf,len); + if (r == -1) + strerr_die2sys(111,FATAL,"unable to read input: "); + if (r == 0) + strerr_die2x(111,FATAL,"unable to read input: truncated file"); + pos += r; + buf += r; + len -= r; + } +} + +char buf[512]; + +void copy(uint32 len) +{ + unsigned int x; + + while (len) { + x = sizeof buf; + if (len < x) x = len; + get(buf,x); + put(buf,x); + len -= x; + } +} + +void getnum(uint32 *num) +{ + get(buf,4); + uint32_unpack(buf,num); +} + +char strnum[FMT_ULONG]; + +main() +{ + uint32 eod; + uint32 klen; + uint32 dlen; + + getnum(&eod); + while (pos < 2048) getnum(&dlen); + + while (pos < eod) { + getnum(&klen); + getnum(&dlen); + put("+",1); put(strnum,fmt_ulong(strnum,klen)); + put(",",1); put(strnum,fmt_ulong(strnum,dlen)); + put(":",1); copy(klen); + put("->",2); copy(dlen); + put("\n",1); + } + + put("\n",1); + putflush(); + _exit(0); +} diff -BbrurN sendmail-8.12.7/makemap/cdbget.c sendmail-8.12.7-cdb-testbuild/makemap/cdbget.c --- sendmail-8.12.7/makemap/cdbget.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/cdbget.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,67 @@ +#include "exit.h" +#include "scan.h" +#include "str.h" +#include "buffer.h" +#include "strerr.h" +#include "cdb.h" + +#define FATAL "cdbget: fatal: " + +void die_read(void) +{ + strerr_die2sys(111,FATAL,"unable to read input: "); +} +void die_write(void) +{ + strerr_die2sys(111,FATAL,"unable to write output: "); +} +void die_usage(void) +{ + strerr_die1x(111,"cdbget: usage: cdbget key [skip]"); +} + +static struct cdb c; +char buf[1024]; + +main(int argc,char **argv) +{ + char *key; + int r; + uint32 pos; + uint32 len; + unsigned long u = 0; + + if (!*argv) die_usage(); + + if (!*++argv) die_usage(); + key = *argv; + + if (*++argv) { + scan_ulong(*argv,&u); + } + + cdb_init(&c,0); + cdb_findstart(&c); + + for (;;) { + r = cdb_findnext(&c,key,str_len(key)); + if (r == -1) die_read(); + if (!r) _exit(100); + if (!u) break; + --u; + } + + pos = cdb_datapos(&c); + len = cdb_datalen(&c); + + while (len > 0) { + r = sizeof buf; + if (r > len) r = len; + if (cdb_read(&c,buf,r,pos) == -1) die_read(); + if (buffer_put(buffer_1small,buf,r) == -1) die_write(); + pos += r; + len -= r; + } + if (buffer_flush(buffer_1small) == -1) die_write(); + _exit(0); +} diff -BbrurN sendmail-8.12.7/makemap/cdb.h sendmail-8.12.7-cdb-testbuild/makemap/cdb.h --- sendmail-8.12.7/makemap/cdb.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/cdb.h 2003-01-29 01:23:17.000000000 +0800 @@ -0,0 +1,37 @@ +/* Public domain. */ + +#ifndef CDB_H +#define CDB_H + +#include "uint32.h" + +#define CDB_HASHSTART 5381 +extern uint32 cdb_hashadd(uint32,unsigned char); +extern uint32 cdb_hash(char *,unsigned int); + +struct cdb { + char *map; /* 0 if no map is available */ + int fd; + uint32 size; /* initialized if map is nonzero */ + uint32 loop; /* number of hash slots searched under this key */ + uint32 khash; /* initialized if loop is nonzero */ + uint32 kpos; /* initialized if loop is nonzero */ + uint32 hpos; /* initialized if loop is nonzero */ + uint32 hslots; /* initialized if loop is nonzero */ + uint32 dpos; /* initialized if cdb_findnext() returns 1 */ + uint32 dlen; /* initialized if cdb_findnext() returns 1 */ +} ; + +extern void cdb_free(struct cdb *); +extern void cdb_init(struct cdb *,int fd); + +extern int cdb_read(struct cdb *,char *,unsigned int,uint32); + +extern void cdb_findstart(struct cdb *); +extern int cdb_findnext(struct cdb *,char *,unsigned int); +extern int cdb_find(struct cdb *,char *,unsigned int); + +#define cdb_datapos(c) ((c)->dpos) +#define cdb_datalen(c) ((c)->dlen) + +#endif diff -BbrurN sendmail-8.12.7/makemap/cdb_hash.c sendmail-8.12.7-cdb-testbuild/makemap/cdb_hash.c --- sendmail-8.12.7/makemap/cdb_hash.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/cdb_hash.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,21 @@ +/* Public domain. */ + +#include "cdb.h" + +uint32 cdb_hashadd(uint32 h,unsigned char c) +{ + h += (h << 5); + return h ^ c; +} + +uint32 cdb_hash(char *buf,unsigned int len) +{ + uint32 h; + + h = CDB_HASHSTART; + while (len) { + h = cdb_hashadd(h,*buf++); + --len; + } + return h; +} diff -BbrurN sendmail-8.12.7/makemap/cdb_make.c sendmail-8.12.7-cdb-testbuild/makemap/cdb_make.c --- sendmail-8.12.7/makemap/cdb_make.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/cdb_make.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,153 @@ +/* Public domain. */ + +#include "readwrite.h" +#include "seek.h" +#include "error.h" +#include "alloc.h" +#include "cdb.h" +#include "cdb_make.h" + +int cdb_make_start(struct cdb_make *c,int fd) +{ + c->head = 0; + c->split = 0; + c->hash = 0; + c->numentries = 0; + c->fd = fd; + c->pos = sizeof c->final; + buffer_init(&c->b,write,fd,c->bspace,sizeof c->bspace); + return seek_set(fd,c->pos); +} + +static int posplus(struct cdb_make *c,uint32 len) +{ + uint32 newpos = c->pos + len; + if (newpos < len) { errno = error_nomem; return -1; } + c->pos = newpos; + return 0; +} + +int cdb_make_addend(struct cdb_make *c,unsigned int keylen,unsigned int datalen,uint32 h) +{ + struct cdb_hplist *head; + + head = c->head; + if (!head || (head->num >= CDB_HPLIST)) { + head = (struct cdb_hplist *) alloc(sizeof(struct cdb_hplist)); + if (!head) return -1; + head->num = 0; + head->next = c->head; + c->head = head; + } + head->hp[head->num].h = h; + head->hp[head->num].p = c->pos; + ++head->num; + ++c->numentries; + if (posplus(c,8) == -1) return -1; + if (posplus(c,keylen) == -1) return -1; + if (posplus(c,datalen) == -1) return -1; + return 0; +} + +int cdb_make_addbegin(struct cdb_make *c,unsigned int keylen,unsigned int datalen) +{ + char buf[8]; + + if (keylen > 0xffffffff) { errno = error_nomem; return -1; } + if (datalen > 0xffffffff) { errno = error_nomem; return -1; } + + uint32_pack(buf,keylen); + uint32_pack(buf + 4,datalen); + if (buffer_putalign(&c->b,buf,8) == -1) return -1; + return 0; +} + +int cdb_make_add(struct cdb_make *c,char *key,unsigned int keylen,char *data,unsigned int datalen) +{ + if (cdb_make_addbegin(c,keylen,datalen) == -1) return -1; + if (buffer_putalign(&c->b,key,keylen) == -1) return -1; + if (buffer_putalign(&c->b,data,datalen) == -1) return -1; + return cdb_make_addend(c,keylen,datalen,cdb_hash(key,keylen)); +} + +int cdb_make_finish(struct cdb_make *c) +{ + char buf[8]; + int i; + uint32 len; + uint32 u; + uint32 memsize; + uint32 count; + uint32 where; + struct cdb_hplist *x; + struct cdb_hp *hp; + + for (i = 0;i < 256;++i) + c->count[i] = 0; + + for (x = c->head;x;x = x->next) { + i = x->num; + while (i--) + ++c->count[255 & x->hp[i].h]; + } + + memsize = 1; + for (i = 0;i < 256;++i) { + u = c->count[i] * 2; + if (u > memsize) + memsize = u; + } + + memsize += c->numentries; /* no overflow possible up to now */ + u = (uint32) 0 - (uint32) 1; + u /= sizeof(struct cdb_hp); + if (memsize > u) { errno = error_nomem; return -1; } + + c->split = (struct cdb_hp *) alloc(memsize * sizeof(struct cdb_hp)); + if (!c->split) return -1; + + c->hash = c->split + c->numentries; + + u = 0; + for (i = 0;i < 256;++i) { + u += c->count[i]; /* bounded by numentries, so no overflow */ + c->start[i] = u; + } + + for (x = c->head;x;x = x->next) { + i = x->num; + while (i--) + c->split[--c->start[255 & x->hp[i].h]] = x->hp[i]; + } + + for (i = 0;i < 256;++i) { + count = c->count[i]; + + len = count + count; /* no overflow possible */ + uint32_pack(c->final + 8 * i,c->pos); + uint32_pack(c->final + 8 * i + 4,len); + + for (u = 0;u < len;++u) + c->hash[u].h = c->hash[u].p = 0; + + hp = c->split + c->start[i]; + for (u = 0;u < count;++u) { + where = (hp->h >> 8) % len; + while (c->hash[where].p) + if (++where == len) + where = 0; + c->hash[where] = *hp++; + } + + for (u = 0;u < len;++u) { + uint32_pack(buf,c->hash[u].h); + uint32_pack(buf + 4,c->hash[u].p); + if (buffer_putalign(&c->b,buf,8) == -1) return -1; + if (posplus(c,8) == -1) return -1; + } + } + + if (buffer_flush(&c->b) == -1) return -1; + if (seek_begin(c->fd) == -1) return -1; + return buffer_putflush(&c->b,c->final,sizeof c->final); +} diff -BbrurN sendmail-8.12.7/makemap/cdbmake.c sendmail-8.12.7-cdb-testbuild/makemap/cdbmake.c --- sendmail-8.12.7/makemap/cdbmake.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/cdbmake.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,110 @@ +#include "error.h" +#include "open.h" +#include "strerr.h" +#include "cdb_make.h" +#include "cdb.h" + +#define FATAL "cdbmake: fatal: " + +char *fn; +char *fntmp; + +void die_usage(void) +{ + strerr_die1x(100,"cdbmake: usage: cdbmake f ftmp"); +} +void die_write(void) +{ + strerr_die4sys(111,FATAL,"unable to create ",fntmp,": "); +} +void die_read(void) +{ + strerr_die2sys(111,FATAL,"unable to read input: "); +} +void die_readformat(void) +{ + strerr_die2x(111,FATAL,"unable to read input: bad format"); +} + +inline void get(char *ch) +{ + switch(buffer_GETC(buffer_0,ch)) { + case 0: die_readformat(); + case -1: die_read(); + } +} + +static struct cdb_make c; + +main(int argc,char **argv) +{ + unsigned int klen; + unsigned int dlen; + unsigned int i; + uint32 h; + int fd; + char ch; + + if (!*argv) die_usage(); + + if (!*++argv) die_usage(); + fn = *argv; + + if (!*++argv) die_usage(); + fntmp = *argv; + + fd = open_trunc(fntmp); + if (fd == -1) die_write(); + + if (cdb_make_start(&c,fd) == -1) die_write(); + + for (;;) { + get(&ch); + if (ch == '\n') break; + if (ch != '+') die_readformat(); + klen = 0; + for (;;) { + get(&ch); + if (ch == ',') break; + if ((ch < '0') || (ch > '9')) die_readformat(); + if (klen > 429496720) { errno = error_nomem; die_write(); } + klen = klen * 10 + (ch - '0'); + } + dlen = 0; + for (;;) { + get(&ch); + if (ch == ':') break; + if ((ch < '0') || (ch > '9')) die_readformat(); + if (dlen > 429496720) { errno = error_nomem; die_write(); } + dlen = dlen * 10 + (ch - '0'); + } + + if (cdb_make_addbegin(&c,klen,dlen) == -1) die_write(); + h = CDB_HASHSTART; + for (i = 0;i < klen;++i) { + get(&ch); + if (buffer_PUTC(&c.b,ch) == -1) die_write(); + h = cdb_hashadd(h,ch); + } + get(&ch); + if (ch != '-') die_readformat(); + get(&ch); + if (ch != '>') die_readformat(); + for (i = 0;i < dlen;++i) { + get(&ch); + if (buffer_PUTC(&c.b,ch) == -1) die_write(); + } + if (cdb_make_addend(&c,klen,dlen,h) == -1) die_write(); + + get(&ch); + if (ch != '\n') die_readformat(); + } + + if (cdb_make_finish(&c) == -1) die_write(); + if (fsync(fd) == -1) die_write(); + if (close(fd) == -1) die_write(); /* NFS silliness */ + if (rename(fntmp,fn) == -1) + strerr_die6sys(111,FATAL,"unable to rename ",fntmp," to ",fn,": "); + + _exit(0); +} diff -BbrurN sendmail-8.12.7/makemap/cdb_make.h sendmail-8.12.7-cdb-testbuild/makemap/cdb_make.h --- sendmail-8.12.7/makemap/cdb_make.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/cdb_make.h 2003-01-29 01:23:17.000000000 +0800 @@ -0,0 +1,39 @@ +/* Public domain. */ + +#ifndef CDB_MAKE_H +#define CDB_MAKE_H + +#include "buffer.h" +#include "uint32.h" + +#define CDB_HPLIST 1000 + +struct cdb_hp { uint32 h; uint32 p; } ; + +struct cdb_hplist { + struct cdb_hp hp[CDB_HPLIST]; + struct cdb_hplist *next; + int num; +} ; + +struct cdb_make { + char bspace[8192]; + char final[2048]; + uint32 count[256]; + uint32 start[256]; + struct cdb_hplist *head; + struct cdb_hp *split; /* includes space for hash */ + struct cdb_hp *hash; + uint32 numentries; + buffer b; + uint32 pos; + int fd; +} ; + +extern int cdb_make_start(struct cdb_make *,int); +extern int cdb_make_addbegin(struct cdb_make *,unsigned int,unsigned int); +extern int cdb_make_addend(struct cdb_make *,unsigned int,unsigned int,uint32); +extern int cdb_make_add(struct cdb_make *,char *,unsigned int,char *,unsigned int); +extern int cdb_make_finish(struct cdb_make *); + +#endif diff -BbrurN sendmail-8.12.7/makemap/cdbstats.c sendmail-8.12.7-cdb-testbuild/makemap/cdbstats.c --- sendmail-8.12.7/makemap/cdbstats.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/cdbstats.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,125 @@ +#include "uint32.h" +#include "fmt.h" +#include "buffer.h" +#include "strerr.h" +#include "seek.h" +#include "cdb.h" + +#define FATAL "cdbstats: fatal: " + +void die_read(void) +{ + strerr_die2sys(111,FATAL,"unable to read input: "); +} +void die_readformat(void) +{ + strerr_die2x(111,FATAL,"unable to read input: truncated file"); +} +void die_write(void) +{ + strerr_die2sys(111,FATAL,"unable to write output: "); +} +void put(char *buf,unsigned int len) +{ + if (buffer_put(buffer_1small,buf,len) == -1) die_write(); +} +void putflush(void) +{ + if (buffer_flush(buffer_1small) == -1) die_write(); +} + +uint32 pos = 0; + +void get(char *buf,unsigned int len) +{ + int r; + while (len > 0) { + r = buffer_get(buffer_0,buf,len); + if (r == -1) die_read(); + if (r == 0) die_readformat(); + pos += r; + buf += r; + len -= r; + } +} + +void getnum(uint32 *num) +{ + char buf[4]; + get(buf,4); + uint32_unpack(buf,num); +} + +char strnum[FMT_ULONG]; + +void putnum(char *label,unsigned long count) +{ + unsigned int i; + put(label,str_len(label)); + for (i = fmt_ulong(0,count);i < 10;++i) put(" ",1); + put(strnum,fmt_ulong(strnum,count)); + put("\n",1); +} + +char key[1024]; + +static struct cdb c; + +static unsigned long numrecords; +static unsigned long numd[11]; + +main() +{ + uint32 eod; + uint32 klen; + uint32 dlen; + seek_pos rest; + int r; + + cdb_init(&c,0); + + getnum(&eod); + while (pos < 2048) getnum(&dlen); + + while (pos < eod) { + getnum(&klen); + getnum(&dlen); + if (klen > sizeof key) { + while (klen) { get(key,1); --klen; } + } + else { + get(key,klen); + rest = seek_cur(0); + cdb_findstart(&c); + do { + switch(cdb_findnext(&c,key,klen)) { + case -1: die_read(); + case 0: die_readformat(); + } + } while (cdb_datapos(&c) != pos); + if (!c.loop) die_readformat(); + ++numrecords; + if (c.loop > 10) + ++numd[10]; + else + ++numd[c.loop - 1]; + if (seek_set(0,rest) == -1) die_read(); + } + while (dlen) { get(key,1); --dlen; } + } + + putnum("records ",numrecords); + putnum("d0 ",numd[0]); + putnum("d1 ",numd[1]); + putnum("d2 ",numd[2]); + putnum("d3 ",numd[3]); + putnum("d4 ",numd[4]); + putnum("d5 ",numd[5]); + putnum("d6 ",numd[6]); + putnum("d7 ",numd[7]); + putnum("d8 ",numd[8]); + putnum("d9 ",numd[9]); + putnum(">9 ",numd[10]); + putflush(); + _exit(0); +} diff -BbrurN sendmail-8.12.7/makemap/cdbtest.c sendmail-8.12.7-cdb-testbuild/makemap/cdbtest.c --- sendmail-8.12.7/makemap/cdbtest.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/cdbtest.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,119 @@ +#include "uint32.h" +#include "fmt.h" +#include "buffer.h" +#include "strerr.h" +#include "seek.h" +#include "cdb.h" + +#define FATAL "cdbtest: fatal: " + +void die_read(void) +{ + strerr_die2sys(111,FATAL,"unable to read input: "); +} +void die_write(void) +{ + strerr_die2sys(111,FATAL,"unable to write output: "); +} +void put(char *buf,unsigned int len) +{ + if (buffer_put(buffer_1small,buf,len) == -1) die_write(); +} +void putflush(void) +{ + if (buffer_flush(buffer_1small) == -1) die_write(); +} + +uint32 pos = 0; + +void get(char *buf,unsigned int len) +{ + int r; + while (len > 0) { + r = buffer_get(buffer_0,buf,len); + if (r == -1) die_read(); + if (r == 0) + strerr_die2x(111,FATAL,"unable to read input: truncated file"); + pos += r; + buf += r; + len -= r; + } +} + +void getnum(uint32 *num) +{ + char buf[4]; + get(buf,4); + uint32_unpack(buf,num); +} + +char strnum[FMT_ULONG]; + +void putnum(char *label,unsigned long count) +{ + put(label,str_len(label)); + put(strnum,fmt_ulong(strnum,count)); + put("\n",1); +} + +char key[1024]; + +unsigned long numuntested = 0; +unsigned long numnotfound = 0; +unsigned long numotherpos = 0; +unsigned long numbadlen = 0; +unsigned long numfound = 0; + +static struct cdb c; + +main() +{ + uint32 eod; + uint32 klen; + uint32 dlen; + seek_pos rest; + int r; + + cdb_init(&c,0); + + getnum(&eod); + while (pos < 2048) getnum(&dlen); + + while (pos < eod) { + getnum(&klen); + getnum(&dlen); + if (klen > sizeof key) { + ++numuntested; + while (klen) { get(key,1); --klen; } + } + else { + get(key,klen); + rest = seek_cur(0); + switch(cdb_find(&c,key,klen)) { + case -1: + die_read(); + case 0: + ++numnotfound; + break; + default: + if (cdb_datapos(&c) != pos) + ++numotherpos; + else + if (cdb_datalen(&c) != dlen) + ++numbadlen; + else + ++numfound; + } + if (seek_set(0,rest) == -1) die_read(); + } + while (dlen) { get(key,1); --dlen; } + } + + putnum("found: ",numfound); + putnum("different record: ",numotherpos); + putnum("bad length: ",numbadlen); + putnum("not found: ",numnotfound); + putnum("untested: ",numuntested); + putflush(); + _exit(0); +} diff -BbrurN sendmail-8.12.7/makemap/error.c sendmail-8.12.7-cdb-testbuild/makemap/error.c --- sendmail-8.12.7/makemap/error.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/error.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,109 @@ +#include +#include "error.h" + +/* warning: as coverage improves here, should update error_{str,temp} */ + +int error_intr = +#ifdef EINTR +EINTR; +#else +-1; +#endif + +int error_nomem = +#ifdef ENOMEM +ENOMEM; +#else +-2; +#endif + +int error_noent = +#ifdef ENOENT +ENOENT; +#else +-3; +#endif + +int error_txtbsy = +#ifdef ETXTBSY +ETXTBSY; +#else +-4; +#endif + +int error_io = +#ifdef EIO +EIO; +#else +-5; +#endif + +int error_exist = +#ifdef EEXIST +EEXIST; +#else +-6; +#endif + +int error_timeout = +#ifdef ETIMEDOUT +ETIMEDOUT; +#else +-7; +#endif + +int error_inprogress = +#ifdef EINPROGRESS +EINPROGRESS; +#else +-8; +#endif + +int error_wouldblock = +#ifdef EWOULDBLOCK +EWOULDBLOCK; +#else +-9; +#endif + +int error_again = +#ifdef EAGAIN +EAGAIN; +#else +-10; +#endif + +int error_pipe = +#ifdef EPIPE +EPIPE; +#else +-11; +#endif + +int error_perm = +#ifdef EPERM +EPERM; +#else +-12; +#endif + +int error_acces = +#ifdef EACCES +EACCES; +#else +-13; +#endif + +int error_nodevice = +#ifdef ENXIO +ENXIO; +#else +-14; +#endif + +int error_proto = +#ifdef EPROTO +EPROTO; +#else +-15; +#endif diff -BbrurN sendmail-8.12.7/makemap/error.h sendmail-8.12.7-cdb-testbuild/makemap/error.h --- sendmail-8.12.7/makemap/error.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/error.h 2003-01-29 01:23:17.000000000 +0800 @@ -0,0 +1,25 @@ +#ifndef ERROR_H +#define ERROR_H + +extern int errno; + +extern int error_intr; +extern int error_nomem; +extern int error_noent; +extern int error_txtbsy; +extern int error_io; +extern int error_exist; +extern int error_timeout; +extern int error_inprogress; +extern int error_wouldblock; +extern int error_again; +extern int error_pipe; +extern int error_perm; +extern int error_acces; +extern int error_nodevice; +extern int error_proto; + +extern char *error_str(int); +extern int error_temp(int); + +#endif diff -BbrurN sendmail-8.12.7/makemap/error_str.c sendmail-8.12.7-cdb-testbuild/makemap/error_str.c --- sendmail-8.12.7/makemap/error_str.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/error_str.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,271 @@ +#include +#include "error.h" + +#define X(e,s) if (i == e) return s; + +char *error_str(int i) +{ + X(0,"no error") + X(error_intr,"interrupted system call") + X(error_nomem,"out of memory") + X(error_noent,"file does not exist") + X(error_txtbsy,"text busy") + X(error_io,"input/output error") + X(error_exist,"file already exists") + X(error_timeout,"timed out") + X(error_inprogress,"operation in progress") + X(error_again,"temporary failure") + X(error_wouldblock,"input/output would block") + X(error_pipe,"broken pipe") + X(error_perm,"permission denied") + X(error_acces,"access denied") + X(error_nodevice,"device not configured") + X(error_proto,"protocol error") +#ifdef ESRCH + X(ESRCH,"no such process") +#endif +#ifdef E2BIG + X(E2BIG,"argument list too long") +#endif +#ifdef ENOEXEC + X(ENOEXEC,"exec format error") +#endif +#ifdef EBADF + X(EBADF,"file descriptor not open") +#endif +#ifdef ECHILD + X(ECHILD,"no child processes") +#endif +#ifdef EDEADLK + X(EDEADLK,"operation would cause deadlock") +#endif +#ifdef EFAULT + X(EFAULT,"bad address") +#endif +#ifdef ENOTBLK + X(ENOTBLK,"not a block device") +#endif +#ifdef EBUSY + X(EBUSY,"device busy") +#endif +#ifdef EXDEV + X(EXDEV,"cross-device link") +#endif +#ifdef ENODEV + X(ENODEV,"device does not support operation") +#endif +#ifdef ENOTDIR + X(ENOTDIR,"not a directory") +#endif +#ifdef EISDIR + X(EISDIR,"is a directory") +#endif +#ifdef EINVAL + X(EINVAL,"invalid argument") +#endif +#ifdef ENFILE + X(ENFILE,"system cannot open more files") +#endif +#ifdef EMFILE + X(EMFILE,"process cannot open more files") +#endif +#ifdef ENOTTY + X(ENOTTY,"not a tty") +#endif +#ifdef EFBIG + X(EFBIG,"file too big") +#endif +#ifdef ENOSPC + X(ENOSPC,"out of disk space") +#endif +#ifdef ESPIPE + X(ESPIPE,"unseekable descriptor") +#endif +#ifdef EROFS + X(EROFS,"read-only file system") +#endif +#ifdef EMLINK + X(EMLINK,"too many links") +#endif +#ifdef EDOM + X(EDOM,"input out of range") +#endif +#ifdef ERANGE + X(ERANGE,"output out of range") +#endif +#ifdef EALREADY + X(EALREADY,"operation already in progress") +#endif +#ifdef ENOTSOCK + X(ENOTSOCK,"not a socket") +#endif +#ifdef EDESTADDRREQ + X(EDESTADDRREQ,"destination address required") +#endif +#ifdef EMSGSIZE + X(EMSGSIZE,"message too long") +#endif +#ifdef EPROTOTYPE + X(EPROTOTYPE,"incorrect protocol type") +#endif +#ifdef ENOPROTOOPT + X(ENOPROTOOPT,"protocol not available") +#endif +#ifdef EPROTONOSUPPORT + X(EPROTONOSUPPORT,"protocol not supported") +#endif +#ifdef ESOCKTNOSUPPORT + X(ESOCKTNOSUPPORT,"socket type not supported") +#endif +#ifdef EOPNOTSUPP + X(EOPNOTSUPP,"operation not supported") +#endif +#ifdef EPFNOSUPPORT + X(EPFNOSUPPORT,"protocol family not supported") +#endif +#ifdef EAFNOSUPPORT + X(EAFNOSUPPORT,"address family not supported") +#endif +#ifdef EADDRINUSE + X(EADDRINUSE,"address already used") +#endif +#ifdef EADDRNOTAVAIL + X(EADDRNOTAVAIL,"address not available") +#endif +#ifdef ENETDOWN + X(ENETDOWN,"network down") +#endif +#ifdef ENETUNREACH + X(ENETUNREACH,"network unreachable") +#endif +#ifdef ENETRESET + X(ENETRESET,"network reset") +#endif +#ifdef ECONNABORTED + X(ECONNABORTED,"connection aborted") +#endif +#ifdef ECONNRESET + X(ECONNRESET,"connection reset") +#endif +#ifdef ENOBUFS + X(ENOBUFS,"out of buffer space") +#endif +#ifdef EISCONN + X(EISCONN,"already connected") +#endif +#ifdef ENOTCONN + X(ENOTCONN,"not connected") +#endif +#ifdef ESHUTDOWN + X(ESHUTDOWN,"socket shut down") +#endif +#ifdef ETOOMANYREFS + X(ETOOMANYREFS,"too many references") +#endif +#ifdef ECONNREFUSED + X(ECONNREFUSED,"connection refused") +#endif +#ifdef ELOOP + X(ELOOP,"symbolic link loop") +#endif +#ifdef ENAMETOOLONG + X(ENAMETOOLONG,"file name too long") +#endif +#ifdef EHOSTDOWN + X(EHOSTDOWN,"host down") +#endif +#ifdef EHOSTUNREACH + X(EHOSTUNREACH,"host unreachable") +#endif +#ifdef ENOTEMPTY + X(ENOTEMPTY,"directory not empty") +#endif +#ifdef EPROCLIM + X(EPROCLIM,"too many processes") +#endif +#ifdef EUSERS + X(EUSERS,"too many users") +#endif +#ifdef EDQUOT + X(EDQUOT,"disk quota exceeded") +#endif +#ifdef ESTALE + X(ESTALE,"stale NFS file handle") +#endif +#ifdef EREMOTE + X(EREMOTE,"too many levels of remote in path") +#endif +#ifdef EBADRPC + X(EBADRPC,"RPC structure is bad") +#endif +#ifdef ERPCMISMATCH + X(ERPCMISMATCH,"RPC version mismatch") +#endif +#ifdef EPROGUNAVAIL + X(EPROGUNAVAIL,"RPC program unavailable") +#endif +#ifdef EPROGMISMATCH + X(EPROGMISMATCH,"program version mismatch") +#endif +#ifdef EPROCUNAVAIL + X(EPROCUNAVAIL,"bad procedure for program") +#endif +#ifdef ENOLCK + X(ENOLCK,"no locks available") +#endif +#ifdef ENOSYS + X(ENOSYS,"system call not available") +#endif +#ifdef EFTYPE + X(EFTYPE,"bad file type") +#endif +#ifdef EAUTH + X(EAUTH,"authentication error") +#endif +#ifdef ENEEDAUTH + X(ENEEDAUTH,"not authenticated") +#endif +#ifdef ENOSTR + X(ENOSTR,"not a stream device") +#endif +#ifdef ETIME + X(ETIME,"timer expired") +#endif +#ifdef ENOSR + X(ENOSR,"out of stream resources") +#endif +#ifdef ENOMSG + X(ENOMSG,"no message of desired type") +#endif +#ifdef EBADMSG + X(EBADMSG,"bad message type") +#endif +#ifdef EIDRM + X(EIDRM,"identifier removed") +#endif +#ifdef ENONET + X(ENONET,"machine not on network") +#endif +#ifdef ERREMOTE + X(ERREMOTE,"object not local") +#endif +#ifdef ENOLINK + X(ENOLINK,"link severed") +#endif +#ifdef EADV + X(EADV,"advertise error") +#endif +#ifdef ESRMNT + X(ESRMNT,"srmount error") +#endif +#ifdef ECOMM + X(ECOMM,"communication error") +#endif +#ifdef EMULTIHOP + X(EMULTIHOP,"multihop attempted") +#endif +#ifdef EREMCHG + X(EREMCHG,"remote address changed") +#endif + return "unknown error"; +} diff -BbrurN sendmail-8.12.7/makemap/exit.h sendmail-8.12.7-cdb-testbuild/makemap/exit.h --- sendmail-8.12.7/makemap/exit.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/exit.h 2003-01-29 01:23:17.000000000 +0800 @@ -0,0 +1,6 @@ +#ifndef EXIT_H +#define EXIT_H + +extern void _exit(); + +#endif diff -BbrurN sendmail-8.12.7/makemap/fmt.h sendmail-8.12.7-cdb-testbuild/makemap/fmt.h --- sendmail-8.12.7/makemap/fmt.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/fmt.h 2003-01-29 01:23:17.000000000 +0800 @@ -0,0 +1,25 @@ +#ifndef FMT_H +#define FMT_H + +#define FMT_ULONG 40 /* enough space to hold 2^128 - 1 in decimal, plus \0 */ +#define FMT_LEN ((char *) 0) /* convenient abbreviation */ + +extern unsigned int fmt_uint(char *,unsigned int); +extern unsigned int fmt_uint0(char *,unsigned int,unsigned int); +extern unsigned int fmt_xint(char *,unsigned int); +extern unsigned int fmt_nbbint(char *,unsigned int,unsigned int,unsigned int,unsigned int); +extern unsigned int fmt_ushort(char *,unsigned short); +extern unsigned int fmt_xshort(char *,unsigned short); +extern unsigned int fmt_nbbshort(char *,unsigned int,unsigned int,unsigned int,unsigned short); +extern unsigned int fmt_ulong(char *,unsigned long); +extern unsigned int fmt_xlong(char *,unsigned long); +extern unsigned int fmt_nbblong(char *,unsigned int,unsigned int,unsigned int,unsigned long); + +extern unsigned int fmt_plusminus(char *,int); +extern unsigned int fmt_minus(char *,int); +extern unsigned int fmt_0x(char *,int); + +extern unsigned int fmt_str(char *,char *); +extern unsigned int fmt_strn(char *,char *,unsigned int); + +#endif diff -BbrurN sendmail-8.12.7/makemap/fmt_ulong.c sendmail-8.12.7-cdb-testbuild/makemap/fmt_ulong.c --- sendmail-8.12.7/makemap/fmt_ulong.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/fmt_ulong.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,13 @@ +#include "fmt.h" + +unsigned int fmt_ulong(register char *s,register unsigned long u) +{ + register unsigned int len; register unsigned long q; + len = 1; q = u; + while (q > 9) { ++len; q /= 10; } + if (s) { + s += len; + do { *--s = '0' + (u % 10); u /= 10; } while(u); /* handles u == 0 */ + } + return len; +} diff -BbrurN sendmail-8.12.7/makemap/hier.c sendmail-8.12.7-cdb-testbuild/makemap/hier.c --- sendmail-8.12.7/makemap/hier.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/hier.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,15 @@ +#include "auto_home.h" + +void hier() +{ + h(auto_home,-1,-1,02755); + d(auto_home,"bin",-1,-1,02755); + + c(auto_home,"bin","cdbget",-1,-1,0755); + c(auto_home,"bin","cdbmake",-1,-1,0755); + c(auto_home,"bin","cdbdump",-1,-1,0755); + c(auto_home,"bin","cdbstats",-1,-1,0755); + c(auto_home,"bin","cdbtest",-1,-1,0755); + c(auto_home,"bin","cdbmake-12",-1,-1,0755); + c(auto_home,"bin","cdbmake-sv",-1,-1,0755); +} diff -BbrurN sendmail-8.12.7/makemap/install.c sendmail-8.12.7-cdb-testbuild/makemap/install.c --- sendmail-8.12.7/makemap/install.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/install.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,149 @@ +#include "buffer.h" +#include "strerr.h" +#include "error.h" +#include "open.h" +#include "readwrite.h" +#include "exit.h" + +extern void hier(); + +#define FATAL "install: fatal: " + +int fdsourcedir = -1; + +void h(home,uid,gid,mode) +char *home; +int uid; +int gid; +int mode; +{ + if (mkdir(home,0700) == -1) + if (errno != error_exist) + strerr_die4sys(111,FATAL,"unable to mkdir ",home,": "); + if (chown(home,uid,gid) == -1) + strerr_die4sys(111,FATAL,"unable to chown ",home,": "); + if (chmod(home,mode) == -1) + strerr_die4sys(111,FATAL,"unable to chmod ",home,": "); +} + +void d(home,subdir,uid,gid,mode) +char *home; +char *subdir; +int uid; +int gid; +int mode; +{ + if (chdir(home) == -1) + strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); + if (mkdir(subdir,0700) == -1) + if (errno != error_exist) + strerr_die6sys(111,FATAL,"unable to mkdir ",home,"/",subdir,": "); + if (chown(subdir,uid,gid) == -1) + strerr_die6sys(111,FATAL,"unable to chown ",home,"/",subdir,": "); + if (chmod(subdir,mode) == -1) + strerr_die6sys(111,FATAL,"unable to chmod ",home,"/",subdir,": "); +} + +char inbuf[BUFFER_INSIZE]; +char outbuf[BUFFER_OUTSIZE]; +buffer ssin; +buffer ssout; + +void c(home,subdir,file,uid,gid,mode) +char *home; +char *subdir; +char *file; +int uid; +int gid; +int mode; +{ + int fdin; + int fdout; + + if (fchdir(fdsourcedir) == -1) + strerr_die2sys(111,FATAL,"unable to switch back to source directory: "); + + fdin = open_read(file); + if (fdin == -1) + strerr_die4sys(111,FATAL,"unable to read ",file,": "); + buffer_init(&ssin,read,fdin,inbuf,sizeof inbuf); + + if (chdir(home) == -1) + strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); + if (chdir(subdir) == -1) + strerr_die6sys(111,FATAL,"unable to switch to ",home,"/",subdir,": "); + + fdout = open_trunc(file); + if (fdout == -1) + strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); + buffer_init(&ssout,write,fdout,outbuf,sizeof outbuf); + + switch(buffer_copy(&ssout,&ssin)) { + case -2: + strerr_die4sys(111,FATAL,"unable to read ",file,": "); + case -3: + strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); + } + + close(fdin); + if (buffer_flush(&ssout) == -1) + strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); + if (fsync(fdout) == -1) + strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); + if (close(fdout) == -1) /* NFS silliness */ + strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); + + if (chown(file,uid,gid) == -1) + strerr_die6sys(111,FATAL,"unable to chown .../",subdir,"/",file,": "); + if (chmod(file,mode) == -1) + strerr_die6sys(111,FATAL,"unable to chmod .../",subdir,"/",file,": "); +} + +void z(home,subdir,file,len,uid,gid,mode) +char *home; +char *subdir; +char *file; +int len; +int uid; +int gid; +int mode; +{ + int fdout; + + if (chdir(home) == -1) + strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); + if (chdir(subdir) == -1) + strerr_die6sys(111,FATAL,"unable to switch to ",home,"/",subdir,": "); + + fdout = open_trunc(file); + if (fdout == -1) + strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); + buffer_init(&ssout,write,fdout,outbuf,sizeof outbuf); + + while (len-- > 0) + if (buffer_put(&ssout,"",1) == -1) + strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); + + if (buffer_flush(&ssout) == -1) + strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); + if (fsync(fdout) == -1) + strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); + if (close(fdout) == -1) /* NFS silliness */ + strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); + + if (chown(file,uid,gid) == -1) + strerr_die6sys(111,FATAL,"unable to chown .../",subdir,"/",file,": "); + if (chmod(file,mode) == -1) + strerr_die6sys(111,FATAL,"unable to chmod .../",subdir,"/",file,": "); +} + +main() +{ + fdsourcedir = open_read("."); + if (fdsourcedir == -1) + strerr_die2sys(111,FATAL,"unable to open current directory: "); + + umask(077); + hier(); + _exit(0); +} diff -BbrurN sendmail-8.12.7/makemap/instcheck.c sendmail-8.12.7-cdb-testbuild/makemap/instcheck.c --- sendmail-8.12.7/makemap/instcheck.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/instcheck.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,108 @@ +#include +#include +#include "strerr.h" +#include "error.h" +#include "readwrite.h" +#include "exit.h" + +extern void hier(); + +#define FATAL "instcheck: fatal: " +#define WARNING "instcheck: warning: " + +void perm(prefix1,prefix2,prefix3,file,type,uid,gid,mode) +char *prefix1; +char *prefix2; +char *prefix3; +char *file; +int type; +int uid; +int gid; +int mode; +{ + struct stat st; + + if (stat(file,&st) == -1) { + if (errno == error_noent) + strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," does not exist",0); + else + strerr_warn4(WARNING,"unable to stat .../",file,": ",&strerr_sys); + return; + } + + if ((uid != -1) && (st.st_uid != uid)) + strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong owner",0); + if ((gid != -1) && (st.st_gid != gid)) + strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong group",0); + if ((st.st_mode & 07777) != mode) + strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong permissions",0); + if ((st.st_mode & S_IFMT) != type) + strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong type",0); +} + +void h(home,uid,gid,mode) +char *home; +int uid; +int gid; +int mode; +{ + perm("","","",home,S_IFDIR,uid,gid,mode); +} + +void d(home,subdir,uid,gid,mode) +char *home; +char *subdir; +int uid; +int gid; +int mode; +{ + if (chdir(home) == -1) + strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); + perm("",home,"/",subdir,S_IFDIR,uid,gid,mode); +} + +void p(home,fifo,uid,gid,mode) +char *home; +char *fifo; +int uid; +int gid; +int mode; +{ + if (chdir(home) == -1) + strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); + perm("",home,"/",fifo,S_IFIFO,uid,gid,mode); +} + +void c(home,subdir,file,uid,gid,mode) +char *home; +char *subdir; +char *file; +int uid; +int gid; +int mode; +{ + if (chdir(home) == -1) + strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); + if (chdir(subdir) == -1) + strerr_die6sys(111,FATAL,"unable to switch to ",home,"/",subdir,": "); + perm(".../",subdir,"/",file,S_IFREG,uid,gid,mode); +} + +void z(home,file,len,uid,gid,mode) +char *home; +char *file; +int len; +int uid; +int gid; +int mode; +{ + if (chdir(home) == -1) + strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); + perm("",home,"/",file,S_IFREG,uid,gid,mode); +} + +main() +{ + hier(); + _exit(0); +} diff -BbrurN sendmail-8.12.7/makemap/open.h sendmail-8.12.7-cdb-testbuild/makemap/open.h --- sendmail-8.12.7/makemap/open.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/open.h 2003-01-29 01:23:17.000000000 +0800 @@ -0,0 +1,10 @@ +#ifndef OPEN_H +#define OPEN_H + +extern int open_read(char *); +extern int open_excl(char *); +extern int open_append(char *); +extern int open_trunc(char *); +extern int open_write(char *); + +#endif diff -BbrurN sendmail-8.12.7/makemap/open_read.c sendmail-8.12.7-cdb-testbuild/makemap/open_read.c --- sendmail-8.12.7/makemap/open_read.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/open_read.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,6 @@ +#include +#include +#include "open.h" + +int open_read(char *fn) +{ return open(fn,O_RDONLY | O_NDELAY); } diff -BbrurN sendmail-8.12.7/makemap/open_trunc.c sendmail-8.12.7-cdb-testbuild/makemap/open_trunc.c --- sendmail-8.12.7/makemap/open_trunc.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/open_trunc.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,6 @@ +#include +#include +#include "open.h" + +int open_trunc(char *fn) +{ return open(fn,O_WRONLY | O_NDELAY | O_TRUNC | O_CREAT,0644); } diff -BbrurN sendmail-8.12.7/makemap/readwrite.h sendmail-8.12.7-cdb-testbuild/makemap/readwrite.h --- sendmail-8.12.7/makemap/readwrite.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/readwrite.h 2003-01-29 01:23:17.000000000 +0800 @@ -0,0 +1,7 @@ +#ifndef READWRITE_H +#define READWRITE_H + +extern int read(); +extern int write(); + +#endif diff -BbrurN sendmail-8.12.7/makemap/scan.h sendmail-8.12.7-cdb-testbuild/makemap/scan.h --- sendmail-8.12.7/makemap/scan.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/scan.h 2003-01-29 01:23:17.000000000 +0800 @@ -0,0 +1,28 @@ +#ifndef SCAN_H +#define SCAN_H + +extern unsigned int scan_uint(char *,unsigned int *); +extern unsigned int scan_xint(char *,unsigned int *); +extern unsigned int scan_nbbint(char *,unsigned int,unsigned int,unsigned int,unsigned int *); +extern unsigned int scan_ushort(char *,unsigned short *); +extern unsigned int scan_xshort(char *,unsigned short *); +extern unsigned int scan_nbbshort(char *,unsigned int,unsigned int,unsigned int,unsigned short *); +extern unsigned int scan_ulong(char *,unsigned long *); +extern unsigned int scan_xlong(char *,unsigned long *); +extern unsigned int scan_nbblong(char *,unsigned int,unsigned int,unsigned int,unsigned long *); + +extern unsigned int scan_plusminus(char *,int *); +extern unsigned int scan_0x(char *,unsigned int *); + +extern unsigned int scan_whitenskip(char *,unsigned int); +extern unsigned int scan_nonwhitenskip(char *,unsigned int); +extern unsigned int scan_charsetnskip(char *,char *,unsigned int); +extern unsigned int scan_noncharsetnskip(char *,char *,unsigned int); + +extern unsigned int scan_strncmp(char *,char *,unsigned int); +extern unsigned int scan_memcmp(char *,char *,unsigned int); + +extern unsigned int scan_long(char *,long *); +extern unsigned int scan_8long(char *,unsigned long *); + +#endif diff -BbrurN sendmail-8.12.7/makemap/scan_ulong.c sendmail-8.12.7-cdb-testbuild/makemap/scan_ulong.c --- sendmail-8.12.7/makemap/scan_ulong.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/scan_ulong.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,11 @@ +#include "scan.h" + +unsigned int scan_ulong(register char *s,register unsigned long *u) +{ + register unsigned int pos; register unsigned long result; + register unsigned long c; + pos = 0; result = 0; + while ((c = (unsigned long) (unsigned char) (s[pos] - '0')) < 10) + { result = result * 10 + c; ++pos; } + *u = result; return pos; +} diff -BbrurN sendmail-8.12.7/makemap/seek_cur.c sendmail-8.12.7-cdb-testbuild/makemap/seek_cur.c --- sendmail-8.12.7/makemap/seek_cur.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/seek_cur.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,7 @@ +#include +#include "seek.h" + +#define CUR 1 /* sigh */ + +seek_pos seek_cur(int fd) +{ return lseek(fd,(off_t) 0,CUR); } diff -BbrurN sendmail-8.12.7/makemap/seek.h sendmail-8.12.7-cdb-testbuild/makemap/seek.h --- sendmail-8.12.7/makemap/seek.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/seek.h 2003-01-29 01:23:17.000000000 +0800 @@ -0,0 +1,15 @@ +#ifndef SEEK_H +#define SEEK_H + +typedef unsigned long seek_pos; + +extern seek_pos seek_cur(int); + +extern int seek_set(int,seek_pos); +extern int seek_end(int); + +extern int seek_trunc(int,seek_pos); + +#define seek_begin(fd) (seek_set((fd),(seek_pos) 0)) + +#endif diff -BbrurN sendmail-8.12.7/makemap/seek_set.c sendmail-8.12.7-cdb-testbuild/makemap/seek_set.c --- sendmail-8.12.7/makemap/seek_set.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/seek_set.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,7 @@ +#include +#include "seek.h" + +#define SET 0 /* sigh */ + +int seek_set(int fd,seek_pos pos) +{ if (lseek(fd,(off_t) pos,SET) == -1) return -1; return 0; } diff -BbrurN sendmail-8.12.7/makemap/strerr_die.c sendmail-8.12.7-cdb-testbuild/makemap/strerr_die.c --- sendmail-8.12.7/makemap/strerr_die.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/strerr_die.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,31 @@ +#include "buffer.h" +#include "exit.h" +#include "strerr.h" + +void strerr_warn(char *x1,char *x2,char *x3,char *x4,char *x5,char *x6,struct strerr *se) +{ + strerr_sysinit(); + + if (x1) buffer_puts(buffer_2,x1); + if (x2) buffer_puts(buffer_2,x2); + if (x3) buffer_puts(buffer_2,x3); + if (x4) buffer_puts(buffer_2,x4); + if (x5) buffer_puts(buffer_2,x5); + if (x6) buffer_puts(buffer_2,x6); + + while(se) { + if (se->x) buffer_puts(buffer_2,se->x); + if (se->y) buffer_puts(buffer_2,se->y); + if (se->z) buffer_puts(buffer_2,se->z); + se = se->who; + } + + buffer_puts(buffer_2,"\n"); + buffer_flush(buffer_2); +} + +void strerr_die(int e,char *x1,char *x2,char *x3,char *x4,char *x5,char *x6,struct strerr *se) +{ + strerr_warn(x1,x2,x3,x4,x5,x6,se); + _exit(e); +} diff -BbrurN sendmail-8.12.7/makemap/strerr.h sendmail-8.12.7-cdb-testbuild/makemap/strerr.h --- sendmail-8.12.7/makemap/strerr.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/strerr.h 2003-01-29 01:23:17.000000000 +0800 @@ -0,0 +1,78 @@ +#ifndef STRERR_H +#define STRERR_H + +struct strerr { + struct strerr *who; + char *x; + char *y; + char *z; +} ; + +extern struct strerr strerr_sys; +extern void strerr_sysinit(void); + +extern char *strerr(struct strerr *); +extern void strerr_warn(char *,char *,char *,char *,char *,char *,struct strerr *); +extern void strerr_die(int,char *,char *,char *,char *,char *,char *,struct strerr *); + +#define STRERR(r,se,a) \ +{ se.who = 0; se.x = a; se.y = 0; se.z = 0; return r; } + +#define STRERR_SYS(r,se,a) \ +{ se.who = &strerr_sys; se.x = a; se.y = 0; se.z = 0; return r; } +#define STRERR_SYS3(r,se,a,b,c) \ +{ se.who = &strerr_sys; se.x = a; se.y = b; se.z = c; return r; } + +#define strerr_warn6(x1,x2,x3,x4,x5,x6,se) \ +strerr_warn((x1),(x2),(x3),(x4),(x5),(x6),(se)) +#define strerr_warn5(x1,x2,x3,x4,x5,se) \ +strerr_warn((x1),(x2),(x3),(x4),(x5),0,(se)) +#define strerr_warn4(x1,x2,x3,x4,se) \ +strerr_warn((x1),(x2),(x3),(x4),0,0,(se)) +#define strerr_warn3(x1,x2,x3,se) \ +strerr_warn((x1),(x2),(x3),0,0,0,(se)) +#define strerr_warn2(x1,x2,se) \ +strerr_warn((x1),(x2),0,0,0,0,(se)) +#define strerr_warn1(x1,se) \ +strerr_warn((x1),0,0,0,0,0,(se)) + +#define strerr_die6(e,x1,x2,x3,x4,x5,x6,se) \ +strerr_die((e),(x1),(x2),(x3),(x4),(x5),(x6),(se)) +#define strerr_die5(e,x1,x2,x3,x4,x5,se) \ +strerr_die((e),(x1),(x2),(x3),(x4),(x5),0,(se)) +#define strerr_die4(e,x1,x2,x3,x4,se) \ +strerr_die((e),(x1),(x2),(x3),(x4),0,0,(se)) +#define strerr_die3(e,x1,x2,x3,se) \ +strerr_die((e),(x1),(x2),(x3),0,0,0,(se)) +#define strerr_die2(e,x1,x2,se) \ +strerr_die((e),(x1),(x2),0,0,0,0,(se)) +#define strerr_die1(e,x1,se) \ +strerr_die((e),(x1),0,0,0,0,0,(se)) + +#define strerr_die6sys(e,x1,x2,x3,x4,x5,x6) \ +strerr_die((e),(x1),(x2),(x3),(x4),(x5),(x6),&strerr_sys) +#define strerr_die5sys(e,x1,x2,x3,x4,x5) \ +strerr_die((e),(x1),(x2),(x3),(x4),(x5),0,&strerr_sys) +#define strerr_die4sys(e,x1,x2,x3,x4) \ +strerr_die((e),(x1),(x2),(x3),(x4),0,0,&strerr_sys) +#define strerr_die3sys(e,x1,x2,x3) \ +strerr_die((e),(x1),(x2),(x3),0,0,0,&strerr_sys) +#define strerr_die2sys(e,x1,x2) \ +strerr_die((e),(x1),(x2),0,0,0,0,&strerr_sys) +#define strerr_die1sys(e,x1) \ +strerr_die((e),(x1),0,0,0,0,0,&strerr_sys) + +#define strerr_die6x(e,x1,x2,x3,x4,x5,x6) \ +strerr_die((e),(x1),(x2),(x3),(x4),(x5),(x6),0) +#define strerr_die5x(e,x1,x2,x3,x4,x5) \ +strerr_die((e),(x1),(x2),(x3),(x4),(x5),0,0) +#define strerr_die4x(e,x1,x2,x3,x4) \ +strerr_die((e),(x1),(x2),(x3),(x4),0,0,0) +#define strerr_die3x(e,x1,x2,x3) \ +strerr_die((e),(x1),(x2),(x3),0,0,0,0) +#define strerr_die2x(e,x1,x2) \ +strerr_die((e),(x1),(x2),0,0,0,0,0) +#define strerr_die1x(e,x1) \ +strerr_die((e),(x1),0,0,0,0,0,0) + +#endif diff -BbrurN sendmail-8.12.7/makemap/strerr_sys.c sendmail-8.12.7-cdb-testbuild/makemap/strerr_sys.c --- sendmail-8.12.7/makemap/strerr_sys.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/strerr_sys.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,12 @@ +#include "error.h" +#include "strerr.h" + +struct strerr strerr_sys; + +void strerr_sysinit(void) +{ + strerr_sys.who = 0; + strerr_sys.x = error_str(errno); + strerr_sys.y = ""; + strerr_sys.z = ""; +} diff -BbrurN sendmail-8.12.7/makemap/str.h sendmail-8.12.7-cdb-testbuild/makemap/str.h --- sendmail-8.12.7/makemap/str.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/str.h 2003-01-29 01:23:17.000000000 +0800 @@ -0,0 +1,14 @@ +#ifndef STR_H +#define STR_H + +extern unsigned int str_copy(char *,char *); +extern int str_diff(char *,char *); +extern int str_diffn(char *,char *,unsigned int); +extern unsigned int str_len(char *); +extern unsigned int str_chr(char *,int); +extern unsigned int str_rchr(char *,int); +extern int str_start(char *,char *); + +#define str_equal(s,t) (!str_diff((s),(t))) + +#endif diff -BbrurN sendmail-8.12.7/makemap/str_len.c sendmail-8.12.7-cdb-testbuild/makemap/str_len.c --- sendmail-8.12.7/makemap/str_len.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/str_len.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,14 @@ +#include "str.h" + +unsigned int str_len(char *s) +{ + register char *t; + + t = s; + for (;;) { + if (!*t) return t - s; ++t; + if (!*t) return t - s; ++t; + if (!*t) return t - s; ++t; + if (!*t) return t - s; ++t; + } +} diff -BbrurN sendmail-8.12.7/makemap/testzero.c sendmail-8.12.7-cdb-testbuild/makemap/testzero.c --- sendmail-8.12.7/makemap/testzero.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/testzero.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,35 @@ +#include "uint32.h" +#include "scan.h" +#include "strerr.h" +#include "cdb_make.h" + +#define FATAL "testzero: fatal: " + +void die_write(void) +{ + strerr_die2sys(111,FATAL,"unable to write: "); +} + +static char key[4]; +static char data[65536]; +struct cdb_make c; + +main(int argc,char **argv) +{ + int fd; + unsigned long loop; + + if (!*argv) _exit(0); + if (!*++argv) _exit(0); + scan_ulong(*argv,&loop); + + if (cdb_make_start(&c,1) == -1) die_write(); + + while (loop) { + uint32_pack(key,--loop); + if (cdb_make_add(&c,key,4,data,sizeof data) == -1) die_write(); + } + + if (cdb_make_finish(&c) == -1) die_write(); + _exit(0); +} diff -BbrurN sendmail-8.12.7/makemap/trycpp.c sendmail-8.12.7-cdb-testbuild/makemap/trycpp.c --- sendmail-8.12.7/makemap/trycpp.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/trycpp.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,7 @@ +main() +{ +#ifdef NeXT + printf("nextstep\n"); exit(0); +#endif + printf("unknown\n"); exit(0); +} diff -BbrurN sendmail-8.12.7/makemap/tryulong32.c sendmail-8.12.7-cdb-testbuild/makemap/tryulong32.c --- sendmail-8.12.7/makemap/tryulong32.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/tryulong32.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,11 @@ +void main() +{ + unsigned long u; + u = 1; + u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; + u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; + u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; + u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; + if (!u) _exit(0); + _exit(1); +} diff -BbrurN sendmail-8.12.7/makemap/uint32.h sendmail-8.12.7-cdb-testbuild/makemap/uint32.h --- sendmail-8.12.7/makemap/uint32.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/uint32.h 2003-01-29 01:23:17.000000000 +0800 @@ -0,0 +1,11 @@ +#ifndef UINT32_H +#define UINT32_H + +typedef unsigned long uint32; + +extern void uint32_pack(char *,uint32); +extern void uint32_pack_big(char *,uint32); +extern void uint32_unpack(char *,uint32 *); +extern void uint32_unpack_big(char *,uint32 *); + +#endif diff -BbrurN sendmail-8.12.7/makemap/uint32_pack.c sendmail-8.12.7-cdb-testbuild/makemap/uint32_pack.c --- sendmail-8.12.7/makemap/uint32_pack.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/uint32_pack.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,21 @@ +#include "uint32.h" + +void uint32_pack(char s[4],uint32 u) +{ + s[0] = u & 255; + u >>= 8; + s[1] = u & 255; + u >>= 8; + s[2] = u & 255; + s[3] = u >> 8; +} + +void uint32_pack_big(char s[4],uint32 u) +{ + s[3] = u & 255; + u >>= 8; + s[2] = u & 255; + u >>= 8; + s[1] = u & 255; + s[0] = u >> 8; +} diff -BbrurN sendmail-8.12.7/makemap/uint32_unpack.c sendmail-8.12.7-cdb-testbuild/makemap/uint32_unpack.c --- sendmail-8.12.7/makemap/uint32_unpack.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/uint32_unpack.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,31 @@ +#include "uint32.h" + +void uint32_unpack(char s[4],uint32 *u) +{ + uint32 result; + + result = (unsigned char) s[3]; + result <<= 8; + result += (unsigned char) s[2]; + result <<= 8; + result += (unsigned char) s[1]; + result <<= 8; + result += (unsigned char) s[0]; + + *u = result; +} + +void uint32_unpack_big(char s[4],uint32 *u) +{ + uint32 result; + + result = (unsigned char) s[0]; + result <<= 8; + result += (unsigned char) s[1]; + result <<= 8; + result += (unsigned char) s[2]; + result <<= 8; + result += (unsigned char) s[3]; + + *u = result; +} diff -BbrurN sendmail-8.12.7/makemap/x86cpuid.c sendmail-8.12.7-cdb-testbuild/makemap/x86cpuid.c --- sendmail-8.12.7/makemap/x86cpuid.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/makemap/x86cpuid.c 2003-01-29 01:23:12.000000000 +0800 @@ -0,0 +1,38 @@ +#include + +void nope() +{ + exit(1); +} + +main() +{ + unsigned long x[4]; + unsigned long y[4]; + int i; + int j; + char c; + + signal(SIGILL,nope); + + x[0] = 0; + x[1] = 0; + x[2] = 0; + x[3] = 0; + + asm volatile(".byte 15;.byte 162" : "=a"(x[0]),"=b"(x[1]),"=c"(x[3]),"=d"(x[2]) : "0"(0) ); + if (!x[0]) return 0; + asm volatile(".byte 15;.byte 162" : "=a"(y[0]),"=b"(y[1]),"=c"(y[2]),"=d"(y[3]) : "0"(1) ); + + for (i = 1;i < 4;++i) + for (j = 0;j < 4;++j) { + c = x[i] >> (8 * j); + if (c < 32) c = 32; + if (c > 126) c = 126; + putchar(c); + } + + printf("-%08x-%08x\n",y[0],y[3]); + + return 0; +} diff -BbrurN sendmail-8.12.7/sendmail/alloc.c sendmail-8.12.7-cdb-testbuild/sendmail/alloc.c --- sendmail-8.12.7/sendmail/alloc.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/alloc.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,32 @@ +#include "alloc.h" +#include "error.h" +extern char *malloc(); +extern void free(); + +#define ALIGNMENT 16 /* XXX: assuming that this alignment is enough */ +#define SPACE 4096 /* must be multiple of ALIGNMENT */ + +typedef union { char irrelevant[ALIGNMENT]; double d; } aligned; +static aligned realspace[SPACE / ALIGNMENT]; +#define space ((char *) realspace) +static unsigned int avail = SPACE; /* multiple of ALIGNMENT; 0<=avail<=SPACE */ + +/*@null@*//*@out@*/char *alloc(n) +unsigned int n; +{ + char *x; + n = ALIGNMENT + n - (n & (ALIGNMENT - 1)); /* XXX: could overflow */ + if (n <= avail) { avail -= n; return space + avail; } + x = malloc(n); + if (!x) errno = error_nomem; + return x; +} + +void alloc_free(x) +char *x; +{ + if (x >= space) + if (x < space + SPACE) + return; /* XXX: assuming that pointers are flat */ + free(x); +} diff -BbrurN sendmail-8.12.7/sendmail/alloc.h sendmail-8.12.7-cdb-testbuild/sendmail/alloc.h --- sendmail-8.12.7/sendmail/alloc.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/alloc.h 2003-01-28 16:35:23.000000000 +0800 @@ -0,0 +1,8 @@ +#ifndef ALLOC_H +#define ALLOC_H + +extern /*@null@*//*@out@*/char *alloc(); +extern void alloc_free(); +extern int alloc_re(); + +#endif diff -BbrurN sendmail-8.12.7/sendmail/alloc_re.c sendmail-8.12.7-cdb-testbuild/sendmail/alloc_re.c --- sendmail-8.12.7/sendmail/alloc_re.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/alloc_re.c 2003-01-30 09:51:33.000000000 +0800 @@ -0,0 +1,17 @@ +#include "alloc.h" +#include "byte.h" + +int alloc_re(x,m,n) +char **x; +unsigned int m; +unsigned int n; +{ + char *y; + + y = alloc(n); + if (!y) return 0; + byte_copy(y,m,*x); + alloc_free(*x); + *x = y; + return 1; +} diff -BbrurN sendmail-8.12.7/sendmail/auto_home.c sendmail-8.12.7-cdb-testbuild/sendmail/auto_home.c --- sendmail-8.12.7/sendmail/auto_home.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/auto_home.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,3 @@ +char auto_home[] = "\ +\057\165\163\162\057\154\157\143\141\154\ +"; diff -BbrurN sendmail-8.12.7/sendmail/auto_home.h sendmail-8.12.7-cdb-testbuild/sendmail/auto_home.h --- sendmail-8.12.7/sendmail/auto_home.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/auto_home.h 2003-01-28 16:35:23.000000000 +0800 @@ -0,0 +1,6 @@ +#ifndef AUTO_HOME_H +#define AUTO_HOME_H + +extern char auto_home[]; + +#endif diff -BbrurN sendmail-8.12.7/sendmail/auto-str.c sendmail-8.12.7-cdb-testbuild/sendmail/auto-str.c --- sendmail-8.12.7/sendmail/auto-str.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/auto-str.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,44 @@ +#include "buffer.h" +#include "readwrite.h" +#include "exit.h" + +char buf1[256]; +buffer ss1 = BUFFER_INIT(write,1,buf1,sizeof(buf1)); + +void puts(s) +char *s; +{ + if (buffer_puts(&ss1,s) == -1) _exit(111); +} + +main(argc,argv) +int argc; +char **argv; +{ + char *name; + char *value; + unsigned char ch; + char octal[4]; + + name = argv[1]; + if (!name) _exit(100); + value = argv[2]; + if (!value) _exit(100); + + puts("char "); + puts(name); + puts("[] = \"\\\n"); + + while (ch = *value++) { + puts("\\"); + octal[3] = 0; + octal[2] = '0' + (ch & 7); ch >>= 3; + octal[1] = '0' + (ch & 7); ch >>= 3; + octal[0] = '0' + (ch & 7); + puts(octal); + } + + puts("\\\n\";\n"); + if (buffer_flush(&ss1) == -1) _exit(111); + _exit(0); +} diff -BbrurN sendmail-8.12.7/sendmail/buffer_0.c sendmail-8.12.7-cdb-testbuild/sendmail/buffer_0.c --- sendmail-8.12.7/sendmail/buffer_0.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/buffer_0.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,12 @@ +#include "readwrite.h" +#include "buffer.h" + +int buffer_0_read(fd,buf,len) int fd; char *buf; int len; +{ + if (buffer_flush(buffer_1) == -1) return -1; + return read(fd,buf,len); +} + +char buffer_0_space[BUFFER_INSIZE]; +static buffer it = BUFFER_INIT(buffer_0_read,0,buffer_0_space,sizeof buffer_0_space); +buffer *buffer_0 = ⁢ diff -BbrurN sendmail-8.12.7/sendmail/buffer_1.c sendmail-8.12.7-cdb-testbuild/sendmail/buffer_1.c --- sendmail-8.12.7/sendmail/buffer_1.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/buffer_1.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,6 @@ +#include "readwrite.h" +#include "buffer.h" + +char buffer_1_space[BUFFER_OUTSIZE]; +static buffer it = BUFFER_INIT(write,1,buffer_1_space,sizeof buffer_1_space); +buffer *buffer_1 = ⁢ diff -BbrurN sendmail-8.12.7/sendmail/buffer_1s.c sendmail-8.12.7-cdb-testbuild/sendmail/buffer_1s.c --- sendmail-8.12.7/sendmail/buffer_1s.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/buffer_1s.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,6 @@ +#include "readwrite.h" +#include "buffer.h" + +char buffer_1small_space[256]; +static buffer it = BUFFER_INIT(write,1,buffer_1small_space,sizeof buffer_1small_space); +buffer *buffer_1small = ⁢ diff -BbrurN sendmail-8.12.7/sendmail/buffer_2.c sendmail-8.12.7-cdb-testbuild/sendmail/buffer_2.c --- sendmail-8.12.7/sendmail/buffer_2.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/buffer_2.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,6 @@ +#include "readwrite.h" +#include "buffer.h" + +char buffer_2_space[256]; +static buffer it = BUFFER_INIT(write,2,buffer_2_space,sizeof buffer_2_space); +buffer *buffer_2 = ⁢ diff -BbrurN sendmail-8.12.7/sendmail/buffer.c sendmail-8.12.7-cdb-testbuild/sendmail/buffer.c --- sendmail-8.12.7/sendmail/buffer.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/buffer.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,10 @@ +#include "buffer.h" + +void buffer_init(buffer *s,int (*op)(),int fd,char *buf,unsigned int len) +{ + s->x = buf; + s->fd = fd; + s->op = op; + s->p = 0; + s->n = len; +} diff -BbrurN sendmail-8.12.7/sendmail/buffer_copy.c sendmail-8.12.7-cdb-testbuild/sendmail/buffer_copy.c --- sendmail-8.12.7/sendmail/buffer_copy.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/buffer_copy.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,16 @@ +#include "buffer.h" + +int buffer_copy(buffer *bout,buffer *bin) +{ + int n; + char *x; + + for (;;) { + n = buffer_feed(bin); + if (n < 0) return -2; + if (!n) return 0; + x = buffer_PEEK(bin); + if (buffer_put(bout,x,n) == -1) return -3; + buffer_SEEK(bin,n); + } +} diff -BbrurN sendmail-8.12.7/sendmail/buffer_get.c sendmail-8.12.7-cdb-testbuild/sendmail/buffer_get.c --- sendmail-8.12.7/sendmail/buffer_get.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/buffer_get.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,67 @@ +#include "buffer.h" +#include "byte.h" +#include "error.h" + +static int oneread(int (*op)(),int fd,char *buf,unsigned int len) +{ + int r; + + for (;;) { + r = op(fd,buf,len); + if (r == -1) if (errno == error_intr) continue; + return r; + } +} + +static int getthis(buffer *s,char *buf,unsigned int len) +{ + if (len > s->p) len = s->p; + s->p -= len; + byte_copy(buf,len,s->x + s->n); + s->n += len; + return len; +} + +int buffer_feed(buffer *s) +{ + int r; + + if (s->p) return s->p; + r = oneread(s->op,s->fd,s->x,s->n); + if (r <= 0) return r; + s->p = r; + s->n -= r; + if (s->n > 0) byte_copyr(s->x + s->n,r,s->x); + return r; +} + +int buffer_bget(buffer *s,char *buf,unsigned int len) +{ + int r; + + if (s->p > 0) return getthis(s,buf,len); + if (s->n <= len) return oneread(s->op,s->fd,buf,s->n); + r = buffer_feed(s); if (r <= 0) return r; + return getthis(s,buf,len); +} + +int buffer_get(buffer *s,char *buf,unsigned int len) +{ + int r; + + if (s->p > 0) return getthis(s,buf,len); + if (s->n <= len) return oneread(s->op,s->fd,buf,len); + r = buffer_feed(s); if (r <= 0) return r; + return getthis(s,buf,len); +} + +char *buffer_peek(buffer *s) +{ + return s->x + s->n; +} + +void buffer_seek(buffer *s,unsigned int len) +{ + s->n += len; + s->p -= len; +} diff -BbrurN sendmail-8.12.7/sendmail/buffer.h sendmail-8.12.7-cdb-testbuild/sendmail/buffer.h --- sendmail-8.12.7/sendmail/buffer.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/buffer.h 2003-01-28 16:35:23.000000000 +0800 @@ -0,0 +1,56 @@ +#ifndef BUFFER_H +#define BUFFER_H + +typedef struct buffer { + char *x; + unsigned int p; + unsigned int n; + int fd; + int (*op)(); +} buffer; + +#define BUFFER_INIT(op,fd,buf,len) { (buf), 0, (len), (fd), (op) } +#define BUFFER_INSIZE 8192 +#define BUFFER_OUTSIZE 8192 + +extern void buffer_init(buffer *,int (*)(),int,char *,unsigned int); + +extern int buffer_flush(buffer *); +extern int buffer_put(buffer *,char *,unsigned int); +extern int buffer_putalign(buffer *,char *,unsigned int); +extern int buffer_putflush(buffer *,char *,unsigned int); +extern int buffer_puts(buffer *,char *); +extern int buffer_putsalign(buffer *,char *); +extern int buffer_putsflush(buffer *,char *); + +#define buffer_PUTC(s,c) \ + ( ((s)->n != (s)->p) \ + ? ( (s)->x[(s)->p++] = (c), 0 ) \ + : buffer_put((s),&(c),1) \ + ) + +extern int buffer_get(buffer *,char *,unsigned int); +extern int buffer_bget(buffer *,char *,unsigned int); +extern int buffer_feed(buffer *); + +extern char *buffer_peek(buffer *); +extern void buffer_seek(buffer *,unsigned int); + +#define buffer_PEEK(s) ( (s)->x + (s)->n ) +#define buffer_SEEK(s,len) ( ( (s)->p -= (len) ) , ( (s)->n += (len) ) ) + +#define buffer_GETC(s,c) \ + ( ((s)->p > 0) \ + ? ( *(c) = (s)->x[(s)->n], buffer_SEEK((s),1), 1 ) \ + : buffer_get((s),(c),1) \ + ) + +extern int buffer_copy(buffer *,buffer *); + +extern buffer *buffer_0; +extern buffer *buffer_0small; +extern buffer *buffer_1; +extern buffer *buffer_1small; +extern buffer *buffer_2; + +#endif diff -BbrurN sendmail-8.12.7/sendmail/buffer_put.c sendmail-8.12.7-cdb-testbuild/sendmail/buffer_put.c --- sendmail-8.12.7/sendmail/buffer_put.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/buffer_put.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,88 @@ +#include "buffer.h" +#include "str.h" +#include "byte.h" +#include "error.h" + +static int allwrite(int (*op)(),int fd,char *buf,unsigned int len) +{ + int w; + + while (len) { + w = op(fd,buf,len); + if (w == -1) { + if (errno == error_intr) continue; + return -1; /* note that some data may have been written */ + } + if (w == 0) ; /* luser's fault */ + buf += w; + len -= w; + } + return 0; +} + +int buffer_flush(buffer *s) +{ + int p; + + p = s->p; + if (!p) return 0; + s->p = 0; + return allwrite(s->op,s->fd,s->x,p); +} + +int buffer_putalign(buffer *s,char *buf,unsigned int len) +{ + unsigned int n; + + while (len > (n = s->n - s->p)) { + byte_copy(s->x + s->p,n,buf); s->p += n; buf += n; len -= n; + if (buffer_flush(s) == -1) return -1; + } + /* now len <= s->n - s->p */ + byte_copy(s->x + s->p,len,buf); + s->p += len; + return 0; +} + +int buffer_put(buffer *s,char *buf,unsigned int len) +{ + unsigned int n; + + n = s->n; + if (len > n - s->p) { + if (buffer_flush(s) == -1) return -1; + /* now s->p == 0 */ + if (n < BUFFER_OUTSIZE) n = BUFFER_OUTSIZE; + while (len > s->n) { + if (n > len) n = len; + if (allwrite(s->op,s->fd,buf,n) == -1) return -1; + buf += n; + len -= n; + } + } + /* now len <= s->n - s->p */ + byte_copy(s->x + s->p,len,buf); + s->p += len; + return 0; +} + +int buffer_putflush(buffer *s,char *buf,unsigned int len) +{ + if (buffer_flush(s) == -1) return -1; + return allwrite(s->op,s->fd,buf,len); +} + +int buffer_putsalign(buffer *s,char *buf) +{ + return buffer_putalign(s,buf,str_len(buf)); +} + +int buffer_puts(buffer *s,char *buf) +{ + return buffer_put(s,buf,str_len(buf)); +} + +int buffer_putsflush(buffer *s,char *buf) +{ + return buffer_putflush(s,buf,str_len(buf)); +} diff -BbrurN sendmail-8.12.7/sendmail/byte_copy.c sendmail-8.12.7-cdb-testbuild/sendmail/byte_copy.c --- sendmail-8.12.7/sendmail/byte_copy.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/byte_copy.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,14 @@ +#include "byte.h" + +void byte_copy(to,n,from) +register char *to; +register unsigned int n; +register char *from; +{ + for (;;) { + if (!n) return; *to++ = *from++; --n; + if (!n) return; *to++ = *from++; --n; + if (!n) return; *to++ = *from++; --n; + if (!n) return; *to++ = *from++; --n; + } +} diff -BbrurN sendmail-8.12.7/sendmail/byte_cr.c sendmail-8.12.7-cdb-testbuild/sendmail/byte_cr.c --- sendmail-8.12.7/sendmail/byte_cr.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/byte_cr.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,16 @@ +#include "byte.h" + +void byte_copyr(to,n,from) +register char *to; +register unsigned int n; +register char *from; +{ + to += n; + from += n; + for (;;) { + if (!n) return; *--to = *--from; --n; + if (!n) return; *--to = *--from; --n; + if (!n) return; *--to = *--from; --n; + if (!n) return; *--to = *--from; --n; + } +} diff -BbrurN sendmail-8.12.7/sendmail/byte_diff.c sendmail-8.12.7-cdb-testbuild/sendmail/byte_diff.c --- sendmail-8.12.7/sendmail/byte_diff.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/byte_diff.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,16 @@ +#include "byte.h" + +int byte_diff(s,n,t) +register char *s; +register unsigned int n; +register char *t; +{ + for (;;) { + if (!n) return 0; if (*s != *t) break; ++s; ++t; --n; + if (!n) return 0; if (*s != *t) break; ++s; ++t; --n; + if (!n) return 0; if (*s != *t) break; ++s; ++t; --n; + if (!n) return 0; if (*s != *t) break; ++s; ++t; --n; + } + return ((int)(unsigned int)(unsigned char) *s) + - ((int)(unsigned int)(unsigned char) *t); +} diff -BbrurN sendmail-8.12.7/sendmail/byte.h sendmail-8.12.7-cdb-testbuild/sendmail/byte.h --- sendmail-8.12.7/sendmail/byte.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/byte.h 2003-01-28 16:35:23.000000000 +0800 @@ -0,0 +1,13 @@ +#ifndef BYTE_H +#define BYTE_H + +extern unsigned int byte_chr(); +extern unsigned int byte_rchr(); +extern void byte_copy(); +extern void byte_copyr(); +extern int byte_diff(); +extern void byte_zero(); + +#define byte_equal(s,n,t) (!byte_diff((s),(n),(t))) + +#endif diff -BbrurN sendmail-8.12.7/sendmail/cdb.c sendmail-8.12.7-cdb-testbuild/sendmail/cdb.c --- sendmail-8.12.7/sendmail/cdb.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/cdb.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,136 @@ +/* Public domain. */ + +#include +#include +#include +#include "readwrite.h" +#include "error.h" +#include "seek.h" +#include "byte.h" +#include "cdb.h" + +void cdb_free(struct cdb *c) +{ + if (c->map) { + munmap(c->map,c->size); + c->map = 0; + } +} + +void cdb_findstart(struct cdb *c) +{ + c->loop = 0; +} + +void cdb_init(struct cdb *c,int fd) +{ + struct stat st; + char *x; + + cdb_free(c); + cdb_findstart(c); + c->fd = fd; + + if (fstat(fd,&st) == 0) + if (st.st_size <= 0xffffffff) { + x = mmap(0,st.st_size,PROT_READ,MAP_SHARED,fd,0); + if (x + 1) { + c->size = st.st_size; + c->map = x; + } + } +} + +int cdb_read(struct cdb *c,char *buf,unsigned int len,uint32 pos) +{ + if (c->map) { + if ((pos > c->size) || (c->size - pos < len)) goto FORMAT; + byte_copy(buf,len,c->map + pos); + } + else { + if (seek_set(c->fd,pos) == -1) return -1; + while (len > 0) { + int r; + do + r = read(c->fd,buf,len); + while ((r == -1) && (errno == error_intr)); + if (r == -1) return -1; + if (r == 0) goto FORMAT; + buf += r; + len -= r; + } + } + return 0; + + FORMAT: + errno = error_proto; + return -1; +} + +static int match(struct cdb *c,char *key,unsigned int len,uint32 pos) +{ + char buf[32]; + int n; + + while (len > 0) { + n = sizeof buf; + if (n > len) n = len; + if (cdb_read(c,buf,n,pos) == -1) return -1; + if (byte_diff(buf,n,key)) return 0; + pos += n; + key += n; + len -= n; + } + return 1; +} + +int cdb_findnext(struct cdb *c,char *key,unsigned int len) +{ + char buf[8]; + uint32 pos; + uint32 u; + + if (!c->loop) { + u = cdb_hash(key,len); + if (cdb_read(c,buf,8,(u << 3) & 2047) == -1) return -1; + uint32_unpack(buf + 4,&c->hslots); + if (!c->hslots) return 0; + uint32_unpack(buf,&c->hpos); + c->khash = u; + u >>= 8; + u %= c->hslots; + u <<= 3; + c->kpos = c->hpos + u; + } + + while (c->loop < c->hslots) { + if (cdb_read(c,buf,8,c->kpos) == -1) return -1; + uint32_unpack(buf + 4,&pos); + if (!pos) return 0; + c->loop += 1; + c->kpos += 8; + if (c->kpos == c->hpos + (c->hslots << 3)) c->kpos = c->hpos; + uint32_unpack(buf,&u); + if (u == c->khash) { + if (cdb_read(c,buf,8,pos) == -1) return -1; + uint32_unpack(buf,&u); + if (u == len) + switch(match(c,key,len,pos + 8)) { + case -1: + return -1; + case 1: + uint32_unpack(buf + 4,&c->dlen); + c->dpos = pos + 8 + len; + return 1; + } + } + } + + return 0; +} + +int cdb_find(struct cdb *c,char *key,unsigned int len) +{ + cdb_findstart(c); + return cdb_findnext(c,key,len); +} diff -BbrurN sendmail-8.12.7/sendmail/cdb.h sendmail-8.12.7-cdb-testbuild/sendmail/cdb.h --- sendmail-8.12.7/sendmail/cdb.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/cdb.h 2003-01-28 16:35:23.000000000 +0800 @@ -0,0 +1,37 @@ +/* Public domain. */ + +#ifndef CDB_H +#define CDB_H + +#include "uint32.h" + +#define CDB_HASHSTART 5381 +extern uint32 cdb_hashadd(uint32,unsigned char); +extern uint32 cdb_hash(char *,unsigned int); + +struct cdb { + char *map; /* 0 if no map is available */ + int fd; + uint32 size; /* initialized if map is nonzero */ + uint32 loop; /* number of hash slots searched under this key */ + uint32 khash; /* initialized if loop is nonzero */ + uint32 kpos; /* initialized if loop is nonzero */ + uint32 hpos; /* initialized if loop is nonzero */ + uint32 hslots; /* initialized if loop is nonzero */ + uint32 dpos; /* initialized if cdb_findnext() returns 1 */ + uint32 dlen; /* initialized if cdb_findnext() returns 1 */ +} ; + +extern void cdb_free(struct cdb *); +extern void cdb_init(struct cdb *,int fd); + +extern int cdb_read(struct cdb *,char *,unsigned int,uint32); + +extern void cdb_findstart(struct cdb *); +extern int cdb_findnext(struct cdb *,char *,unsigned int); +extern int cdb_find(struct cdb *,char *,unsigned int); + +#define cdb_datapos(c) ((c)->dpos) +#define cdb_datalen(c) ((c)->dlen) + +#endif diff -BbrurN sendmail-8.12.7/sendmail/cdb_hash.c sendmail-8.12.7-cdb-testbuild/sendmail/cdb_hash.c --- sendmail-8.12.7/sendmail/cdb_hash.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/cdb_hash.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,21 @@ +/* Public domain. */ + +#include "cdb.h" + +uint32 cdb_hashadd(uint32 h,unsigned char c) +{ + h += (h << 5); + return h ^ c; +} + +uint32 cdb_hash(char *buf,unsigned int len) +{ + uint32 h; + + h = CDB_HASHSTART; + while (len) { + h = cdb_hashadd(h,*buf++); + --len; + } + return h; +} diff -BbrurN sendmail-8.12.7/sendmail/cdb_make.c sendmail-8.12.7-cdb-testbuild/sendmail/cdb_make.c --- sendmail-8.12.7/sendmail/cdb_make.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/cdb_make.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,153 @@ +/* Public domain. */ + +#include "readwrite.h" +#include "seek.h" +#include "error.h" +#include "alloc.h" +#include "cdb.h" +#include "cdb_make.h" + +int cdb_make_start(struct cdb_make *c,int fd) +{ + c->head = 0; + c->split = 0; + c->hash = 0; + c->numentries = 0; + c->fd = fd; + c->pos = sizeof c->final; + buffer_init(&c->b,write,fd,c->bspace,sizeof c->bspace); + return seek_set(fd,c->pos); +} + +static int posplus(struct cdb_make *c,uint32 len) +{ + uint32 newpos = c->pos + len; + if (newpos < len) { errno = error_nomem; return -1; } + c->pos = newpos; + return 0; +} + +int cdb_make_addend(struct cdb_make *c,unsigned int keylen,unsigned int datalen,uint32 h) +{ + struct cdb_hplist *head; + + head = c->head; + if (!head || (head->num >= CDB_HPLIST)) { + head = (struct cdb_hplist *) alloc(sizeof(struct cdb_hplist)); + if (!head) return -1; + head->num = 0; + head->next = c->head; + c->head = head; + } + head->hp[head->num].h = h; + head->hp[head->num].p = c->pos; + ++head->num; + ++c->numentries; + if (posplus(c,8) == -1) return -1; + if (posplus(c,keylen) == -1) return -1; + if (posplus(c,datalen) == -1) return -1; + return 0; +} + +int cdb_make_addbegin(struct cdb_make *c,unsigned int keylen,unsigned int datalen) +{ + char buf[8]; + + if (keylen > 0xffffffff) { errno = error_nomem; return -1; } + if (datalen > 0xffffffff) { errno = error_nomem; return -1; } + + uint32_pack(buf,keylen); + uint32_pack(buf + 4,datalen); + if (buffer_putalign(&c->b,buf,8) == -1) return -1; + return 0; +} + +int cdb_make_add(struct cdb_make *c,char *key,unsigned int keylen,char *data,unsigned int datalen) +{ + if (cdb_make_addbegin(c,keylen,datalen) == -1) return -1; + if (buffer_putalign(&c->b,key,keylen) == -1) return -1; + if (buffer_putalign(&c->b,data,datalen) == -1) return -1; + return cdb_make_addend(c,keylen,datalen,cdb_hash(key,keylen)); +} + +int cdb_make_finish(struct cdb_make *c) +{ + char buf[8]; + int i; + uint32 len; + uint32 u; + uint32 memsize; + uint32 count; + uint32 where; + struct cdb_hplist *x; + struct cdb_hp *hp; + + for (i = 0;i < 256;++i) + c->count[i] = 0; + + for (x = c->head;x;x = x->next) { + i = x->num; + while (i--) + ++c->count[255 & x->hp[i].h]; + } + + memsize = 1; + for (i = 0;i < 256;++i) { + u = c->count[i] * 2; + if (u > memsize) + memsize = u; + } + + memsize += c->numentries; /* no overflow possible up to now */ + u = (uint32) 0 - (uint32) 1; + u /= sizeof(struct cdb_hp); + if (memsize > u) { errno = error_nomem; return -1; } + + c->split = (struct cdb_hp *) alloc(memsize * sizeof(struct cdb_hp)); + if (!c->split) return -1; + + c->hash = c->split + c->numentries; + + u = 0; + for (i = 0;i < 256;++i) { + u += c->count[i]; /* bounded by numentries, so no overflow */ + c->start[i] = u; + } + + for (x = c->head;x;x = x->next) { + i = x->num; + while (i--) + c->split[--c->start[255 & x->hp[i].h]] = x->hp[i]; + } + + for (i = 0;i < 256;++i) { + count = c->count[i]; + + len = count + count; /* no overflow possible */ + uint32_pack(c->final + 8 * i,c->pos); + uint32_pack(c->final + 8 * i + 4,len); + + for (u = 0;u < len;++u) + c->hash[u].h = c->hash[u].p = 0; + + hp = c->split + c->start[i]; + for (u = 0;u < count;++u) { + where = (hp->h >> 8) % len; + while (c->hash[where].p) + if (++where == len) + where = 0; + c->hash[where] = *hp++; + } + + for (u = 0;u < len;++u) { + uint32_pack(buf,c->hash[u].h); + uint32_pack(buf + 4,c->hash[u].p); + if (buffer_putalign(&c->b,buf,8) == -1) return -1; + if (posplus(c,8) == -1) return -1; + } + } + + if (buffer_flush(&c->b) == -1) return -1; + if (seek_begin(c->fd) == -1) return -1; + return buffer_putflush(&c->b,c->final,sizeof c->final); +} diff -BbrurN sendmail-8.12.7/sendmail/cdb_make.h sendmail-8.12.7-cdb-testbuild/sendmail/cdb_make.h --- sendmail-8.12.7/sendmail/cdb_make.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/cdb_make.h 2003-01-28 16:35:23.000000000 +0800 @@ -0,0 +1,39 @@ +/* Public domain. */ + +#ifndef CDB_MAKE_H +#define CDB_MAKE_H + +#include "buffer.h" +#include "uint32.h" + +#define CDB_HPLIST 1000 + +struct cdb_hp { uint32 h; uint32 p; } ; + +struct cdb_hplist { + struct cdb_hp hp[CDB_HPLIST]; + struct cdb_hplist *next; + int num; +} ; + +struct cdb_make { + char bspace[8192]; + char final[2048]; + uint32 count[256]; + uint32 start[256]; + struct cdb_hplist *head; + struct cdb_hp *split; /* includes space for hash */ + struct cdb_hp *hash; + uint32 numentries; + buffer b; + uint32 pos; + int fd; +} ; + +extern int cdb_make_start(struct cdb_make *,int); +extern int cdb_make_addbegin(struct cdb_make *,unsigned int,unsigned int); +extern int cdb_make_addend(struct cdb_make *,unsigned int,unsigned int,uint32); +extern int cdb_make_add(struct cdb_make *,char *,unsigned int,char *,unsigned int); +extern int cdb_make_finish(struct cdb_make *); + +#endif diff -BbrurN sendmail-8.12.7/sendmail/conf.c sendmail-8.12.7-cdb-testbuild/sendmail/conf.c --- sendmail-8.12.7/sendmail/conf.c 2002-12-13 05:19:29.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/conf.c 2003-01-28 16:41:40.000000000 +0800 @@ -478,6 +478,12 @@ ndbm_map_lookup, ndbm_map_store); #endif /* NDBM */ +#if CDB + MAPDEF("cdb", ".cdb", MCF_ALIASOK|MCF_REBUILDABLE, + map_parseargs, cdb_map_open, cdb_map_close, + cdb_map_lookup, cdb_map_store); +#endif + #if NIS MAPDEF("nis", NULL, MCF_ALIASOK, map_parseargs, nis_map_open, null_map_close, @@ -5605,6 +5611,9 @@ #if NEWDB "NEWDB", #endif /* NEWDB */ +#if CDB + "CDB", +#endif #if NIS "NIS", #endif /* NIS */ diff -BbrurN sendmail-8.12.7/sendmail/error.c sendmail-8.12.7-cdb-testbuild/sendmail/error.c --- sendmail-8.12.7/sendmail/error.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/error.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,109 @@ +#include +#include "error.h" + +/* warning: as coverage improves here, should update error_{str,temp} */ + +int error_intr = +#ifdef EINTR +EINTR; +#else +-1; +#endif + +int error_nomem = +#ifdef ENOMEM +ENOMEM; +#else +-2; +#endif + +int error_noent = +#ifdef ENOENT +ENOENT; +#else +-3; +#endif + +int error_txtbsy = +#ifdef ETXTBSY +ETXTBSY; +#else +-4; +#endif + +int error_io = +#ifdef EIO +EIO; +#else +-5; +#endif + +int error_exist = +#ifdef EEXIST +EEXIST; +#else +-6; +#endif + +int error_timeout = +#ifdef ETIMEDOUT +ETIMEDOUT; +#else +-7; +#endif + +int error_inprogress = +#ifdef EINPROGRESS +EINPROGRESS; +#else +-8; +#endif + +int error_wouldblock = +#ifdef EWOULDBLOCK +EWOULDBLOCK; +#else +-9; +#endif + +int error_again = +#ifdef EAGAIN +EAGAIN; +#else +-10; +#endif + +int error_pipe = +#ifdef EPIPE +EPIPE; +#else +-11; +#endif + +int error_perm = +#ifdef EPERM +EPERM; +#else +-12; +#endif + +int error_acces = +#ifdef EACCES +EACCES; +#else +-13; +#endif + +int error_nodevice = +#ifdef ENXIO +ENXIO; +#else +-14; +#endif + +int error_proto = +#ifdef EPROTO +EPROTO; +#else +-15; +#endif diff -BbrurN sendmail-8.12.7/sendmail/error.h sendmail-8.12.7-cdb-testbuild/sendmail/error.h --- sendmail-8.12.7/sendmail/error.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/error.h 2003-01-28 16:35:23.000000000 +0800 @@ -0,0 +1,25 @@ +#ifndef ERROR_H +#define ERROR_H + +extern int errno; + +extern int error_intr; +extern int error_nomem; +extern int error_noent; +extern int error_txtbsy; +extern int error_io; +extern int error_exist; +extern int error_timeout; +extern int error_inprogress; +extern int error_wouldblock; +extern int error_again; +extern int error_pipe; +extern int error_perm; +extern int error_acces; +extern int error_nodevice; +extern int error_proto; + +extern char *error_str(int); +extern int error_temp(int); + +#endif diff -BbrurN sendmail-8.12.7/sendmail/error_str.c sendmail-8.12.7-cdb-testbuild/sendmail/error_str.c --- sendmail-8.12.7/sendmail/error_str.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/error_str.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,271 @@ +#include +#include "error.h" + +#define X(e,s) if (i == e) return s; + +char *error_str(int i) +{ + X(0,"no error") + X(error_intr,"interrupted system call") + X(error_nomem,"out of memory") + X(error_noent,"file does not exist") + X(error_txtbsy,"text busy") + X(error_io,"input/output error") + X(error_exist,"file already exists") + X(error_timeout,"timed out") + X(error_inprogress,"operation in progress") + X(error_again,"temporary failure") + X(error_wouldblock,"input/output would block") + X(error_pipe,"broken pipe") + X(error_perm,"permission denied") + X(error_acces,"access denied") + X(error_nodevice,"device not configured") + X(error_proto,"protocol error") +#ifdef ESRCH + X(ESRCH,"no such process") +#endif +#ifdef E2BIG + X(E2BIG,"argument list too long") +#endif +#ifdef ENOEXEC + X(ENOEXEC,"exec format error") +#endif +#ifdef EBADF + X(EBADF,"file descriptor not open") +#endif +#ifdef ECHILD + X(ECHILD,"no child processes") +#endif +#ifdef EDEADLK + X(EDEADLK,"operation would cause deadlock") +#endif +#ifdef EFAULT + X(EFAULT,"bad address") +#endif +#ifdef ENOTBLK + X(ENOTBLK,"not a block device") +#endif +#ifdef EBUSY + X(EBUSY,"device busy") +#endif +#ifdef EXDEV + X(EXDEV,"cross-device link") +#endif +#ifdef ENODEV + X(ENODEV,"device does not support operation") +#endif +#ifdef ENOTDIR + X(ENOTDIR,"not a directory") +#endif +#ifdef EISDIR + X(EISDIR,"is a directory") +#endif +#ifdef EINVAL + X(EINVAL,"invalid argument") +#endif +#ifdef ENFILE + X(ENFILE,"system cannot open more files") +#endif +#ifdef EMFILE + X(EMFILE,"process cannot open more files") +#endif +#ifdef ENOTTY + X(ENOTTY,"not a tty") +#endif +#ifdef EFBIG + X(EFBIG,"file too big") +#endif +#ifdef ENOSPC + X(ENOSPC,"out of disk space") +#endif +#ifdef ESPIPE + X(ESPIPE,"unseekable descriptor") +#endif +#ifdef EROFS + X(EROFS,"read-only file system") +#endif +#ifdef EMLINK + X(EMLINK,"too many links") +#endif +#ifdef EDOM + X(EDOM,"input out of range") +#endif +#ifdef ERANGE + X(ERANGE,"output out of range") +#endif +#ifdef EALREADY + X(EALREADY,"operation already in progress") +#endif +#ifdef ENOTSOCK + X(ENOTSOCK,"not a socket") +#endif +#ifdef EDESTADDRREQ + X(EDESTADDRREQ,"destination address required") +#endif +#ifdef EMSGSIZE + X(EMSGSIZE,"message too long") +#endif +#ifdef EPROTOTYPE + X(EPROTOTYPE,"incorrect protocol type") +#endif +#ifdef ENOPROTOOPT + X(ENOPROTOOPT,"protocol not available") +#endif +#ifdef EPROTONOSUPPORT + X(EPROTONOSUPPORT,"protocol not supported") +#endif +#ifdef ESOCKTNOSUPPORT + X(ESOCKTNOSUPPORT,"socket type not supported") +#endif +#ifdef EOPNOTSUPP + X(EOPNOTSUPP,"operation not supported") +#endif +#ifdef EPFNOSUPPORT + X(EPFNOSUPPORT,"protocol family not supported") +#endif +#ifdef EAFNOSUPPORT + X(EAFNOSUPPORT,"address family not supported") +#endif +#ifdef EADDRINUSE + X(EADDRINUSE,"address already used") +#endif +#ifdef EADDRNOTAVAIL + X(EADDRNOTAVAIL,"address not available") +#endif +#ifdef ENETDOWN + X(ENETDOWN,"network down") +#endif +#ifdef ENETUNREACH + X(ENETUNREACH,"network unreachable") +#endif +#ifdef ENETRESET + X(ENETRESET,"network reset") +#endif +#ifdef ECONNABORTED + X(ECONNABORTED,"connection aborted") +#endif +#ifdef ECONNRESET + X(ECONNRESET,"connection reset") +#endif +#ifdef ENOBUFS + X(ENOBUFS,"out of buffer space") +#endif +#ifdef EISCONN + X(EISCONN,"already connected") +#endif +#ifdef ENOTCONN + X(ENOTCONN,"not connected") +#endif +#ifdef ESHUTDOWN + X(ESHUTDOWN,"socket shut down") +#endif +#ifdef ETOOMANYREFS + X(ETOOMANYREFS,"too many references") +#endif +#ifdef ECONNREFUSED + X(ECONNREFUSED,"connection refused") +#endif +#ifdef ELOOP + X(ELOOP,"symbolic link loop") +#endif +#ifdef ENAMETOOLONG + X(ENAMETOOLONG,"file name too long") +#endif +#ifdef EHOSTDOWN + X(EHOSTDOWN,"host down") +#endif +#ifdef EHOSTUNREACH + X(EHOSTUNREACH,"host unreachable") +#endif +#ifdef ENOTEMPTY + X(ENOTEMPTY,"directory not empty") +#endif +#ifdef EPROCLIM + X(EPROCLIM,"too many processes") +#endif +#ifdef EUSERS + X(EUSERS,"too many users") +#endif +#ifdef EDQUOT + X(EDQUOT,"disk quota exceeded") +#endif +#ifdef ESTALE + X(ESTALE,"stale NFS file handle") +#endif +#ifdef EREMOTE + X(EREMOTE,"too many levels of remote in path") +#endif +#ifdef EBADRPC + X(EBADRPC,"RPC structure is bad") +#endif +#ifdef ERPCMISMATCH + X(ERPCMISMATCH,"RPC version mismatch") +#endif +#ifdef EPROGUNAVAIL + X(EPROGUNAVAIL,"RPC program unavailable") +#endif +#ifdef EPROGMISMATCH + X(EPROGMISMATCH,"program version mismatch") +#endif +#ifdef EPROCUNAVAIL + X(EPROCUNAVAIL,"bad procedure for program") +#endif +#ifdef ENOLCK + X(ENOLCK,"no locks available") +#endif +#ifdef ENOSYS + X(ENOSYS,"system call not available") +#endif +#ifdef EFTYPE + X(EFTYPE,"bad file type") +#endif +#ifdef EAUTH + X(EAUTH,"authentication error") +#endif +#ifdef ENEEDAUTH + X(ENEEDAUTH,"not authenticated") +#endif +#ifdef ENOSTR + X(ENOSTR,"not a stream device") +#endif +#ifdef ETIME + X(ETIME,"timer expired") +#endif +#ifdef ENOSR + X(ENOSR,"out of stream resources") +#endif +#ifdef ENOMSG + X(ENOMSG,"no message of desired type") +#endif +#ifdef EBADMSG + X(EBADMSG,"bad message type") +#endif +#ifdef EIDRM + X(EIDRM,"identifier removed") +#endif +#ifdef ENONET + X(ENONET,"machine not on network") +#endif +#ifdef ERREMOTE + X(ERREMOTE,"object not local") +#endif +#ifdef ENOLINK + X(ENOLINK,"link severed") +#endif +#ifdef EADV + X(EADV,"advertise error") +#endif +#ifdef ESRMNT + X(ESRMNT,"srmount error") +#endif +#ifdef ECOMM + X(ECOMM,"communication error") +#endif +#ifdef EMULTIHOP + X(EMULTIHOP,"multihop attempted") +#endif +#ifdef EREMCHG + X(EREMCHG,"remote address changed") +#endif + return "unknown error"; +} diff -BbrurN sendmail-8.12.7/sendmail/exit.h sendmail-8.12.7-cdb-testbuild/sendmail/exit.h --- sendmail-8.12.7/sendmail/exit.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/exit.h 2003-01-28 16:35:23.000000000 +0800 @@ -0,0 +1,6 @@ +#ifndef EXIT_H +#define EXIT_H + +extern void _exit(); + +#endif diff -BbrurN sendmail-8.12.7/sendmail/fmt.h sendmail-8.12.7-cdb-testbuild/sendmail/fmt.h --- sendmail-8.12.7/sendmail/fmt.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/fmt.h 2003-01-28 16:35:23.000000000 +0800 @@ -0,0 +1,25 @@ +#ifndef FMT_H +#define FMT_H + +#define FMT_ULONG 40 /* enough space to hold 2^128 - 1 in decimal, plus \0 */ +#define FMT_LEN ((char *) 0) /* convenient abbreviation */ + +extern unsigned int fmt_uint(char *,unsigned int); +extern unsigned int fmt_uint0(char *,unsigned int,unsigned int); +extern unsigned int fmt_xint(char *,unsigned int); +extern unsigned int fmt_nbbint(char *,unsigned int,unsigned int,unsigned int,unsigned int); +extern unsigned int fmt_ushort(char *,unsigned short); +extern unsigned int fmt_xshort(char *,unsigned short); +extern unsigned int fmt_nbbshort(char *,unsigned int,unsigned int,unsigned int,unsigned short); +extern unsigned int fmt_ulong(char *,unsigned long); +extern unsigned int fmt_xlong(char *,unsigned long); +extern unsigned int fmt_nbblong(char *,unsigned int,unsigned int,unsigned int,unsigned long); + +extern unsigned int fmt_plusminus(char *,int); +extern unsigned int fmt_minus(char *,int); +extern unsigned int fmt_0x(char *,int); + +extern unsigned int fmt_str(char *,char *); +extern unsigned int fmt_strn(char *,char *,unsigned int); + +#endif diff -BbrurN sendmail-8.12.7/sendmail/fmt_ulong.c sendmail-8.12.7-cdb-testbuild/sendmail/fmt_ulong.c --- sendmail-8.12.7/sendmail/fmt_ulong.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/fmt_ulong.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,13 @@ +#include "fmt.h" + +unsigned int fmt_ulong(register char *s,register unsigned long u) +{ + register unsigned int len; register unsigned long q; + len = 1; q = u; + while (q > 9) { ++len; q /= 10; } + if (s) { + s += len; + do { *--s = '0' + (u % 10); u /= 10; } while(u); /* handles u == 0 */ + } + return len; +} diff -BbrurN sendmail-8.12.7/sendmail/gen_allocdefs.h sendmail-8.12.7-cdb-testbuild/sendmail/gen_allocdefs.h --- sendmail-8.12.7/sendmail/gen_allocdefs.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/gen_allocdefs.h 2003-01-30 09:53:21.000000000 +0800 @@ -0,0 +1,34 @@ +#ifndef GEN_ALLOC_DEFS_H +#define GEN_ALLOC_DEFS_H + +#define GEN_ALLOC_ready(ta,type,field,len,a,i,n,x,base,ta_ready) \ +int ta_ready(x,n) register ta *x; register unsigned int n; \ +{ register unsigned int i; \ + if (x->field) { \ + i = x->a; \ + if (n > i) { \ + x->a = base + n + (n >> 3); \ + if (alloc_re(&x->field,i * sizeof(type),x->a * sizeof(type))) return 1; \ + x->a = i; return 0; } \ + return 1; } \ + x->len = 0; \ + return !!(x->field = (type *) alloc((x->a = n) * sizeof(type))); } + +#define GEN_ALLOC_readyplus(ta,type,field,len,a,i,n,x,base,ta_rplus) \ +int ta_rplus(x,n) register ta *x; register unsigned int n; \ +{ register unsigned int i; \ + if (x->field) { \ + i = x->a; n += x->len; \ + if (n > i) { \ + x->a = base + n + (n >> 3); \ + if (alloc_re(&x->field,i * sizeof(type),x->a * sizeof(type))) return 1; \ + x->a = i; return 0; } \ + return 1; } \ + x->len = 0; \ + return !!(x->field = (type *) alloc((x->a = n) * sizeof(type))); } + +#define GEN_ALLOC_append(ta,type,field,len,a,i,n,x,base,ta_rplus,ta_append) \ +int ta_append(x,i) register ta *x; register type *i; \ +{ if (!ta_rplus(x,1)) return 0; x->field[x->len++] = *i; return 1; } + +#endif diff -BbrurN sendmail-8.12.7/sendmail/gen_alloc.h sendmail-8.12.7-cdb-testbuild/sendmail/gen_alloc.h --- sendmail-8.12.7/sendmail/gen_alloc.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/gen_alloc.h 2003-01-30 09:53:21.000000000 +0800 @@ -0,0 +1,7 @@ +#ifndef GEN_ALLOC_H +#define GEN_ALLOC_H + +#define GEN_ALLOC_typedef(ta,type,field,len,a) \ + typedef struct ta { type *field; unsigned int len; unsigned int a; } ta; + +#endif diff -BbrurN sendmail-8.12.7/sendmail/map.c sendmail-8.12.7-cdb-testbuild/sendmail/map.c --- sendmail-8.12.7/sendmail/map.c 2002-12-04 01:01:15.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/map.c 2003-02-14 18:31:25.000000000 +0800 @@ -12,6 +12,16 @@ */ #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include SM_RCSID("@(#)$Id: map.c,v 8.645.2.7 2002/12/03 17:01:15 ca Exp $") @@ -1834,6 +1843,258 @@ } #endif /* NDBM */ + +#if CDB + +static struct cdb_make create_map_tmp; +static struct cdb cdb_map_db; +stralloc search_key = {0}; +stralloc found_value = {0}; + +bool +cdb_map_open(map, mode) + MAP *map; + int mode; +{ + int i; + int omode; + int smode = S_IREAD; + int fd, tmpfd; + long sff; + int save_errno; + struct stat st; + char buf[MAXPATHLEN], tmpbuf[MAXPATHLEN]; + + /* do initial file and directory checks */ + if (sm_strlcpy(buf, map->map_file, sizeof buf) >= sizeof buf) + { + errno = 0; + if (!bitset(MF_OPTIONAL, map->map_mflags)) + syserr("cdb map \"%s\": map file %s name too long", + map->map_mname, map->map_file); + return false; + } + i = strlen(buf); + if (i < 3 || strcmp(&buf[i - 4], ".cdb") != 0) + { + if (sm_strlcat(buf, ".cdb", sizeof buf) >= sizeof buf) + { + errno = 0; + if (!bitset(MF_OPTIONAL, map->map_mflags)) + syserr("cdb map \"%s\": map file %s name too long", + map->map_mname, map->map_file); + return false; + } + } + if (sm_strlcpy(tmpbuf, map->map_file, sizeof tmpbuf) >= sizeof tmpbuf) + { + errno = 0; + if (!bitset(MF_OPTIONAL, map->map_mflags)) + syserr("cdb map \"%s\": map file %s name too long", + map->map_mname, map->map_file); + return false; + } + i = strlen(tmpbuf); + if (i < 3 || strcmp(&tmpbuf[i - 8], ".cdb.tmp") != 0) + { + if (sm_strlcat(tmpbuf, ".cdb.tmp", sizeof tmpbuf) >= sizeof tmpbuf) + { + errno = 0; + if (!bitset(MF_OPTIONAL, map->map_mflags)) + syserr("cdb map \"%s\": map file %s name too long", + map->map_mname, map->map_file); + return false; + } + } + mode &= O_ACCMODE; + omode = mode; + sff = SFF_ROOTOK|SFF_REGONLY; + if (mode == O_RDWR) + { + sff |= SFF_CREAT; + if (!bitnset(DBS_WRITEMAPTOSYMLINK, DontBlameSendmail)) + sff |= SFF_NOSLINK; + if (!bitnset(DBS_WRITEMAPTOHARDLINK, DontBlameSendmail)) + sff |= SFF_NOHLINK; + smode = S_IWRITE; + } + else + { + if (!bitnset(DBS_LINKEDMAPINWRITABLEDIR, DontBlameSendmail)) + sff |= SFF_NOWLINK; + } + if (!bitnset(DBS_MAPINUNSAFEDIRPATH, DontBlameSendmail)) + sff |= SFF_SAFEDIRPATH; + i = safefile(buf, RunAsUid, RunAsGid, RunAsUserName, sff, smode, &st); + if (i != 0) + { + char *prob = "unsafe"; + + /* cannot open this map */ + if (i == ENOENT) + prob = "missing"; + if (tTd(38, 2)) + sm_dprintf("\t%s map file: %s\n", prob, sm_errstring(i)); + errno = i; + if (!bitset(MF_OPTIONAL, map->map_mflags)) + syserr("%s map \"%s\": %s map file %s", + map->map_mname, prob, buf); + return false; + } + + if (mode == O_RDWR) { + tmpfd = open_trunc(tmpbuf); + if (tmpfd == -1) { + syserr("tmp cdb map file %s could not be created", tmpbuf); + return false; + } + if (cdb_make_start(&create_map_tmp, tmpfd) == -1) { + syserr("tmp cdb map file %s could not be created", tmpbuf); + } + map->map_db1= (ARBPTR_T)omode; + map->map_db2 = (ARBPTR_T)tmpfd; + } + + if (mode == O_RDONLY) { + fd = open_read(buf); + if (fd == -1) { + syserr("cdb %s could not be opened", buf); + return false; + } + map->map_db1 = (ARBPTR_T)omode; + map->map_db2 = (ARBPTR_T)fd; + } + return true; +} + +char * cdb_map_lookup(map, name, av, statp) + MAP *map; + char *name; + char **av; + int *statp; +{ + int cdbfd = (int)map->map_db2; + unsigned int dlen, klen; + uint32 dpos; + char *errstr; + char search_key[MAXNAME+1]; + klen = strlen(name); + if (klen > sizeof search_key - 1) + klen = sizeof search_key - 1; + memmove(search_key, name, klen); + if (tTd(38, 20)) + sm_dprintf("cdb_map_lookup(%s, %s)\n", + map->map_mname, name); + if (!bitset(MF_NOFOLDCASE, map->map_mflags)) { + makelower(search_key); + } + cdb_init(&cdb_map_db, cdbfd); + if (cdb_find(&cdb_map_db, search_key, klen) == 1) { + dlen = cdb_datalen(&cdb_map_db); + dpos = cdb_datapos(&cdb_map_db); + stralloc_ready(&found_value, dlen); + memset(found_value.s, 0, strlen(found_value.s)); + if (cdb_read(&cdb_map_db, found_value.s, dlen, dpos) == -1) { + errstr = strerror(errno); + syserr("cdb: problem reading value of %s: error: %s", name, errstr); + return NULL; + } + else { + if (bitset(MF_MATCHONLY, map->map_mflags)) { + return map_rewrite(map, name, klen, NULL); + } + else { + return map_rewrite(map, found_value.s, strlen(found_value.s), av); + } + + } + + } + else + return NULL; +} + + +void cdb_map_store(map, lhs, rhs) + MAP *map; + char *lhs; + char *rhs; +{ + unsigned int klen; + unsigned int dlen; + unsigned int i; + int encerr; + uint32 h; + klen = strlen(lhs); + dlen = strlen(rhs); + if (cdb_make_addbegin(&create_map_tmp, klen, dlen) == -1) syserr("cdb: failed trying to add %s %s to cdb", lhs, rhs); + else { + h = CDB_HASHSTART; + for (i = 0;i < klen;++i) { + if ((encerr = buffer_PUTC(&create_map_tmp.b,lhs[i])) == -1) { syserr("Error encountered adding key %s to cdb", lhs); break;} + h = cdb_hashadd(h,lhs[i]); + } + if (encerr == -1) + syserr("Not adding value %s due error encountered when adding key %s to cdb", rhs, lhs); + else { + for (i = 0;i < dlen;++i) { + if (buffer_PUTC(&create_map_tmp.b,rhs[i]) == -1) syserr("Error encountered add value %s for key %s", rhs, lhs); + } + if (cdb_make_addend(&create_map_tmp,klen,dlen,h) == -1) syserr("cdb: failed to complete adding %s %s tp cdb", lhs, rhs); + } + } +} + +void cdb_map_close(map) + MAP *map; +{ + int i; + char tmpfn[MAXPATHLEN], cdbfn[MAXPATHLEN]; + int omode = (int)map->map_db1; + int fd = (int)map->map_db2; + if (omode == O_RDONLY) { + cdb_free(&cdb_map_db); + close(fd); + } + if (omode == O_RDWR){ + if (sm_strlcpy(cdbfn, map->map_file, sizeof cdbfn) >= sizeof cdbfn) + { + syserr("cdb close map \"%s\": map file %s name too long", + map->map_mname, map->map_file); + } + i = strlen(cdbfn); + if (i < 3 || strcmp(&cdbfn[i - 4], ".cdb") != 0) + { + if (sm_strlcat(cdbfn, ".cdb", sizeof cdbfn) >= sizeof cdbfn) + { + syserr("cdb close map \"%s\": map file %s name too long", + map->map_mname, map->map_file); + } + } + if (sm_strlcpy(tmpfn, map->map_file, sizeof tmpfn) >= sizeof tmpfn) + { + syserr("cdb close map \"%s\": map file %s name too long", + map->map_mname, map->map_file); + } + i = strlen(tmpfn); + if (i < 3 || strcmp(&tmpfn[i - 8], ".cdb.tmp") != 0) + { + if (sm_strlcat(tmpfn, ".cdb.tmp", sizeof tmpfn) >= sizeof tmpfn) + { + syserr("cdb close map \"%s\": map file %s name too long", + map->map_mname, map->map_file); + } + } + + if (cdb_make_finish(&create_map_tmp) == -1) syserr("cdb: failed to write %s", tmpfn); + if (fsync(fd) == -1) syserr("cdb: fsync failed on %s", tmpfn); + if (close(fd) == -1) syserr("cdb: close failed on %s", tmpfn); + if (rename(tmpfn,cdbfn) == -1) syserr("cdb: failed to rename %s to %s", tmpfn, cdbfn); + } +} + +#endif + /* ** NEWDB (Hash and BTree) Modules */ @@ -6116,6 +6376,10 @@ if (bitset(MF_IMPL_NDBM, map->map_mflags)) return ndbm_map_lookup(map, name, av, pstat); #endif /* NDBM */ +#if CDB + if (bitset(MF_IMPL_CDB, map->map_mflags)) + return cdb_map_lookup(map, name, av, pstat); +#endif return stab_map_lookup(map, name, av, pstat); } @@ -6140,6 +6404,10 @@ if (bitset(MF_IMPL_NDBM, map->map_mflags)) ndbm_map_store(map, lhs, rhs); #endif /* NDBM */ +#if CDB + if (bitset(MF_IMPL_CDB, map->map_mflags)) + cdb_map_store(map, lhs, rhs); +#endif stab_map_store(map, lhs, rhs); } @@ -6178,8 +6446,14 @@ else map->map_mflags &= ~MF_IMPL_NDBM; #endif /* NDBM */ - -#if defined(NEWDB) || defined(NDBM) +#if CDB + map->map_mflags |= MF_IMPL_CDB; + if (cdb_map_open(map, mode)) + { + return true; + } +#endif +#if defined(NEWDB) || defined(NDBM) || defined(CDB) if (Verbose) message("WARNING: cannot open alias database %s%s", map->map_file, @@ -6222,6 +6496,13 @@ map->map_mflags &= ~MF_IMPL_NDBM; } #endif /* NDBM */ +#if CDB + if (bitset(MF_IMPL_CDB, map->map_mflags)) + { + cdb_map_close(map); + map->map_mflags &= ~MF_IMPL_CDB; + } +#endif } /* ** User map class. diff -BbrurN sendmail-8.12.7/sendmail/open.h sendmail-8.12.7-cdb-testbuild/sendmail/open.h --- sendmail-8.12.7/sendmail/open.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/open.h 2003-01-28 16:35:23.000000000 +0800 @@ -0,0 +1,10 @@ +#ifndef OPEN_H +#define OPEN_H + +extern int open_read(char *); +extern int open_excl(char *); +extern int open_append(char *); +extern int open_trunc(char *); +extern int open_write(char *); + +#endif diff -BbrurN sendmail-8.12.7/sendmail/open_read.c sendmail-8.12.7-cdb-testbuild/sendmail/open_read.c --- sendmail-8.12.7/sendmail/open_read.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/open_read.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,6 @@ +#include +#include +#include "open.h" + +int open_read(char *fn) +{ return open(fn,O_RDONLY | O_NDELAY); } diff -BbrurN sendmail-8.12.7/sendmail/open_trunc.c sendmail-8.12.7-cdb-testbuild/sendmail/open_trunc.c --- sendmail-8.12.7/sendmail/open_trunc.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/open_trunc.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,6 @@ +#include +#include +#include "open.h" + +int open_trunc(char *fn) +{ return open(fn,O_WRONLY | O_NDELAY | O_TRUNC | O_CREAT,0644); } diff -BbrurN sendmail-8.12.7/sendmail/readwrite.h sendmail-8.12.7-cdb-testbuild/sendmail/readwrite.h --- sendmail-8.12.7/sendmail/readwrite.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/readwrite.h 2003-01-28 16:35:23.000000000 +0800 @@ -0,0 +1,7 @@ +#ifndef READWRITE_H +#define READWRITE_H + +extern int read(); +extern int write(); + +#endif diff -BbrurN sendmail-8.12.7/sendmail/scan.h sendmail-8.12.7-cdb-testbuild/sendmail/scan.h --- sendmail-8.12.7/sendmail/scan.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/scan.h 2003-01-28 16:35:23.000000000 +0800 @@ -0,0 +1,28 @@ +#ifndef SCAN_H +#define SCAN_H + +extern unsigned int scan_uint(char *,unsigned int *); +extern unsigned int scan_xint(char *,unsigned int *); +extern unsigned int scan_nbbint(char *,unsigned int,unsigned int,unsigned int,unsigned int *); +extern unsigned int scan_ushort(char *,unsigned short *); +extern unsigned int scan_xshort(char *,unsigned short *); +extern unsigned int scan_nbbshort(char *,unsigned int,unsigned int,unsigned int,unsigned short *); +extern unsigned int scan_ulong(char *,unsigned long *); +extern unsigned int scan_xlong(char *,unsigned long *); +extern unsigned int scan_nbblong(char *,unsigned int,unsigned int,unsigned int,unsigned long *); + +extern unsigned int scan_plusminus(char *,int *); +extern unsigned int scan_0x(char *,unsigned int *); + +extern unsigned int scan_whitenskip(char *,unsigned int); +extern unsigned int scan_nonwhitenskip(char *,unsigned int); +extern unsigned int scan_charsetnskip(char *,char *,unsigned int); +extern unsigned int scan_noncharsetnskip(char *,char *,unsigned int); + +extern unsigned int scan_strncmp(char *,char *,unsigned int); +extern unsigned int scan_memcmp(char *,char *,unsigned int); + +extern unsigned int scan_long(char *,long *); +extern unsigned int scan_8long(char *,unsigned long *); + +#endif diff -BbrurN sendmail-8.12.7/sendmail/scan_ulong.c sendmail-8.12.7-cdb-testbuild/sendmail/scan_ulong.c --- sendmail-8.12.7/sendmail/scan_ulong.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/scan_ulong.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,11 @@ +#include "scan.h" + +unsigned int scan_ulong(register char *s,register unsigned long *u) +{ + register unsigned int pos; register unsigned long result; + register unsigned long c; + pos = 0; result = 0; + while ((c = (unsigned long) (unsigned char) (s[pos] - '0')) < 10) + { result = result * 10 + c; ++pos; } + *u = result; return pos; +} diff -BbrurN sendmail-8.12.7/sendmail/seek_cur.c sendmail-8.12.7-cdb-testbuild/sendmail/seek_cur.c --- sendmail-8.12.7/sendmail/seek_cur.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/seek_cur.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,7 @@ +#include +#include "seek.h" + +#define CUR 1 /* sigh */ + +seek_pos seek_cur(int fd) +{ return lseek(fd,(off_t) 0,CUR); } diff -BbrurN sendmail-8.12.7/sendmail/seek.h sendmail-8.12.7-cdb-testbuild/sendmail/seek.h --- sendmail-8.12.7/sendmail/seek.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/seek.h 2003-01-28 16:35:23.000000000 +0800 @@ -0,0 +1,15 @@ +#ifndef SEEK_H +#define SEEK_H + +typedef unsigned long seek_pos; + +extern seek_pos seek_cur(int); + +extern int seek_set(int,seek_pos); +extern int seek_end(int); + +extern int seek_trunc(int,seek_pos); + +#define seek_begin(fd) (seek_set((fd),(seek_pos) 0)) + +#endif diff -BbrurN sendmail-8.12.7/sendmail/seek_set.c sendmail-8.12.7-cdb-testbuild/sendmail/seek_set.c --- sendmail-8.12.7/sendmail/seek_set.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/seek_set.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,7 @@ +#include +#include "seek.h" + +#define SET 0 /* sigh */ + +int seek_set(int fd,seek_pos pos) +{ if (lseek(fd,(off_t) pos,SET) == -1) return -1; return 0; } diff -BbrurN sendmail-8.12.7/sendmail/sendmail.h sendmail-8.12.7-cdb-testbuild/sendmail/sendmail.h --- sendmail-8.12.7/sendmail/sendmail.h 2002-12-13 06:46:35.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/sendmail.h 2003-01-29 01:08:21.000000000 +0800 @@ -1201,7 +1201,7 @@ #define MF_ALIASWAIT 0x00000800 /* alias map in aliaswait state */ #define MF_IMPL_HASH 0x00001000 /* implicit: underlying hash database */ #define MF_IMPL_NDBM 0x00002000 /* implicit: underlying NDBM database */ -/* 0x00004000 */ +#define MF_IMPL_CDB 0x00004000 /* implicit: underlying cdb database */ #define MF_APPEND 0x00008000 /* append new entry on rebuild */ #define MF_KEEPQUOTES 0x00010000 /* don't dequote key before lookup */ #define MF_NODEFER 0x00020000 /* don't defer if map lookup fails */ diff -BbrurN sendmail-8.12.7/sendmail/stralloc.3 sendmail-8.12.7-cdb-testbuild/sendmail/stralloc.3 --- sendmail-8.12.7/sendmail/stralloc.3 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/stralloc.3 2003-01-30 09:52:06.000000000 +0800 @@ -0,0 +1,160 @@ +.TH stralloc 3 +.SH NAME +stralloc \- dynamically allocated strings +.SH SYNTAX +.B #include + +int \fBstralloc_ready\fP(&\fIsa\fR,\fIlen\fR); +.br +int \fBstralloc_readyplus\fP(&\fIsa\fR,\fIlen\fR); + +int \fBstralloc_copy\fP(&\fIsa\fR,&\fIsa2\fR); +.br +int \fBstralloc_copys\fP(&\fIsa\fR,\fIbuf\fR); +.br +int \fBstralloc_copyb\fP(&\fIsa\fR,\fIbuf\fR,\fIlen\fR); + +int \fBstralloc_cat\fP(&\fIsa\fR,&\fIsa2\fR); +.br +int \fBstralloc_cats\fP(&\fIsa\fR,\fIbuf\fR); +.br +int \fBstralloc_catb\fP(&\fIsa\fR,\fIbuf\fR,\fIlen\fR); + +int \fBstralloc_append\fP(&\fIsa\fR,\fIbuf\fR); +.br +int \fBstralloc_0\fP(&\fIsa\fR); + +int \fBstralloc_starts\fP(&\fIsa\fR,\fIbuf\fR); + +stralloc \fIsa\fR = {0}; +.br +stralloc \fIsa2\fR = {0}; +.br +unsigned int \fIlen\fR; +.br +char *\fIbuf\fR; +.SH DESCRIPTION +A +.B stralloc +variable holds a string in dynamically allocated space. +String length is limited only by memory. +String contents are unrestricted. + +The +.B stralloc +structure has three components: +.I sa\fB.s +is a pointer to the string, or 0 if it is not allocated; +.I sa\fB.len +is the number of bytes in the string, if it is allocated; +.I sa\fB.a +is the number of bytes allocated for the string, if it is allocated. +A +.B stralloc +variable should be initialized to {0}, +meaning unallocated. + +.B stralloc_ready +makes sure that +.I sa +has enough space allocated for +.I len +characters. +It allocates extra space if necessary. + +.B stralloc_readyplus +makes sure that +.I sa +has enough space allocated for +.I len +characters more than its current length. +If +.I sa +is unallocated, +.B stralloc_readyplus +is the same as +.BR stralloc_ready . + +.B stralloc_copy +copies +.I sa2 +to +.IR sa , +allocating space if necessary. +Here +.I sa2 +is an allocated +.B stralloc +variable. + +.B stralloc_copys +copies a 0-terminated string, +.IR buf , +to +.IR sa , +without the 0. + +.B stralloc_copyb +copies +.I len +characters from +.I buf +to +.IR sa . + +.B stralloc_cat +appends +.I sa2 +to +.IR sa , +allocating space if necessary. +If +.I sa +is unallocated, +.B stralloc_cat +is the same as +.BR stralloc_copy . + +.B stralloc_cats +and +.B stralloc_catb +are analogous to +.B stralloc_copys +and +.BR stralloc_copyb . + +.B stralloc_append +adds a single character, +.IR *buf , +to +.IR sa , +allocating space if necessary. + +.B stralloc_0 +adds a single 0 character +to +.IR sa . + +.B stralloc_starts +returns 1 if the 0-terminated string +.IR buf , +without the 0, +is a prefix of +.IR sa . +.SH "ERROR HANDLING" +If a +.B stralloc +routine runs out of memory, +it leaves +.I sa +alone and returns 0, +setting +.B errno +appropriately. +On success it returns 1; +this guarantees that +.I sa +is allocated. +.SH "SEE ALSO" +alloc(3), +error(3) diff -BbrurN sendmail-8.12.7/sendmail/stralloc_arts.c sendmail-8.12.7-cdb-testbuild/sendmail/stralloc_arts.c --- sendmail-8.12.7/sendmail/stralloc_arts.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/stralloc_arts.c 2003-01-30 09:52:06.000000000 +0800 @@ -0,0 +1,12 @@ +#include "byte.h" +#include "str.h" +#include "stralloc.h" + +int stralloc_starts(sa,s) +stralloc *sa; +char *s; +{ + int len; + len = str_len(s); + return (sa->len >= len) && byte_equal(s,len,sa->s); +} diff -BbrurN sendmail-8.12.7/sendmail/stralloc_catb.c sendmail-8.12.7-cdb-testbuild/sendmail/stralloc_catb.c --- sendmail-8.12.7/sendmail/stralloc_catb.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/stralloc_catb.c 2003-01-30 09:52:06.000000000 +0800 @@ -0,0 +1,15 @@ +#include "stralloc.h" +#include "byte.h" + +int stralloc_catb(sa,s,n) +stralloc *sa; +char *s; +unsigned int n; +{ + if (!sa->s) return stralloc_copyb(sa,s,n); + if (!stralloc_readyplus(sa,n + 1)) return 0; + byte_copy(sa->s + sa->len,n,s); + sa->len += n; + sa->s[sa->len] = 'Z'; /* ``offensive programming'' */ + return 1; +} diff -BbrurN sendmail-8.12.7/sendmail/stralloc_cat.c sendmail-8.12.7-cdb-testbuild/sendmail/stralloc_cat.c --- sendmail-8.12.7/sendmail/stralloc_cat.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/stralloc_cat.c 2003-01-30 09:52:06.000000000 +0800 @@ -0,0 +1,9 @@ +#include "byte.h" +#include "stralloc.h" + +int stralloc_cat(sato,safrom) +stralloc *sato; +stralloc *safrom; +{ + return stralloc_catb(sato,safrom->s,safrom->len); +} diff -BbrurN sendmail-8.12.7/sendmail/stralloc_cats.c sendmail-8.12.7-cdb-testbuild/sendmail/stralloc_cats.c --- sendmail-8.12.7/sendmail/stralloc_cats.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/stralloc_cats.c 2003-01-30 09:52:06.000000000 +0800 @@ -0,0 +1,10 @@ +#include "byte.h" +#include "str.h" +#include "stralloc.h" + +int stralloc_cats(sa,s) +stralloc *sa; +char *s; +{ + return stralloc_catb(sa,s,str_len(s)); +} diff -BbrurN sendmail-8.12.7/sendmail/stralloc_copy.c sendmail-8.12.7-cdb-testbuild/sendmail/stralloc_copy.c --- sendmail-8.12.7/sendmail/stralloc_copy.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/stralloc_copy.c 2003-01-30 09:52:06.000000000 +0800 @@ -0,0 +1,9 @@ +#include "byte.h" +#include "stralloc.h" + +int stralloc_copy(sato,safrom) +stralloc *sato; +stralloc *safrom; +{ + return stralloc_copyb(sato,safrom->s,safrom->len); +} diff -BbrurN sendmail-8.12.7/sendmail/stralloc_eady.c sendmail-8.12.7-cdb-testbuild/sendmail/stralloc_eady.c --- sendmail-8.12.7/sendmail/stralloc_eady.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/stralloc_eady.c 2003-01-30 09:52:06.000000000 +0800 @@ -0,0 +1,6 @@ +#include "alloc.h" +#include "stralloc.h" +#include "gen_allocdefs.h" + +GEN_ALLOC_ready(stralloc,char,s,len,a,i,n,x,30,stralloc_ready) +GEN_ALLOC_readyplus(stralloc,char,s,len,a,i,n,x,30,stralloc_readyplus) diff -BbrurN sendmail-8.12.7/sendmail/stralloc.h sendmail-8.12.7-cdb-testbuild/sendmail/stralloc.h --- sendmail-8.12.7/sendmail/stralloc.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/stralloc.h 2003-01-30 09:52:06.000000000 +0800 @@ -0,0 +1,21 @@ +#ifndef STRALLOC_H +#define STRALLOC_H + +#include "gen_alloc.h" + +GEN_ALLOC_typedef(stralloc,char,s,len,a) + +extern int stralloc_ready(); +extern int stralloc_readyplus(); +extern int stralloc_copy(); +extern int stralloc_cat(); +extern int stralloc_copys(); +extern int stralloc_cats(); +extern int stralloc_copyb(); +extern int stralloc_catb(); +extern int stralloc_append(); /* beware: this takes a pointer to 1 char */ +extern int stralloc_starts(); + +#define stralloc_0(sa) stralloc_append(sa,"") + +#endif diff -BbrurN sendmail-8.12.7/sendmail/stralloc_opyb.c sendmail-8.12.7-cdb-testbuild/sendmail/stralloc_opyb.c --- sendmail-8.12.7/sendmail/stralloc_opyb.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/stralloc_opyb.c 2003-01-30 09:52:06.000000000 +0800 @@ -0,0 +1,14 @@ +#include "stralloc.h" +#include "byte.h" + +int stralloc_copyb(sa,s,n) +stralloc *sa; +char *s; +unsigned int n; +{ + if (!stralloc_ready(sa,n + 1)) return 0; + byte_copy(sa->s,n,s); + sa->len = n; + sa->s[n] = 'Z'; /* ``offensive programming'' */ + return 1; +} diff -BbrurN sendmail-8.12.7/sendmail/stralloc_opys.c sendmail-8.12.7-cdb-testbuild/sendmail/stralloc_opys.c --- sendmail-8.12.7/sendmail/stralloc_opys.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/stralloc_opys.c 2003-01-30 09:52:06.000000000 +0800 @@ -0,0 +1,10 @@ +#include "byte.h" +#include "str.h" +#include "stralloc.h" + +int stralloc_copys(sa,s) +stralloc *sa; +char *s; +{ + return stralloc_copyb(sa,s,str_len(s)); +} diff -BbrurN sendmail-8.12.7/sendmail/stralloc_pend.c sendmail-8.12.7-cdb-testbuild/sendmail/stralloc_pend.c --- sendmail-8.12.7/sendmail/stralloc_pend.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/stralloc_pend.c 2003-01-30 09:52:06.000000000 +0800 @@ -0,0 +1,5 @@ +#include "alloc.h" +#include "stralloc.h" +#include "gen_allocdefs.h" + +GEN_ALLOC_append(stralloc,char,s,len,a,i,n,x,30,stralloc_readyplus,stralloc_append) diff -BbrurN sendmail-8.12.7/sendmail/strerr_die.c sendmail-8.12.7-cdb-testbuild/sendmail/strerr_die.c --- sendmail-8.12.7/sendmail/strerr_die.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/strerr_die.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,31 @@ +#include "buffer.h" +#include "exit.h" +#include "strerr.h" + +void strerr_warn(char *x1,char *x2,char *x3,char *x4,char *x5,char *x6,struct strerr *se) +{ + strerr_sysinit(); + + if (x1) buffer_puts(buffer_2,x1); + if (x2) buffer_puts(buffer_2,x2); + if (x3) buffer_puts(buffer_2,x3); + if (x4) buffer_puts(buffer_2,x4); + if (x5) buffer_puts(buffer_2,x5); + if (x6) buffer_puts(buffer_2,x6); + + while(se) { + if (se->x) buffer_puts(buffer_2,se->x); + if (se->y) buffer_puts(buffer_2,se->y); + if (se->z) buffer_puts(buffer_2,se->z); + se = se->who; + } + + buffer_puts(buffer_2,"\n"); + buffer_flush(buffer_2); +} + +void strerr_die(int e,char *x1,char *x2,char *x3,char *x4,char *x5,char *x6,struct strerr *se) +{ + strerr_warn(x1,x2,x3,x4,x5,x6,se); + _exit(e); +} diff -BbrurN sendmail-8.12.7/sendmail/strerr.h sendmail-8.12.7-cdb-testbuild/sendmail/strerr.h --- sendmail-8.12.7/sendmail/strerr.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/strerr.h 2003-01-28 16:35:23.000000000 +0800 @@ -0,0 +1,78 @@ +#ifndef STRERR_H +#define STRERR_H + +struct strerr { + struct strerr *who; + char *x; + char *y; + char *z; +} ; + +extern struct strerr strerr_sys; +extern void strerr_sysinit(void); + +extern char *strerr(struct strerr *); +extern void strerr_warn(char *,char *,char *,char *,char *,char *,struct strerr *); +extern void strerr_die(int,char *,char *,char *,char *,char *,char *,struct strerr *); + +#define STRERR(r,se,a) \ +{ se.who = 0; se.x = a; se.y = 0; se.z = 0; return r; } + +#define STRERR_SYS(r,se,a) \ +{ se.who = &strerr_sys; se.x = a; se.y = 0; se.z = 0; return r; } +#define STRERR_SYS3(r,se,a,b,c) \ +{ se.who = &strerr_sys; se.x = a; se.y = b; se.z = c; return r; } + +#define strerr_warn6(x1,x2,x3,x4,x5,x6,se) \ +strerr_warn((x1),(x2),(x3),(x4),(x5),(x6),(se)) +#define strerr_warn5(x1,x2,x3,x4,x5,se) \ +strerr_warn((x1),(x2),(x3),(x4),(x5),0,(se)) +#define strerr_warn4(x1,x2,x3,x4,se) \ +strerr_warn((x1),(x2),(x3),(x4),0,0,(se)) +#define strerr_warn3(x1,x2,x3,se) \ +strerr_warn((x1),(x2),(x3),0,0,0,(se)) +#define strerr_warn2(x1,x2,se) \ +strerr_warn((x1),(x2),0,0,0,0,(se)) +#define strerr_warn1(x1,se) \ +strerr_warn((x1),0,0,0,0,0,(se)) + +#define strerr_die6(e,x1,x2,x3,x4,x5,x6,se) \ +strerr_die((e),(x1),(x2),(x3),(x4),(x5),(x6),(se)) +#define strerr_die5(e,x1,x2,x3,x4,x5,se) \ +strerr_die((e),(x1),(x2),(x3),(x4),(x5),0,(se)) +#define strerr_die4(e,x1,x2,x3,x4,se) \ +strerr_die((e),(x1),(x2),(x3),(x4),0,0,(se)) +#define strerr_die3(e,x1,x2,x3,se) \ +strerr_die((e),(x1),(x2),(x3),0,0,0,(se)) +#define strerr_die2(e,x1,x2,se) \ +strerr_die((e),(x1),(x2),0,0,0,0,(se)) +#define strerr_die1(e,x1,se) \ +strerr_die((e),(x1),0,0,0,0,0,(se)) + +#define strerr_die6sys(e,x1,x2,x3,x4,x5,x6) \ +strerr_die((e),(x1),(x2),(x3),(x4),(x5),(x6),&strerr_sys) +#define strerr_die5sys(e,x1,x2,x3,x4,x5) \ +strerr_die((e),(x1),(x2),(x3),(x4),(x5),0,&strerr_sys) +#define strerr_die4sys(e,x1,x2,x3,x4) \ +strerr_die((e),(x1),(x2),(x3),(x4),0,0,&strerr_sys) +#define strerr_die3sys(e,x1,x2,x3) \ +strerr_die((e),(x1),(x2),(x3),0,0,0,&strerr_sys) +#define strerr_die2sys(e,x1,x2) \ +strerr_die((e),(x1),(x2),0,0,0,0,&strerr_sys) +#define strerr_die1sys(e,x1) \ +strerr_die((e),(x1),0,0,0,0,0,&strerr_sys) + +#define strerr_die6x(e,x1,x2,x3,x4,x5,x6) \ +strerr_die((e),(x1),(x2),(x3),(x4),(x5),(x6),0) +#define strerr_die5x(e,x1,x2,x3,x4,x5) \ +strerr_die((e),(x1),(x2),(x3),(x4),(x5),0,0) +#define strerr_die4x(e,x1,x2,x3,x4) \ +strerr_die((e),(x1),(x2),(x3),(x4),0,0,0) +#define strerr_die3x(e,x1,x2,x3) \ +strerr_die((e),(x1),(x2),(x3),0,0,0,0) +#define strerr_die2x(e,x1,x2) \ +strerr_die((e),(x1),(x2),0,0,0,0,0) +#define strerr_die1x(e,x1) \ +strerr_die((e),(x1),0,0,0,0,0,0) + +#endif diff -BbrurN sendmail-8.12.7/sendmail/strerr_sys.c sendmail-8.12.7-cdb-testbuild/sendmail/strerr_sys.c --- sendmail-8.12.7/sendmail/strerr_sys.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/strerr_sys.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,12 @@ +#include "error.h" +#include "strerr.h" + +struct strerr strerr_sys; + +void strerr_sysinit(void) +{ + strerr_sys.who = 0; + strerr_sys.x = error_str(errno); + strerr_sys.y = ""; + strerr_sys.z = ""; +} diff -BbrurN sendmail-8.12.7/sendmail/str.h sendmail-8.12.7-cdb-testbuild/sendmail/str.h --- sendmail-8.12.7/sendmail/str.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/str.h 2003-01-28 16:35:23.000000000 +0800 @@ -0,0 +1,14 @@ +#ifndef STR_H +#define STR_H + +extern unsigned int str_copy(char *,char *); +extern int str_diff(char *,char *); +extern int str_diffn(char *,char *,unsigned int); +extern unsigned int str_len(char *); +extern unsigned int str_chr(char *,int); +extern unsigned int str_rchr(char *,int); +extern int str_start(char *,char *); + +#define str_equal(s,t) (!str_diff((s),(t))) + +#endif diff -BbrurN sendmail-8.12.7/sendmail/str_len.c sendmail-8.12.7-cdb-testbuild/sendmail/str_len.c --- sendmail-8.12.7/sendmail/str_len.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/str_len.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,14 @@ +#include "str.h" + +unsigned int str_len(char *s) +{ + register char *t; + + t = s; + for (;;) { + if (!*t) return t - s; ++t; + if (!*t) return t - s; ++t; + if (!*t) return t - s; ++t; + if (!*t) return t - s; ++t; + } +} diff -BbrurN sendmail-8.12.7/sendmail/testzero.c sendmail-8.12.7-cdb-testbuild/sendmail/testzero.c --- sendmail-8.12.7/sendmail/testzero.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/testzero.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,35 @@ +#include "uint32.h" +#include "scan.h" +#include "strerr.h" +#include "cdb_make.h" + +#define FATAL "testzero: fatal: " + +void die_write(void) +{ + strerr_die2sys(111,FATAL,"unable to write: "); +} + +static char key[4]; +static char data[65536]; +struct cdb_make c; + +main(int argc,char **argv) +{ + int fd; + unsigned long loop; + + if (!*argv) _exit(0); + if (!*++argv) _exit(0); + scan_ulong(*argv,&loop); + + if (cdb_make_start(&c,1) == -1) die_write(); + + while (loop) { + uint32_pack(key,--loop); + if (cdb_make_add(&c,key,4,data,sizeof data) == -1) die_write(); + } + + if (cdb_make_finish(&c) == -1) die_write(); + _exit(0); +} diff -BbrurN sendmail-8.12.7/sendmail/trycpp.c sendmail-8.12.7-cdb-testbuild/sendmail/trycpp.c --- sendmail-8.12.7/sendmail/trycpp.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/trycpp.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,7 @@ +main() +{ +#ifdef NeXT + printf("nextstep\n"); exit(0); +#endif + printf("unknown\n"); exit(0); +} diff -BbrurN sendmail-8.12.7/sendmail/tryulong32.c sendmail-8.12.7-cdb-testbuild/sendmail/tryulong32.c --- sendmail-8.12.7/sendmail/tryulong32.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/tryulong32.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,11 @@ +void main() +{ + unsigned long u; + u = 1; + u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; + u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; + u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; + u += u; u += u; u += u; u += u; u += u; u += u; u += u; u += u; + if (!u) _exit(0); + _exit(1); +} diff -BbrurN sendmail-8.12.7/sendmail/uint32.h sendmail-8.12.7-cdb-testbuild/sendmail/uint32.h --- sendmail-8.12.7/sendmail/uint32.h 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/uint32.h 2003-01-28 16:35:23.000000000 +0800 @@ -0,0 +1,11 @@ +#ifndef UINT32_H +#define UINT32_H + +typedef unsigned long uint32; + +extern void uint32_pack(char *,uint32); +extern void uint32_pack_big(char *,uint32); +extern void uint32_unpack(char *,uint32 *); +extern void uint32_unpack_big(char *,uint32 *); + +#endif diff -BbrurN sendmail-8.12.7/sendmail/uint32_pack.c sendmail-8.12.7-cdb-testbuild/sendmail/uint32_pack.c --- sendmail-8.12.7/sendmail/uint32_pack.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/uint32_pack.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,21 @@ +#include "uint32.h" + +void uint32_pack(char s[4],uint32 u) +{ + s[0] = u & 255; + u >>= 8; + s[1] = u & 255; + u >>= 8; + s[2] = u & 255; + s[3] = u >> 8; +} + +void uint32_pack_big(char s[4],uint32 u) +{ + s[3] = u & 255; + u >>= 8; + s[2] = u & 255; + u >>= 8; + s[1] = u & 255; + s[0] = u >> 8; +} diff -BbrurN sendmail-8.12.7/sendmail/uint32_unpack.c sendmail-8.12.7-cdb-testbuild/sendmail/uint32_unpack.c --- sendmail-8.12.7/sendmail/uint32_unpack.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/uint32_unpack.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,31 @@ +#include "uint32.h" + +void uint32_unpack(char s[4],uint32 *u) +{ + uint32 result; + + result = (unsigned char) s[3]; + result <<= 8; + result += (unsigned char) s[2]; + result <<= 8; + result += (unsigned char) s[1]; + result <<= 8; + result += (unsigned char) s[0]; + + *u = result; +} + +void uint32_unpack_big(char s[4],uint32 *u) +{ + uint32 result; + + result = (unsigned char) s[0]; + result <<= 8; + result += (unsigned char) s[1]; + result <<= 8; + result += (unsigned char) s[2]; + result <<= 8; + result += (unsigned char) s[3]; + + *u = result; +} diff -BbrurN sendmail-8.12.7/sendmail/x86cpuid.c sendmail-8.12.7-cdb-testbuild/sendmail/x86cpuid.c --- sendmail-8.12.7/sendmail/x86cpuid.c 1970-01-01 08:00:00.000000000 +0800 +++ sendmail-8.12.7-cdb-testbuild/sendmail/x86cpuid.c 2003-01-28 16:35:26.000000000 +0800 @@ -0,0 +1,38 @@ +#include + +void nope() +{ + exit(1); +} + +main() +{ + unsigned long x[4]; + unsigned long y[4]; + int i; + int j; + char c; + + signal(SIGILL,nope); + + x[0] = 0; + x[1] = 0; + x[2] = 0; + x[3] = 0; + + asm volatile(".byte 15;.byte 162" : "=a"(x[0]),"=b"(x[1]),"=c"(x[3]),"=d"(x[2]) : "0"(0) ); + if (!x[0]) return 0; + asm volatile(".byte 15;.byte 162" : "=a"(y[0]),"=b"(y[1]),"=c"(y[2]),"=d"(y[3]) : "0"(1) ); + + for (i = 1;i < 4;++i) + for (j = 0;j < 4;++j) { + c = x[i] >> (8 * j); + if (c < 32) c = 32; + if (c > 126) c = 126; + putchar(c); + } + + printf("-%08x-%08x\n",y[0],y[3]); + + return 0; +}