Index: ChangeLog =================================================================== RCS file: /home/mea/src/CVSROOT/zmailer/ChangeLog,v retrieving revision 1.109 retrieving revision 1.110 diff -u -r1.109 -r1.110 --- ChangeLog 1999/04/04 16:18:52 1.109 +++ ChangeLog 1999/04/06 17:33:37 1.110 @@ -1,3 +1,45 @@ +1999-04-06 Matti Aarnio + + * libsh/builtins.c: + $(elements ...) tinkering; code "cleanup". (This wasn't the + real problem..) + + * include/listutils.h: + Test of ``LISTness'' vs. ``STRINGness'' became a bit confused + with ELEMENT flag set. Mask that off when comparing. + (THIS was the problem that plagued $(elements ...) ) + + * libsh/execute.c: Just small cleanup. + + * libsh/expand.c: + glob() expansion list construction straightening. Pre-Sort + items in reverse, and the list construction will be easy.. + + * libsh/interpret.c: functype() + Remember always to set the return value variable -- if its + pointer is available, otherwise some things behave strangely + depening on what happens to be at the stack frame... + ( + removed some dead code from the interpret() proper.) + + * libsh/listtrees.c: _s_copy_tree() + Added a comment (for myself) to explain things a bit. + + * proto/cf/server.cf: + Some extra tinkerings for those who want interactive router + at their smtpserver. + + * smtpserver/policytest.c: _addrtest_() + Selectively test blanket allowance/denial things, so that + when e.g. MAIL FROM: the literal IP address + can be looked up from the RBL/DUL/whatnot database while + not allowing e.g. MAIL FROM to suddently allow input from + any possible host just because once a suitable address is + given in MAIL FROM data... + + * smtpserver/smtpchild.c: + Count the number of childs properly, and always remember to + return a value thru the childcntp pointer. + 1999-04-03 Matti Aarnio * Makefile.in: 2.99.50-s14 Index: include/listutils.h =================================================================== RCS file: /home/mea/src/CVSROOT/zmailer/include/listutils.h,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- listutils.h 1999/04/03 12:08:17 1.12 +++ listutils.h 1999/04/06 16:52:46 1.13 @@ -66,8 +66,8 @@ #define EXTINLINE extern __inline__ #endif -EXTINLINE int LIST(conscell *C) { return ((~_DSW_MASK & (C)->flags) == 0); } -EXTINLINE int STRING(conscell *C) { return ((~_DSW_MASK & (C)->flags) != 0); } +EXTINLINE int LIST(conscell *C) { return ((~(_DSW_MASK|ELEMENT) & (C)->flags) == 0); } +EXTINLINE int STRING(conscell *C) { return ((~(_DSW_MASK|ELEMENT) & (C)->flags) != 0); } EXTINLINE int ISCONST(conscell *C) { return ((C)->flags & CONSTSTRING); } EXTINLINE int ISNEW(conscell *C) { return ((C)->flags & NEWSTRING); } EXTINLINE int ISQUOTED(conscell *C) { return ((C)->flags & QUOTEDSTRING); } @@ -76,8 +76,8 @@ #else /* ----- not profiling ----- */ -#define LIST(C) ((~_DSW_MASK & (C)->flags) == 0) -#define STRING(C) ((~_DSW_MASK & (C)->flags) != 0) +#define LIST(C) ((~(_DSW_MASK|ELEMENT) & (C)->flags) == 0) +#define STRING(C) ((~(_DSW_MASK|ELEMENT) & (C)->flags) != 0) #define ISCONST(C) ((C)->flags & CONSTSTRING) #define ISNEW(C) ((C)->flags & NEWSTRING) #define ISQUOTED(C) ((C)->flags & QUOTEDSTRING) Index: libsh/builtins.c =================================================================== RCS file: /home/mea/src/CVSROOT/zmailer/libsh/builtins.c,v retrieving revision 1.16 retrieving revision 1.18 diff -u -r1.16 -r1.18 --- builtins.c 1999/03/30 14:34:45 1.16 +++ builtins.c 1999/04/06 16:54:38 1.18 @@ -194,9 +194,11 @@ if ((p = cdar(avl)) == NULL || !LIST(p)) return p; il = cadar(avl); - p = il = s_copy_tree(il); /* creates new cells, but this is - also last call to the creator here */ - for (; p != NULL; p = cdr(p)) + + il = s_copy_tree(il); /* Creates new cells, but this is + also last call to the creator here. */ + + for (p = il; p != NULL; p = cdr(p)) p->flags |= ELEMENT; return il; } Index: libsh/execute.c =================================================================== RCS file: /home/mea/src/CVSROOT/zmailer/libsh/execute.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- execute.c 1999/04/04 11:39:22 1.7 +++ execute.c 1999/04/06 16:54:39 1.8 @@ -183,7 +183,7 @@ if (car(c->argv) == NULL || LIST(car(c->argv))) c->argv = NULL; else - functype(car(c->argv)->string, &c->shcmdp, NULL); + functype(car(c->argv)->cstring, &c->shcmdp, NULL); } if (c->argv && LIST(c->argv) && STRING(car(c->argv))) { /* there are string arguments */ @@ -192,7 +192,7 @@ fprintf(runiofp, "Run:"); } if (c->shcmdp == NULL) { - functype((car(c->argv))->string, NULL, &sfdp); + functype((car(c->argv))->cstring, NULL, &sfdp); if (sfdp == NULL) path_hash((car(c->argv))->string); } Index: libsh/expand.c =================================================================== RCS file: /home/mea/src/CVSROOT/zmailer/libsh/expand.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- expand.c 1999/03/30 14:34:45 1.5 +++ expand.c 1999/04/05 14:27:59 1.6 @@ -101,7 +101,10 @@ register const void **a = (const void **)ap; register const void **b = (const void **)bp; - return strcmp(*a, *b); + /* sort to reverse order, easier to collate + into an object chain */ + + return -strcmp(*a, *b); } /* note that | is going to be used instead of / in some pathname examples */ @@ -127,7 +130,7 @@ int *ibuf; /* unglobbed pathname w/ each byte stored as int */ { register int i, n; - conscell **pp, *cc; + conscell *pp, *cc = NULL; struct sawpath *spp; struct sawpath head; char *pwd, /* points to end of current directory in cwd */ @@ -169,12 +172,11 @@ /* construct a sorted linked list */ cc = NULL; GCPRO1(cc); - pp = &cc; for (i = 0; i < n; ++i) { int slen = strlen(base[i]); - *pp = newstring(dupnstr(base[i],slen),slen); - pp = &cdr(*pp); - *pp = NULL; + pp = newstring(dupnstr(base[i],slen),slen); + cdr(pp) = cc; + cc = pp; /* printf("saw %s\n", base[i]); */ } UNGCPRO1; Index: libsh/interpret.c =================================================================== RCS file: /home/mea/src/CVSROOT/zmailer/libsh/interpret.c,v retrieving revision 1.14 retrieving revision 1.16 diff -u -r1.14 -r1.16 --- interpret.c 1999/04/03 12:08:20 1.14 +++ interpret.c 1999/04/06 16:54:39 1.16 @@ -964,26 +964,27 @@ struct sslfuncdef **sfdpp; { spkey_t symid; - struct sslfuncdef *sfdp; struct spblk *spl; symid = symbol_lookup(fname); /* is it a defined function? */ - if (!symid) - spl = NULL; - else + spl = NULL; + if (symid) spl = sp_lookup(symid, spt_funclist); - if (spl == NULL) - sfdp = NULL; - else - sfdp = (struct sslfuncdef *)spl->data; - if (sfdpp != NULL) - *sfdpp = sfdp; + if (sfdpp) { + if (spl != NULL) + *sfdpp = (struct sslfuncdef *)spl->data; + else + *sfdpp = NULL; + } + /* behaviour in execute() requires we continue, not return */ /* is it a builtin command? */ - if (shcmdpp != NULL && symid) { + spl = NULL; + if (symid) spl = sp_lookup(symid, spt_builtins); + if (shcmdpp != NULL) { if (spl != NULL) *shcmdpp = (struct shCmd *)spl->data; else @@ -2630,10 +2631,8 @@ --commandIndex; } -/* #define RETVAL_FREEUP */ /* yes or no.. undefine if problems.. */ - -#ifndef RETVAL_FREEUP /* The original way ... */ setlevel(MEM_SHCMD, origlevel); + #ifdef MAILER /* * This is pretty dicey; we rely on setlevel() not changing the @@ -2645,43 +2644,6 @@ caller->rval = command->rval; } #endif -#else /* defined: RETVAL_FREEUP */ -#ifdef MAILER - /* - * This is pretty dicey; we rely on setlevel() not changing the - * stuff that was just freed. We need to do this to avoid - * malloc'ing stuff unnecessarily. For example we usually just - * want to access the return value in the context of the caller. - */ -/* mea: I will do some extra work just in case it would solve the dilemma.. */ - - if ((command->rval != NULL) && - (caller != NULL)) { - - conscell *rval; - char *tmplevel; - - stickytmp = stickymem; - stickymem = MEM_SHRET; - tmplevel = getlevel(MEM_SHRET); - - rval = s_copy_tree(command->rval); - stickymem = stickytmp; - - /* Release the level, caller's copy is in MEM_SHRET */ - setlevel(MEM_SHCMD, origlevel); - - /* Re-copy into MEM_SHCMD, or whatever.. */ - caller->rval = s_copy_tree(rval); - - /* And release that temp space */ - setlevel(MEM_SHRET, tmplevel); - } else -#endif /* MAILER */ - - /* Release the level, caller's copy is in MEM_TEMP */ - setlevel(MEM_SHCMD, origlevel); -#endif /* RETVAL_FREEUP */ while (margin != car(envarlist)) { d = car(envarlist); Index: libsh/listtrees.c =================================================================== RCS file: /home/mea/src/CVSROOT/zmailer/libsh/listtrees.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- listtrees.c 1999/04/02 19:26:00 1.3 +++ listtrees.c 1999/04/06 16:54:39 1.4 @@ -95,6 +95,8 @@ if (STRING(list)) { /* malloc new string and conscell to store it in */ new = copycell(list); + /* copycell() generates always just NEWSTRING, we preserve + some more flags... */ new->flags = (list->flags & ~CONSTSTRING) | NEWSTRING; cdr(new) = NULL; Index: proto/cf/server.cf =================================================================== RCS file: /home/mea/src/CVSROOT/zmailer/proto/cf/server.cf,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- server.cf 1999/03/08 10:24:02 1.2 +++ server.cf 1999/04/06 17:17:56 1.3 @@ -80,8 +80,8 @@ case "$key" in to|from|verify|expand) a="$1" - tsift "$a" in - <(.+)> a="\1" ;; + tsift "$a" in # "Defocus" brackets + <(.+)> a="\1"; continue ;; tfist if rfc822syntax "$a"; then ; else echo "554 illegal address syntax: <$a>" @@ -98,7 +98,7 @@ } ;; to|from) - a="$(router "$1" default_attributes)" + a="$(router "$a" default_attributes)" for i in $(elements $a) do for j in $(elements $i) @@ -117,7 +117,7 @@ echo "250 Ok (verified)" ;; verify) - a="$(router "$1" $A)" + a="$(router "$a" $A)" #| Invoke the router function with alias expansion turned off. for i in $(elements $a) do @@ -128,7 +128,7 @@ done ;; expand) - a="$(router "$1" $B)" + a="$(router "$a" $B)" #| Invoke the router function with alias expansion enabled. Index: smtpserver/policytest.c =================================================================== RCS file: /home/mea/src/CVSROOT/zmailer/smtpserver/policytest.c,v retrieving revision 1.25 retrieving revision 1.26 diff -u -r1.25 -r1.26 --- policytest.c 1999/03/08 10:16:14 1.25 +++ policytest.c 1999/04/05 15:43:50 1.26 @@ -643,10 +643,13 @@ } -static int _addrtest_(rel, state, pbuf) +static int _addrtest_ __((struct policytest *rel, struct policystate *state, const char *pbuf, int sourceaddr)); + +static int _addrtest_(rel, state, pbuf, sourceaddr) struct policytest *rel; struct policystate *state; const char *pbuf; +int sourceaddr; { u_char ipv4addr[4]; @@ -672,6 +675,9 @@ if (checkaddr(rel, state, pbuf) != 0) return 0; /* Nothing found */ + if (!sourceaddr) + goto just_rbl_checks; + #if 0 /* if (IP address of SMTP client has 'rejectnet +' attribute) then any further conversation refused @@ -742,6 +748,8 @@ if (state->trust_recipients || state->full_trust || state->always_accept) return 0; + just_rbl_checks:; + if (state->values[P_A_TestDnsRBL] && !valueeq(state->values[P_A_TestDnsRBL], "-") && pbuf[1] == P_K_IPv4) { @@ -826,7 +834,7 @@ return -2; } - return _addrtest_(rel, state, pbuf); + return _addrtest_(rel, state, pbuf, 1); } @@ -889,7 +897,7 @@ pbuf[1] = P_K_IPv4; pbuf[6] = 32; } - return _addrtest_(rel,state,pbuf); + return _addrtest_(rel,state,pbuf, 0); } plen = addr_len; Index: smtpserver/smtpchild.c =================================================================== RCS file: /home/mea/src/CVSROOT/zmailer/smtpserver/smtpchild.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- smtpchild.c 1999/03/19 15:17:42 1.2 +++ smtpchild.c 1999/04/05 14:46:06 1.3 @@ -30,7 +30,8 @@ int childcnt = 1; /* Ourself */ time(&child_now); - + + *childcntp = 1; if (childs == NULL) return 0; for (i = 0; i < child_top; ++i) { @@ -50,7 +51,7 @@ if (childs[i].pid != 0 && /* PID non zero */ addr->v4.sin_family == childs[i].addr.v4.sin_family) { - /* Same AddressFamily */ + /* Same AddressFamily */ if ((addr->v4.sin_family == AF_INET && /* Address is IPv4 one */ memcmp(& addr->v4.sin_addr, & childs[i].addr.v4.sin_addr, 4) == 0) @@ -60,10 +61,11 @@ /* ... or Address is IPv6 one */ memcmp(& addr->v6.sin6_addr, & childs[i].addr.v6.sin6_addr, 16) == 0)) #endif - ) + ) ++cnt; } - ++childcnt; + if (childs[i].pid != 0) + ++childcnt; } *childcntp = childcnt;