xref: /onnv-gate/usr/src/cmd/mailx/names.c (revision 18:7e2dc246c4e2)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
22*18Srobbin 
23*18Srobbin /*
24*18Srobbin  * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
25*18Srobbin  * Use is subject to license terms.
26*18Srobbin  */
27*18Srobbin 
280Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
290Sstevel@tonic-gate /*	  All Rights Reserved  	*/
300Sstevel@tonic-gate 
310Sstevel@tonic-gate /*
320Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
330Sstevel@tonic-gate  * The Regents of the University of California
340Sstevel@tonic-gate  * All Rights Reserved
350Sstevel@tonic-gate  *
360Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
370Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
380Sstevel@tonic-gate  * contributors.
390Sstevel@tonic-gate  */
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
420Sstevel@tonic-gate 
430Sstevel@tonic-gate /*
440Sstevel@tonic-gate  * mailx -- a modified version of a University of California at Berkeley
450Sstevel@tonic-gate  *	mail program
460Sstevel@tonic-gate  *
470Sstevel@tonic-gate  * Handle name lists.
480Sstevel@tonic-gate  */
490Sstevel@tonic-gate 
500Sstevel@tonic-gate #include "rcv.h"
510Sstevel@tonic-gate #include <locale.h>
520Sstevel@tonic-gate 
530Sstevel@tonic-gate static struct name	*nalloc(char str[]);
540Sstevel@tonic-gate static int		isfileaddr(char *name);
550Sstevel@tonic-gate static int		lengthof(struct name *name);
560Sstevel@tonic-gate static struct name	*gexpand(struct name *nlist, struct grouphead *gh, int metoo, int arg_ntype);
570Sstevel@tonic-gate static char		*norm(register char *user, register char *ubuf, int nbangs);
580Sstevel@tonic-gate static struct name	*put(struct name *list, struct name *node);
590Sstevel@tonic-gate 
600Sstevel@tonic-gate /*
610Sstevel@tonic-gate  * Allocate a single element of a name list,
620Sstevel@tonic-gate  * initialize its name field to the passed
630Sstevel@tonic-gate  * name and return it.
640Sstevel@tonic-gate  */
650Sstevel@tonic-gate 
660Sstevel@tonic-gate static struct name *
nalloc(char str[])670Sstevel@tonic-gate nalloc(char str[])
680Sstevel@tonic-gate {
690Sstevel@tonic-gate 	register struct name *np;
700Sstevel@tonic-gate 
710Sstevel@tonic-gate 	np = (struct name *) salloc(sizeof *np);
720Sstevel@tonic-gate 	np->n_flink = NIL;
730Sstevel@tonic-gate 	np->n_blink = NIL;
740Sstevel@tonic-gate 	np->n_type = -1;
750Sstevel@tonic-gate 	np->n_full = savestr(str);
760Sstevel@tonic-gate 	np->n_name = skin(np->n_full);
770Sstevel@tonic-gate 	return(np);
780Sstevel@tonic-gate }
790Sstevel@tonic-gate 
800Sstevel@tonic-gate /*
810Sstevel@tonic-gate  * Find the tail of a list and return it.
820Sstevel@tonic-gate  */
830Sstevel@tonic-gate 
840Sstevel@tonic-gate struct name *
tailof(struct name * name)850Sstevel@tonic-gate tailof(struct name *name)
860Sstevel@tonic-gate {
870Sstevel@tonic-gate 	register struct name *np;
880Sstevel@tonic-gate 
890Sstevel@tonic-gate 	np = name;
900Sstevel@tonic-gate 	if (np == NIL)
910Sstevel@tonic-gate 		return(NIL);
920Sstevel@tonic-gate 	while (np->n_flink != NIL)
930Sstevel@tonic-gate 		np = np->n_flink;
940Sstevel@tonic-gate 	return(np);
950Sstevel@tonic-gate }
960Sstevel@tonic-gate 
970Sstevel@tonic-gate /*
980Sstevel@tonic-gate  * Extract a list of names from a line,
990Sstevel@tonic-gate  * and make a list of names from it.
1000Sstevel@tonic-gate  * Return the list or NIL if none found.
1010Sstevel@tonic-gate  */
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate struct name *
extract(char line[],int arg_ntype)1040Sstevel@tonic-gate extract(char line[], int arg_ntype)
1050Sstevel@tonic-gate {
1060Sstevel@tonic-gate 	short ntype = (short)arg_ntype;
1070Sstevel@tonic-gate 	register char *cp;
1080Sstevel@tonic-gate 	register struct name *top, *np, *t;
1090Sstevel@tonic-gate 	char nbuf[BUFSIZ], abuf[BUFSIZ];
1100Sstevel@tonic-gate 	int comma;
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate 	if (line == NOSTR || strlen(line) == 0)
1130Sstevel@tonic-gate 		return(NIL);
1140Sstevel@tonic-gate 	comma = docomma(line);
1150Sstevel@tonic-gate 	top = NIL;
1160Sstevel@tonic-gate 	np = NIL;
1170Sstevel@tonic-gate 	cp = line;
1180Sstevel@tonic-gate 	while ((cp = yankword(cp, nbuf, sizeof (nbuf), comma)) != NOSTR) {
1190Sstevel@tonic-gate 		if (np != NIL && equal(nbuf, "at")) {
1200Sstevel@tonic-gate 			nstrcpy(abuf, sizeof (abuf), nbuf);
1210Sstevel@tonic-gate 			if ((cp = yankword(cp, nbuf, sizeof (nbuf),
1220Sstevel@tonic-gate 				comma)) == NOSTR) {
1230Sstevel@tonic-gate 				nstrcpy(nbuf, sizeof (nbuf), abuf);
1240Sstevel@tonic-gate 				goto normal;
1250Sstevel@tonic-gate 			}
1260Sstevel@tonic-gate 			snprintf(abuf, sizeof (abuf), "%s@%s", np->n_name,
1270Sstevel@tonic-gate 				nbuf);
1280Sstevel@tonic-gate 			np->n_name = savestr(abuf);
1290Sstevel@tonic-gate 			continue;
1300Sstevel@tonic-gate 		}
1310Sstevel@tonic-gate normal:
1320Sstevel@tonic-gate 		t = nalloc(nbuf);
1330Sstevel@tonic-gate 		t->n_type = ntype;
1340Sstevel@tonic-gate 		if (top == NIL)
1350Sstevel@tonic-gate 			top = t;
1360Sstevel@tonic-gate 		else
1370Sstevel@tonic-gate 			np->n_flink = t;
1380Sstevel@tonic-gate 		t->n_blink = np;
1390Sstevel@tonic-gate 		np = t;
1400Sstevel@tonic-gate 	}
1410Sstevel@tonic-gate 	return(top);
1420Sstevel@tonic-gate }
1430Sstevel@tonic-gate 
1440Sstevel@tonic-gate /*
1450Sstevel@tonic-gate  * Turn a list of names into a string of the same names.
1460Sstevel@tonic-gate  */
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate char *
detract(register struct name * np,int ntype)1490Sstevel@tonic-gate detract(register struct name *np, int ntype)
1500Sstevel@tonic-gate {
1510Sstevel@tonic-gate 	register int s;
1520Sstevel@tonic-gate 	register char *cp, *top;
1530Sstevel@tonic-gate 	register struct name *p;
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate 	if (np == NIL)
1560Sstevel@tonic-gate 		return(NOSTR);
1570Sstevel@tonic-gate 	s = 0;
1580Sstevel@tonic-gate 	for (p = np; p != NIL; p = p->n_flink) {
1590Sstevel@tonic-gate 		if ((ntype && (p->n_type & GMASK) != ntype)
1600Sstevel@tonic-gate 		 || (p->n_type & GDEL))
1610Sstevel@tonic-gate 			continue;
1620Sstevel@tonic-gate 		s += strlen(p->n_full) + 2;
1630Sstevel@tonic-gate 	}
1640Sstevel@tonic-gate 	if (s == 0)
1650Sstevel@tonic-gate 		return(NOSTR);
1660Sstevel@tonic-gate 	top = (char *)salloc((unsigned)(++s));
1670Sstevel@tonic-gate 	cp = top;
1680Sstevel@tonic-gate 	for (p = np; p != NIL; p = p->n_flink) {
1690Sstevel@tonic-gate 		if ((ntype && (p->n_type & GMASK) != ntype)
1700Sstevel@tonic-gate 		 || (p->n_type & GDEL))
1710Sstevel@tonic-gate 			continue;
1720Sstevel@tonic-gate 		cp = copy(p->n_full, cp);
1730Sstevel@tonic-gate 		*cp++ = ',';
1740Sstevel@tonic-gate 		*cp++ = ' ';
1750Sstevel@tonic-gate 	}
1760Sstevel@tonic-gate 	*cp = 0;
1770Sstevel@tonic-gate 	return(top);
1780Sstevel@tonic-gate }
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate struct name *
outpre(struct name * to)1810Sstevel@tonic-gate outpre(struct name *to)
1820Sstevel@tonic-gate {
1830Sstevel@tonic-gate 	register struct name *np;
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate 	for (np = to; np; np = np->n_flink)
1860Sstevel@tonic-gate 		if (isfileaddr(np->n_name))
1870Sstevel@tonic-gate 			np->n_type |= GDEL;
1880Sstevel@tonic-gate 	return to;
1890Sstevel@tonic-gate }
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate /*
1920Sstevel@tonic-gate  * For each recipient in the passed name list with a /
1930Sstevel@tonic-gate  * in the name, append the message to the end of the named file
1940Sstevel@tonic-gate  * and remove him from the recipient list.
1950Sstevel@tonic-gate  *
1960Sstevel@tonic-gate  * Recipients whose name begins with | are piped through the given
1970Sstevel@tonic-gate  * program and removed.
1980Sstevel@tonic-gate  */
1990Sstevel@tonic-gate 
2000Sstevel@tonic-gate int
outof(struct name * names,FILE * fo)2010Sstevel@tonic-gate outof(struct name *names, FILE *fo)
2020Sstevel@tonic-gate {
2030Sstevel@tonic-gate 	register int c;
2040Sstevel@tonic-gate 	register struct name *np;
2050Sstevel@tonic-gate 	time_t now;
2060Sstevel@tonic-gate 	char *date, *fname, *shell;
2070Sstevel@tonic-gate 	FILE *fout, *fin;
2080Sstevel@tonic-gate 	int ispipe;
2090Sstevel@tonic-gate 	int nout = 0;
2100Sstevel@tonic-gate 	int fd = 0;
2110Sstevel@tonic-gate #ifdef preSVr4
2120Sstevel@tonic-gate 	char line[BUFSIZ];
2130Sstevel@tonic-gate #endif
2140Sstevel@tonic-gate 
2150Sstevel@tonic-gate 	for (np = names; np != NIL; np = np->n_flink) {
2160Sstevel@tonic-gate 		if (!isfileaddr(np->n_name) && np->n_name[0] != '|')
2170Sstevel@tonic-gate 			continue;
2180Sstevel@tonic-gate 		nout++;
2190Sstevel@tonic-gate 		ispipe = np->n_name[0] == '|';
2200Sstevel@tonic-gate 		if (ispipe)
2210Sstevel@tonic-gate 			fname = np->n_name+1;
2220Sstevel@tonic-gate 		else
2230Sstevel@tonic-gate 			fname = safeexpand(np->n_name);
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate 		/*
2260Sstevel@tonic-gate 		 * See if we have copied the complete message out yet.
2270Sstevel@tonic-gate 		 * If not, do so.
2280Sstevel@tonic-gate 		 */
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate 		if (image < 0) {
2310Sstevel@tonic-gate 			fd = open(tempEdit, O_CREAT|O_EXCL|O_APPEND|O_WRONLY,
2320Sstevel@tonic-gate 					0600);
2330Sstevel@tonic-gate 			if ((fd  < 0) && (errno == EEXIST)) {
2340Sstevel@tonic-gate 				if ((fd = open(tempEdit, O_APPEND|O_WRONLY,
2350Sstevel@tonic-gate 						0600)) < 0) {
2360Sstevel@tonic-gate 					perror(tempEdit);
2370Sstevel@tonic-gate 					senderr++;
2380Sstevel@tonic-gate 					goto cant;
2390Sstevel@tonic-gate 				}
2400Sstevel@tonic-gate 			}
2410Sstevel@tonic-gate 			if ((fout = fdopen(fd, "a")) == NULL) {
2420Sstevel@tonic-gate 				perror(tempEdit);
2430Sstevel@tonic-gate 				senderr++;
2440Sstevel@tonic-gate 				goto cant;
2450Sstevel@tonic-gate 			}
2460Sstevel@tonic-gate 			image = open(tempEdit, O_RDWR);
2470Sstevel@tonic-gate 			unlink(tempEdit);
2480Sstevel@tonic-gate 			if (image < 0) {
2490Sstevel@tonic-gate 				perror(tempEdit);
2500Sstevel@tonic-gate 				senderr++;
2510Sstevel@tonic-gate 				goto cant;
2520Sstevel@tonic-gate 			} else {
2530Sstevel@tonic-gate 				rewind(fo);
2540Sstevel@tonic-gate 				time(&now);
2550Sstevel@tonic-gate 				date = ctime(&now);
2560Sstevel@tonic-gate 				fprintf(fout, "From %s %s", myname, date);
2570Sstevel@tonic-gate 				while ((c = getc(fo)) != EOF)
2580Sstevel@tonic-gate 					putc(c, fout);
2590Sstevel@tonic-gate 				rewind(fo);
2600Sstevel@tonic-gate 				fflush(fout);
2610Sstevel@tonic-gate 				if (fferror(fout))
2620Sstevel@tonic-gate 					perror(tempEdit);
2630Sstevel@tonic-gate 				fclose(fout);
2640Sstevel@tonic-gate 			}
2650Sstevel@tonic-gate 		}
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate 		/*
2680Sstevel@tonic-gate 		 * Now either copy "image" to the desired file
2690Sstevel@tonic-gate 		 * or give it as the standard input to the desired
2700Sstevel@tonic-gate 		 * program as appropriate.
2710Sstevel@tonic-gate 		 */
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate 		if (ispipe) {
2740Sstevel@tonic-gate 			wait((int *)NULL);
2750Sstevel@tonic-gate 			switch (fork()) {
2760Sstevel@tonic-gate 			case 0:
2770Sstevel@tonic-gate 				sigchild();
2780Sstevel@tonic-gate 				sigset(SIGHUP, SIG_IGN);
2790Sstevel@tonic-gate 				sigset(SIGINT, SIG_IGN);
2800Sstevel@tonic-gate 				sigset(SIGQUIT, SIG_IGN);
2810Sstevel@tonic-gate 				close(0);
2820Sstevel@tonic-gate 				dup(image);
2830Sstevel@tonic-gate 				close(image);
2840Sstevel@tonic-gate 				lseek(0, 0L, 0);
2850Sstevel@tonic-gate 				if ((shell = value("SHELL")) == NOSTR || *shell=='\0')
2860Sstevel@tonic-gate 					shell = SHELL;
2870Sstevel@tonic-gate 				(void) execlp(shell, shell, "-c", fname, (char *)0);
2880Sstevel@tonic-gate 				perror(shell);
2890Sstevel@tonic-gate 				exit(1);
2900Sstevel@tonic-gate 				break;
2910Sstevel@tonic-gate 
2920Sstevel@tonic-gate 			case (pid_t)-1:
2930Sstevel@tonic-gate 				perror("fork");
2940Sstevel@tonic-gate 				senderr++;
2950Sstevel@tonic-gate 				goto cant;
2960Sstevel@tonic-gate 			}
2970Sstevel@tonic-gate 		}
2980Sstevel@tonic-gate 		else {
2990Sstevel@tonic-gate 			if ((fout = fopen(fname, "a")) == NULL) {
3000Sstevel@tonic-gate 				perror(fname);
3010Sstevel@tonic-gate 				senderr++;
3020Sstevel@tonic-gate 				goto cant;
3030Sstevel@tonic-gate 			}
3040Sstevel@tonic-gate 			fin = Fdopen(image, "r");
3050Sstevel@tonic-gate 			if (fin == NULL) {
3060Sstevel@tonic-gate 				fprintf(stderr,
3070Sstevel@tonic-gate 				    gettext("Can't reopen image\n"));
3080Sstevel@tonic-gate 				fclose(fout);
3090Sstevel@tonic-gate 				senderr++;
3100Sstevel@tonic-gate 				goto cant;
3110Sstevel@tonic-gate 			}
3120Sstevel@tonic-gate 			rewind(fin);
3130Sstevel@tonic-gate #ifdef preSVr4
3140Sstevel@tonic-gate 			putc(getc(fin), fout);
3150Sstevel@tonic-gate 			while (fgets(line, sizeof line, fin)) {
3160Sstevel@tonic-gate 				if (!strncmp(line, "From ", 5))
3170Sstevel@tonic-gate 					putc('>', fout);
3180Sstevel@tonic-gate 				fputs(line, fout);
3190Sstevel@tonic-gate 			}
3200Sstevel@tonic-gate #else
3210Sstevel@tonic-gate 			while ((c = getc(fin)) != EOF)
3220Sstevel@tonic-gate 				putc(c, fout);
3230Sstevel@tonic-gate #endif
3240Sstevel@tonic-gate 			putc('\n', fout);
3250Sstevel@tonic-gate 			fflush(fout);
3260Sstevel@tonic-gate 			if (fferror(fout))
3270Sstevel@tonic-gate 				senderr++, perror(fname);
3280Sstevel@tonic-gate 			fclose(fout);
3290Sstevel@tonic-gate 			fclose(fin);
3300Sstevel@tonic-gate 		}
3310Sstevel@tonic-gate cant:
3320Sstevel@tonic-gate 		/*
3330Sstevel@tonic-gate 		 * In days of old we removed the entry from the
3340Sstevel@tonic-gate 		 * the list; now for sake of header expansion
3350Sstevel@tonic-gate 		 * we leave it in and mark it as deleted.
3360Sstevel@tonic-gate 		 */
3370Sstevel@tonic-gate 
3380Sstevel@tonic-gate #ifdef CRAZYWOW
3390Sstevel@tonic-gate 		{
3400Sstevel@tonic-gate 		register struct name *t, *x;
3410Sstevel@tonic-gate 
3420Sstevel@tonic-gate 		if (np == top) {
3430Sstevel@tonic-gate 			top = np->n_flink;
3440Sstevel@tonic-gate 			if (top != NIL)
3450Sstevel@tonic-gate 				top->n_blink = NIL;
3460Sstevel@tonic-gate 			np = top;
3470Sstevel@tonic-gate 			continue;
3480Sstevel@tonic-gate 		}
3490Sstevel@tonic-gate 		x = np->n_blink;
3500Sstevel@tonic-gate 		t = np->n_flink;
3510Sstevel@tonic-gate 		x->n_flink = t;
3520Sstevel@tonic-gate 		if (t != NIL)
3530Sstevel@tonic-gate 			t->n_blink = x;
3540Sstevel@tonic-gate 		np = t;
3550Sstevel@tonic-gate 		}
3560Sstevel@tonic-gate #endif
3570Sstevel@tonic-gate 
3580Sstevel@tonic-gate 		np->n_type |= GDEL;
3590Sstevel@tonic-gate 	}
3600Sstevel@tonic-gate 	if (image >= 0) {
3610Sstevel@tonic-gate 		close(image);
3620Sstevel@tonic-gate 		image = -1;
3630Sstevel@tonic-gate 	}
3640Sstevel@tonic-gate 	return(nout);
3650Sstevel@tonic-gate }
3660Sstevel@tonic-gate 
3670Sstevel@tonic-gate /*
3680Sstevel@tonic-gate  * Determine if the passed address is a local "send to file" address.
3690Sstevel@tonic-gate  * If any of the network metacharacters precedes any slashes, it can't
3700Sstevel@tonic-gate  * be a filename.  We cheat with .'s to allow path names like ./...
3710Sstevel@tonic-gate  * If "fcc" has been unset, then short-circuit those tests, but not
3720Sstevel@tonic-gate  * the +... test.
3730Sstevel@tonic-gate  */
3740Sstevel@tonic-gate static int
isfileaddr(char * name)3750Sstevel@tonic-gate isfileaddr(char *name)
3760Sstevel@tonic-gate {
3770Sstevel@tonic-gate 	register char *cp;
3780Sstevel@tonic-gate 	char *fcc = value("fcc");
3790Sstevel@tonic-gate 
3800Sstevel@tonic-gate 	if (any('@', name))
3810Sstevel@tonic-gate 		return(0);
3820Sstevel@tonic-gate 	if (*name == '+')
3830Sstevel@tonic-gate 		return(1);
3840Sstevel@tonic-gate 	if (fcc == NOSTR)
3850Sstevel@tonic-gate 		return(0);
3860Sstevel@tonic-gate 	for (cp = name; *cp; cp++) {
3870Sstevel@tonic-gate 		if (*cp == '.')
3880Sstevel@tonic-gate 			continue;
3890Sstevel@tonic-gate 		if (any(*cp, metanet))
3900Sstevel@tonic-gate 			return(0);
3910Sstevel@tonic-gate 		if (*cp == '/')
3920Sstevel@tonic-gate 			return(1);
3930Sstevel@tonic-gate 	}
3940Sstevel@tonic-gate 	return(0);
3950Sstevel@tonic-gate }
3960Sstevel@tonic-gate 
3970Sstevel@tonic-gate /*
3980Sstevel@tonic-gate  * Map all of the aliased users in the invoker's mailrc
3990Sstevel@tonic-gate  * file and insert them into the list.
4000Sstevel@tonic-gate  * Changed after all these months of service to recursively
4010Sstevel@tonic-gate  * expand names (2/14/80).
4020Sstevel@tonic-gate  */
4030Sstevel@tonic-gate 
4040Sstevel@tonic-gate struct name *
usermap(struct name * names)4050Sstevel@tonic-gate usermap(struct name *names)
4060Sstevel@tonic-gate {
4070Sstevel@tonic-gate 	register struct name *newnames, *np, *cp;
4080Sstevel@tonic-gate 	struct grouphead *gh;
4090Sstevel@tonic-gate 	register int metoo;
4100Sstevel@tonic-gate 
4110Sstevel@tonic-gate 	newnames = NIL;
4120Sstevel@tonic-gate 	np = names;
4130Sstevel@tonic-gate 	metoo = (value("metoo") != NOSTR);
4140Sstevel@tonic-gate 	while (np != NIL) {
4150Sstevel@tonic-gate 		if (np->n_name[0] == '\\') {
4160Sstevel@tonic-gate 			cp = np->n_flink;
4170Sstevel@tonic-gate 			newnames = put(newnames, np);
4180Sstevel@tonic-gate 			np = cp;
4190Sstevel@tonic-gate 			continue;
4200Sstevel@tonic-gate 		}
4210Sstevel@tonic-gate 		gh = findgroup(np->n_name);
4220Sstevel@tonic-gate 		cp = np->n_flink;
4230Sstevel@tonic-gate 		if (gh != NOGRP)
4240Sstevel@tonic-gate 			newnames = gexpand(newnames, gh, metoo, np->n_type);
4250Sstevel@tonic-gate 		else
4260Sstevel@tonic-gate 			newnames = put(newnames, np);
4270Sstevel@tonic-gate 		np = cp;
4280Sstevel@tonic-gate 	}
4290Sstevel@tonic-gate 	return(newnames);
4300Sstevel@tonic-gate }
4310Sstevel@tonic-gate 
4320Sstevel@tonic-gate /*
4330Sstevel@tonic-gate  * Recursively expand a group name.  We limit the expansion to some
4340Sstevel@tonic-gate  * fixed level to keep things from going haywire.
4350Sstevel@tonic-gate  * Direct recursion is not expanded for convenience.
4360Sstevel@tonic-gate  */
4370Sstevel@tonic-gate 
4380Sstevel@tonic-gate static struct name *
gexpand(struct name * nlist,struct grouphead * gh,int metoo,int arg_ntype)4390Sstevel@tonic-gate gexpand(struct name *nlist, struct grouphead *gh, int metoo, int arg_ntype)
4400Sstevel@tonic-gate {
4410Sstevel@tonic-gate 	short ntype = (short)arg_ntype;
4420Sstevel@tonic-gate 	struct mgroup *gp;
4430Sstevel@tonic-gate 	struct grouphead *ngh;
4440Sstevel@tonic-gate 	struct name *np;
4450Sstevel@tonic-gate 	static int depth;
4460Sstevel@tonic-gate 	register char *cp;
4470Sstevel@tonic-gate 
4480Sstevel@tonic-gate 	if (depth > MAXEXP) {
4490Sstevel@tonic-gate 		printf(gettext("Expanding alias to depth larger than %d\n"),
4500Sstevel@tonic-gate 		    MAXEXP);
4510Sstevel@tonic-gate 		return(nlist);
4520Sstevel@tonic-gate 	}
4530Sstevel@tonic-gate 	depth++;
4540Sstevel@tonic-gate 	for (gp = gh->g_list; gp != NOGE; gp = gp->ge_link) {
4550Sstevel@tonic-gate 		cp = gp->ge_name;
4560Sstevel@tonic-gate 		if (*cp == '\\')
4570Sstevel@tonic-gate 			goto quote;
4580Sstevel@tonic-gate 		if (strcmp(cp, gh->g_name) == 0)
4590Sstevel@tonic-gate 			goto quote;
4600Sstevel@tonic-gate 		if ((ngh = findgroup(cp)) != NOGRP) {
4610Sstevel@tonic-gate 			nlist = gexpand(nlist, ngh, metoo, ntype);
4620Sstevel@tonic-gate 			continue;
4630Sstevel@tonic-gate 		}
4640Sstevel@tonic-gate quote:
4650Sstevel@tonic-gate 		np = nalloc(cp);
4660Sstevel@tonic-gate 		np->n_type = ntype;
4670Sstevel@tonic-gate 		/*
4680Sstevel@tonic-gate 		 * At this point should allow to expand
4690Sstevel@tonic-gate 		 * to self if only person in group
4700Sstevel@tonic-gate 		 */
4710Sstevel@tonic-gate 		if (gp == gh->g_list && gp->ge_link == NOGE)
4720Sstevel@tonic-gate 			goto skip;
4730Sstevel@tonic-gate 		if (!metoo && samebody(myname, gp->ge_name, FALSE))
4740Sstevel@tonic-gate 			np->n_type |= GDEL;
4750Sstevel@tonic-gate skip:
4760Sstevel@tonic-gate 		nlist = put(nlist, np);
4770Sstevel@tonic-gate 	}
4780Sstevel@tonic-gate 	depth--;
4790Sstevel@tonic-gate 	return(nlist);
4800Sstevel@tonic-gate }
4810Sstevel@tonic-gate 
4820Sstevel@tonic-gate /*
4830Sstevel@tonic-gate  * Normalize a network name for comparison purposes.
4840Sstevel@tonic-gate  */
4850Sstevel@tonic-gate static char *
norm(register char * user,register char * ubuf,int nbangs)4860Sstevel@tonic-gate norm(register char *user, register char *ubuf, int nbangs)
4870Sstevel@tonic-gate {
4880Sstevel@tonic-gate 	register char *cp;
4890Sstevel@tonic-gate 	int inubuf = 0;
4900Sstevel@tonic-gate 
4910Sstevel@tonic-gate 	while (*user++ == '!');
4920Sstevel@tonic-gate 	user--;
4930Sstevel@tonic-gate 	if (!strchr(user, '!')) {
4940Sstevel@tonic-gate 		snprintf(ubuf, BUFSIZ, "%s!%s", host, user);
4950Sstevel@tonic-gate 		user = ubuf;
4960Sstevel@tonic-gate 		inubuf++;
4970Sstevel@tonic-gate 	}
4980Sstevel@tonic-gate 	if (nbangs) {
4990Sstevel@tonic-gate 		cp = user + strlen(user);
5000Sstevel@tonic-gate 		while (nbangs--)
5010Sstevel@tonic-gate 			while (cp > user && *--cp != '!');
5020Sstevel@tonic-gate 		user = (cp > user) ? ++cp : cp;
5030Sstevel@tonic-gate 		/*
5040Sstevel@tonic-gate 		 * Now strip off all Internet-type
5050Sstevel@tonic-gate 		 * hosts.
5060Sstevel@tonic-gate 		 */
5070Sstevel@tonic-gate 		if ((cp = strchr(user, '%')) == NOSTR)
5080Sstevel@tonic-gate 			cp = strchr(user, '@');
5090Sstevel@tonic-gate 		if (cp != NOSTR) {
5100Sstevel@tonic-gate 			if (!inubuf) {
5110Sstevel@tonic-gate 				strncpy(ubuf, user, cp - user);
5120Sstevel@tonic-gate 				ubuf[cp - user] = '\0';
5130Sstevel@tonic-gate 				user = ubuf;
5140Sstevel@tonic-gate 			} else
5150Sstevel@tonic-gate 				*cp = '\0';
5160Sstevel@tonic-gate 		}
5170Sstevel@tonic-gate 	}
5180Sstevel@tonic-gate 	return user;
5190Sstevel@tonic-gate }
5200Sstevel@tonic-gate 
5210Sstevel@tonic-gate /*
5220Sstevel@tonic-gate  * Implement allnet options.
5230Sstevel@tonic-gate  */
5240Sstevel@tonic-gate int
samebody(register char * user,register char * addr,int fuzzy)5250Sstevel@tonic-gate samebody(register char *user, register char *addr, int fuzzy)
5260Sstevel@tonic-gate {
5270Sstevel@tonic-gate 	char ubuf[BUFSIZ], abuf[BUFSIZ];
5280Sstevel@tonic-gate 	char *allnet = value("allnet");
5290Sstevel@tonic-gate 	int nbangs = allnet ? !strcmp(allnet, "uucp") ? 2 : 1 : 0;
5300Sstevel@tonic-gate 
5310Sstevel@tonic-gate 	if (fuzzy && value("fuzzymatch")) {
5320Sstevel@tonic-gate 		int i;
5330Sstevel@tonic-gate 
5340Sstevel@tonic-gate 		(void) strlcpy(ubuf, user, BUFSIZ);
5350Sstevel@tonic-gate 		for (i = 0; ubuf[i]; i++)
5360Sstevel@tonic-gate 			ubuf[i] = tolower(ubuf[i]);
5370Sstevel@tonic-gate 		(void) strlcpy(abuf, addr, BUFSIZ);
5380Sstevel@tonic-gate 		for (i = 0; abuf[i]; i++)
5390Sstevel@tonic-gate 			abuf[i] = tolower(abuf[i]);
5400Sstevel@tonic-gate 		return (strstr(abuf, ubuf) != NOSTR);
5410Sstevel@tonic-gate 	}
5420Sstevel@tonic-gate 	user = norm(user, ubuf, nbangs);
5430Sstevel@tonic-gate 	addr = norm(addr, abuf, nbangs);
5440Sstevel@tonic-gate 	return strcmp(user, addr) == 0;
5450Sstevel@tonic-gate }
5460Sstevel@tonic-gate 
5470Sstevel@tonic-gate /*
5480Sstevel@tonic-gate  * Compute the length of the passed name list and
5490Sstevel@tonic-gate  * return it.
5500Sstevel@tonic-gate  */
5510Sstevel@tonic-gate static int
lengthof(struct name * name)5520Sstevel@tonic-gate lengthof(struct name *name)
5530Sstevel@tonic-gate {
5540Sstevel@tonic-gate 	register struct name *np;
5550Sstevel@tonic-gate 	register int c;
5560Sstevel@tonic-gate 
5570Sstevel@tonic-gate 	for (c = 0, np = name; np != NIL; c++, np = np->n_flink)
5580Sstevel@tonic-gate 		;
5590Sstevel@tonic-gate 	return(c);
5600Sstevel@tonic-gate }
5610Sstevel@tonic-gate 
5620Sstevel@tonic-gate /*
5630Sstevel@tonic-gate  * Concatenate the two passed name lists, return the result.
5640Sstevel@tonic-gate  */
5650Sstevel@tonic-gate 
5660Sstevel@tonic-gate struct name *
cat(struct name * n1,struct name * n2)5670Sstevel@tonic-gate cat(struct name *n1, struct name *n2)
5680Sstevel@tonic-gate {
5690Sstevel@tonic-gate 	register struct name *tail;
5700Sstevel@tonic-gate 
5710Sstevel@tonic-gate 	if (n1 == NIL)
5720Sstevel@tonic-gate 		return(n2);
5730Sstevel@tonic-gate 	if (n2 == NIL)
5740Sstevel@tonic-gate 		return(n1);
5750Sstevel@tonic-gate 	tail = tailof(n1);
5760Sstevel@tonic-gate 	tail->n_flink = n2;
5770Sstevel@tonic-gate 	n2->n_blink = tail;
5780Sstevel@tonic-gate 	return(n1);
5790Sstevel@tonic-gate }
5800Sstevel@tonic-gate 
5810Sstevel@tonic-gate /*
5820Sstevel@tonic-gate  * Unpack the name list onto a vector of strings.
5830Sstevel@tonic-gate  * Return an error if the name list won't fit.
5840Sstevel@tonic-gate  */
5850Sstevel@tonic-gate 
5860Sstevel@tonic-gate char **
unpack(struct name * np)5870Sstevel@tonic-gate unpack(struct name *np)
5880Sstevel@tonic-gate {
5890Sstevel@tonic-gate 	register char **ap, **top;
5900Sstevel@tonic-gate 	register struct name *n;
5910Sstevel@tonic-gate 	char hbuf[10];
5920Sstevel@tonic-gate 	int t, extra, metoo, verbose;
5930Sstevel@tonic-gate 
5940Sstevel@tonic-gate 	n = np;
5950Sstevel@tonic-gate 	if ((t = lengthof(n)) == 0)
5960Sstevel@tonic-gate 		panic("No names to unpack");
5970Sstevel@tonic-gate 
5980Sstevel@tonic-gate 	/*
5990Sstevel@tonic-gate 	 * Compute the number of extra arguments we will need.
6000Sstevel@tonic-gate 	 * We need at least 2 extra -- one for "mail" and one for
6010Sstevel@tonic-gate 	 * the terminating 0 pointer.
6020Sstevel@tonic-gate 	 * Additional spots may be needed to pass along -r and -f to
6030Sstevel@tonic-gate 	 * the host mailer.
6040Sstevel@tonic-gate 	 */
6050Sstevel@tonic-gate 
6060Sstevel@tonic-gate 	extra = 2;
6070Sstevel@tonic-gate 
6080Sstevel@tonic-gate 	if (rflag != NOSTR)
6090Sstevel@tonic-gate 		extra += 2;
6100Sstevel@tonic-gate #ifdef SENDMAIL
6110Sstevel@tonic-gate 	extra++;
6120Sstevel@tonic-gate 	metoo = value("metoo") != NOSTR;
6130Sstevel@tonic-gate 	if (metoo)
6140Sstevel@tonic-gate 		extra++;
6150Sstevel@tonic-gate 	verbose = value("verbose") != NOSTR;
6160Sstevel@tonic-gate 	if (verbose)
6170Sstevel@tonic-gate 		extra++;
6180Sstevel@tonic-gate 	if (hflag)
6190Sstevel@tonic-gate 		extra += 2;
620*18Srobbin #endif /* SENDMAIL */
6210Sstevel@tonic-gate 	top = (char **) salloc((t + extra) * sizeof (char *));
6220Sstevel@tonic-gate 	ap = top;
6230Sstevel@tonic-gate 	*ap++ = "mail";
6240Sstevel@tonic-gate 	if (rflag != NOSTR) {
6250Sstevel@tonic-gate 		*ap++ = "-r";
6260Sstevel@tonic-gate 		*ap++ = rflag;
6270Sstevel@tonic-gate 	}
6280Sstevel@tonic-gate #ifdef SENDMAIL
6290Sstevel@tonic-gate 	*ap++ = "-i";
6300Sstevel@tonic-gate 	if (metoo)
6310Sstevel@tonic-gate 		*ap++ = "-m";
6320Sstevel@tonic-gate 	if (verbose)
6330Sstevel@tonic-gate 		*ap++ = "-v";
6340Sstevel@tonic-gate 	if (hflag) {
6350Sstevel@tonic-gate 		*ap++ = "-h";
6360Sstevel@tonic-gate 		snprintf(hbuf, sizeof (hbuf), "%d", hflag);
6370Sstevel@tonic-gate 		*ap++ = savestr(hbuf);
6380Sstevel@tonic-gate 	}
639*18Srobbin #endif /* SENDMAIL */
6400Sstevel@tonic-gate 	while (n != NIL) {
6410Sstevel@tonic-gate 		if (n->n_type & GDEL) {
6420Sstevel@tonic-gate 			n = n->n_flink;
6430Sstevel@tonic-gate 			continue;
6440Sstevel@tonic-gate 		}
6450Sstevel@tonic-gate 		*ap++ = n->n_name;
6460Sstevel@tonic-gate 		n = n->n_flink;
6470Sstevel@tonic-gate 	}
6480Sstevel@tonic-gate 	*ap = NOSTR;
6490Sstevel@tonic-gate 	return(top);
6500Sstevel@tonic-gate }
6510Sstevel@tonic-gate 
6520Sstevel@tonic-gate /*
6530Sstevel@tonic-gate  * See if the user named himself as a destination
6540Sstevel@tonic-gate  * for outgoing mail.  If so, set the global flag
6550Sstevel@tonic-gate  * selfsent so that we avoid removing his mailbox.
6560Sstevel@tonic-gate  */
6570Sstevel@tonic-gate 
6580Sstevel@tonic-gate void
mechk(struct name * names)6590Sstevel@tonic-gate mechk(struct name *names)
6600Sstevel@tonic-gate {
6610Sstevel@tonic-gate 	register struct name *np;
6620Sstevel@tonic-gate 
6630Sstevel@tonic-gate 	for (np = names; np != NIL; np = np->n_flink)
6640Sstevel@tonic-gate 		if ((np->n_type & GDEL) == 0 &&
6650Sstevel@tonic-gate 		    samebody(np->n_name, myname, FALSE)) {
6660Sstevel@tonic-gate 			selfsent++;
6670Sstevel@tonic-gate 			return;
6680Sstevel@tonic-gate 		}
6690Sstevel@tonic-gate }
6700Sstevel@tonic-gate 
6710Sstevel@tonic-gate /*
6720Sstevel@tonic-gate  * Remove all of the duplicates from the passed name list by
6730Sstevel@tonic-gate  * insertion sorting them, then checking for dups.
6740Sstevel@tonic-gate  * Return the head of the new list.
6750Sstevel@tonic-gate  */
6760Sstevel@tonic-gate 
6770Sstevel@tonic-gate struct name *
elide(struct name * names)6780Sstevel@tonic-gate elide(struct name *names)
6790Sstevel@tonic-gate {
6800Sstevel@tonic-gate 	register struct name *np, *t, *newnames;
6810Sstevel@tonic-gate 	struct name *x;
6820Sstevel@tonic-gate 
6830Sstevel@tonic-gate 	if (names == NIL)
6840Sstevel@tonic-gate 		return(NIL);
6850Sstevel@tonic-gate 	newnames = names;
6860Sstevel@tonic-gate 	np = names;
6870Sstevel@tonic-gate 	np = np->n_flink;
6880Sstevel@tonic-gate 	if (np != NIL)
6890Sstevel@tonic-gate 		np->n_blink = NIL;
6900Sstevel@tonic-gate 	newnames->n_flink = NIL;
6910Sstevel@tonic-gate 	while (np != NIL) {
6920Sstevel@tonic-gate 		t = newnames;
6930Sstevel@tonic-gate 		while (strcmp(t->n_name, np->n_name) < 0) {
6940Sstevel@tonic-gate 			if (t->n_flink == NIL)
6950Sstevel@tonic-gate 				break;
6960Sstevel@tonic-gate 			t = t->n_flink;
6970Sstevel@tonic-gate 		}
6980Sstevel@tonic-gate 
6990Sstevel@tonic-gate 		/*
7000Sstevel@tonic-gate 		 * If we ran out of t's, put the new entry after
7010Sstevel@tonic-gate 		 * the current value of t.
7020Sstevel@tonic-gate 		 */
7030Sstevel@tonic-gate 
7040Sstevel@tonic-gate 		if (strcmp(t->n_name, np->n_name) < 0) {
7050Sstevel@tonic-gate 			t->n_flink = np;
7060Sstevel@tonic-gate 			np->n_blink = t;
7070Sstevel@tonic-gate 			t = np;
7080Sstevel@tonic-gate 			np = np->n_flink;
7090Sstevel@tonic-gate 			t->n_flink = NIL;
7100Sstevel@tonic-gate 			continue;
7110Sstevel@tonic-gate 		}
7120Sstevel@tonic-gate 
7130Sstevel@tonic-gate 		/*
7140Sstevel@tonic-gate 		 * Otherwise, put the new entry in front of the
7150Sstevel@tonic-gate 		 * current t.  If at the front of the list,
7160Sstevel@tonic-gate 		 * the new guy becomes the new head of the list.
7170Sstevel@tonic-gate 		 */
7180Sstevel@tonic-gate 
7190Sstevel@tonic-gate 		if (t == newnames) {
7200Sstevel@tonic-gate 			t = np;
7210Sstevel@tonic-gate 			np = np->n_flink;
7220Sstevel@tonic-gate 			t->n_flink = newnames;
7230Sstevel@tonic-gate 			newnames->n_blink = t;
7240Sstevel@tonic-gate 			t->n_blink = NIL;
7250Sstevel@tonic-gate 			newnames = t;
7260Sstevel@tonic-gate 			continue;
7270Sstevel@tonic-gate 		}
7280Sstevel@tonic-gate 
7290Sstevel@tonic-gate 		/*
7300Sstevel@tonic-gate 		 * The normal case -- we are inserting into the
7310Sstevel@tonic-gate 		 * middle of the list.
7320Sstevel@tonic-gate 		 */
7330Sstevel@tonic-gate 
7340Sstevel@tonic-gate 		x = np;
7350Sstevel@tonic-gate 		np = np->n_flink;
7360Sstevel@tonic-gate 		x->n_flink = t;
7370Sstevel@tonic-gate 		x->n_blink = t->n_blink;
7380Sstevel@tonic-gate 		t->n_blink->n_flink = x;
7390Sstevel@tonic-gate 		t->n_blink = x;
7400Sstevel@tonic-gate 	}
7410Sstevel@tonic-gate 
7420Sstevel@tonic-gate 	/*
7430Sstevel@tonic-gate 	 * Now the list headed up by new is sorted.
7440Sstevel@tonic-gate 	 * Go through it and remove duplicates.
7450Sstevel@tonic-gate 	 * Remember the best "type" among all the
7460Sstevel@tonic-gate 	 * duplicates of a name.
7470Sstevel@tonic-gate 	 */
7480Sstevel@tonic-gate 
7490Sstevel@tonic-gate 	np = newnames;
7500Sstevel@tonic-gate 	while (np != NIL) {
7510Sstevel@tonic-gate 		int type;
7520Sstevel@tonic-gate 
7530Sstevel@tonic-gate 		t = np;
7540Sstevel@tonic-gate 		type = np->n_type;
7550Sstevel@tonic-gate 		while (t->n_flink!=NIL &&
7560Sstevel@tonic-gate 		    strcmp(np->n_name, t->n_flink->n_name) == 0) {
7570Sstevel@tonic-gate 			t = t->n_flink;
7580Sstevel@tonic-gate 			/* "To" before "Cc" before "Bcc" */
7590Sstevel@tonic-gate 			if (t->n_type < type)
7600Sstevel@tonic-gate 				type = t->n_type;
7610Sstevel@tonic-gate 		}
7620Sstevel@tonic-gate 		if (t == np || t == NIL) {
7630Sstevel@tonic-gate 			np = np->n_flink;
7640Sstevel@tonic-gate 			continue;
7650Sstevel@tonic-gate 		}
7660Sstevel@tonic-gate 
7670Sstevel@tonic-gate 		/*
7680Sstevel@tonic-gate 		 * Now t points to the last entry with the same name
7690Sstevel@tonic-gate 		 * as np.  Make np point beyond t.
7700Sstevel@tonic-gate 		 */
7710Sstevel@tonic-gate 
7720Sstevel@tonic-gate 		np->n_flink = t->n_flink;
7730Sstevel@tonic-gate 		if (t->n_flink != NIL)
7740Sstevel@tonic-gate 			t->n_flink->n_blink = np;
7750Sstevel@tonic-gate 		np->n_type = type;
7760Sstevel@tonic-gate 		np = np->n_flink;
7770Sstevel@tonic-gate 	}
7780Sstevel@tonic-gate 	return(newnames);
7790Sstevel@tonic-gate }
7800Sstevel@tonic-gate 
7810Sstevel@tonic-gate /*
7820Sstevel@tonic-gate  * Put another node onto a list of names and return
7830Sstevel@tonic-gate  * the list.
7840Sstevel@tonic-gate  */
7850Sstevel@tonic-gate 
7860Sstevel@tonic-gate static struct name *
put(struct name * list,struct name * node)7870Sstevel@tonic-gate put(struct name *list, struct name *node)
7880Sstevel@tonic-gate {
7890Sstevel@tonic-gate 	node->n_flink = list;
7900Sstevel@tonic-gate 	node->n_blink = NIL;
7910Sstevel@tonic-gate 	if (list != NIL)
7920Sstevel@tonic-gate 		list->n_blink = node;
7930Sstevel@tonic-gate 	return(node);
7940Sstevel@tonic-gate }
7950Sstevel@tonic-gate 
7960Sstevel@tonic-gate 
7970Sstevel@tonic-gate /*
7980Sstevel@tonic-gate  * Delete the given name from a namelist.
7990Sstevel@tonic-gate  */
8000Sstevel@tonic-gate struct name *
delname(register struct name * np,char name[])8010Sstevel@tonic-gate delname(register struct name *np, char name[])
8020Sstevel@tonic-gate {
8030Sstevel@tonic-gate 	register struct name *p;
8040Sstevel@tonic-gate 
8050Sstevel@tonic-gate 	for (p = np; p != NIL; p = p->n_flink)
8060Sstevel@tonic-gate 		if (samebody(name, p->n_name, FALSE)) {
8070Sstevel@tonic-gate 			if (p->n_blink == NIL) {
8080Sstevel@tonic-gate 				if (p->n_flink != NIL)
8090Sstevel@tonic-gate 					p->n_flink->n_blink = NIL;
8100Sstevel@tonic-gate 				np = p->n_flink;
8110Sstevel@tonic-gate 				continue;
8120Sstevel@tonic-gate 			}
8130Sstevel@tonic-gate 			if (p->n_flink == NIL) {
8140Sstevel@tonic-gate 				if (p->n_blink != NIL)
8150Sstevel@tonic-gate 					p->n_blink->n_flink = NIL;
8160Sstevel@tonic-gate 				continue;
8170Sstevel@tonic-gate 			}
8180Sstevel@tonic-gate 			p->n_blink->n_flink = p->n_flink;
8190Sstevel@tonic-gate 			p->n_flink->n_blink = p->n_blink;
8200Sstevel@tonic-gate 		}
8210Sstevel@tonic-gate 	return(np);
8220Sstevel@tonic-gate }
8230Sstevel@tonic-gate 
8240Sstevel@tonic-gate /*
8250Sstevel@tonic-gate  * Call the given routine on each element of the name
8260Sstevel@tonic-gate  * list, replacing said value if need be.
8270Sstevel@tonic-gate  */
8280Sstevel@tonic-gate 
8290Sstevel@tonic-gate void
mapf(register struct name * np,char * from)8300Sstevel@tonic-gate mapf(register struct name *np, char *from)
8310Sstevel@tonic-gate {
8320Sstevel@tonic-gate 	register struct name *p;
8330Sstevel@tonic-gate 
8340Sstevel@tonic-gate 	if (debug) fprintf(stderr, "mapf %lx, %s\n", (long)np, from);
8350Sstevel@tonic-gate 	for (p = np; p != NIL; p = p->n_flink)
8360Sstevel@tonic-gate 		if ((p->n_type & GDEL) == 0) {
8370Sstevel@tonic-gate 			p->n_name = netmap(p->n_name, from);
8380Sstevel@tonic-gate 			p->n_full = splice(p->n_name, p->n_full);
8390Sstevel@tonic-gate 		}
8400Sstevel@tonic-gate 	if (debug) fprintf(stderr, "mapf %s done\n", from);
8410Sstevel@tonic-gate }
842