17c478bd9Sstevel@tonic-gate /*
2c7402f07SJoep Vesseur  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
37c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  */
57c478bd9Sstevel@tonic-gate 
6*981fe1b1SJohn Levon /*
7*981fe1b1SJohn Levon  * Copyright (c) 2018, Joyent, Inc.
8*981fe1b1SJohn Levon  */
9*981fe1b1SJohn Levon 
107c478bd9Sstevel@tonic-gate /*
117c478bd9Sstevel@tonic-gate  * This program is copyright Alec Muffett 1993. The author disclaims all
127c478bd9Sstevel@tonic-gate  * responsibility or liability with respect to it's usage or its effect
137c478bd9Sstevel@tonic-gate  * upon hardware or computer systems, and maintains copyright as set out
147c478bd9Sstevel@tonic-gate  * in the "LICENCE" document which accompanies distributions of Crack v4.0
157c478bd9Sstevel@tonic-gate  * and upwards.
167c478bd9Sstevel@tonic-gate  */
177c478bd9Sstevel@tonic-gate 
187c478bd9Sstevel@tonic-gate #include "packer.h"
197c478bd9Sstevel@tonic-gate 
207c478bd9Sstevel@tonic-gate void
PWRemove(char * path)217c478bd9Sstevel@tonic-gate PWRemove(char *path)
227c478bd9Sstevel@tonic-gate {
237c478bd9Sstevel@tonic-gate 	char fname[PATH_MAX];
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate 	(void) snprintf(fname, sizeof (fname), "%s/%s", path,
267c478bd9Sstevel@tonic-gate 	    DICT_DATABASE_PWI);
277c478bd9Sstevel@tonic-gate 	(void) unlink(fname);
287c478bd9Sstevel@tonic-gate 	(void) snprintf(fname, sizeof (fname), "%s/%s", path,
297c478bd9Sstevel@tonic-gate 	    DICT_DATABASE_PWD);
307c478bd9Sstevel@tonic-gate 	(void) unlink(fname);
317c478bd9Sstevel@tonic-gate 	(void) snprintf(fname, sizeof (fname), "%s/%s", path,
327c478bd9Sstevel@tonic-gate 	    DICT_DATABASE_HWM);
337c478bd9Sstevel@tonic-gate 	(void) unlink(fname);
347c478bd9Sstevel@tonic-gate }
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate PWDICT *
PWOpen(char * path,char * mode)377c478bd9Sstevel@tonic-gate PWOpen(char *path, char *mode)
387c478bd9Sstevel@tonic-gate {
397c478bd9Sstevel@tonic-gate 	PWDICT *pdesc;
407c478bd9Sstevel@tonic-gate 	char iname[PATH_MAX];
417c478bd9Sstevel@tonic-gate 	char dname[PATH_MAX];
427c478bd9Sstevel@tonic-gate 	char wname[PATH_MAX];
437c478bd9Sstevel@tonic-gate 	int fd_d;
447c478bd9Sstevel@tonic-gate 	int fd_i;
457c478bd9Sstevel@tonic-gate 	int fd_w;
467c478bd9Sstevel@tonic-gate 	FILE *dfp;
477c478bd9Sstevel@tonic-gate 	FILE *ifp;
487c478bd9Sstevel@tonic-gate 	FILE *wfp;
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate 	if ((pdesc = calloc(1, sizeof (PWDICT))) == NULL)
517c478bd9Sstevel@tonic-gate 		return ((PWDICT *) 0);
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate 	if (pdesc->header.pih_magic == PIH_MAGIC) {
547c478bd9Sstevel@tonic-gate 		return ((PWDICT *) 0);
557c478bd9Sstevel@tonic-gate 	}
567c478bd9Sstevel@tonic-gate 	(void) memset(pdesc, '\0', sizeof (pdesc));
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate 	(void) snprintf(iname, sizeof (iname), "%s/%s", path,
597c478bd9Sstevel@tonic-gate 	    DICT_DATABASE_PWI);
607c478bd9Sstevel@tonic-gate 	(void) snprintf(dname, sizeof (dname), "%s/%s", path,
617c478bd9Sstevel@tonic-gate 	    DICT_DATABASE_PWD);
627c478bd9Sstevel@tonic-gate 	(void) snprintf(wname, sizeof (wname), "%s/%s", path,
637c478bd9Sstevel@tonic-gate 	    DICT_DATABASE_HWM);
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate 	if ((fd_d = open(dname, O_RDWR|O_CREAT, 0600)) == -1)
667c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, "PWopen: can't open %s: %s", dname,
677c478bd9Sstevel@tonic-gate 		    strerror(errno));
687c478bd9Sstevel@tonic-gate 	if ((fd_i = open(iname, O_RDWR|O_CREAT, 0600)) == -1)
697c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, "PWopen: can't open %s: %s", iname,
707c478bd9Sstevel@tonic-gate 		    strerror(errno));
717c478bd9Sstevel@tonic-gate 	if ((fd_w = open(wname, O_RDWR|O_CREAT, 0600)) == -1)
727c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, "PWopen: can't open %s: %s", wname,
737c478bd9Sstevel@tonic-gate 		    strerror(errno));
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate 	if (!(pdesc->dfp = fdopen(fd_d, mode))) {
767c478bd9Sstevel@tonic-gate 		return ((PWDICT *) 0);
777c478bd9Sstevel@tonic-gate 	}
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate 	if (!(pdesc->ifp = fdopen(fd_i, mode))) {
807c478bd9Sstevel@tonic-gate 		(void) fclose(pdesc->dfp);
817c478bd9Sstevel@tonic-gate 		return ((PWDICT *) 0);
827c478bd9Sstevel@tonic-gate 	}
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate 	if (pdesc->wfp = fdopen(fd_w, mode)) {
857c478bd9Sstevel@tonic-gate 		pdesc->flags |= PFOR_USEHWMS;
867c478bd9Sstevel@tonic-gate 	}
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 	ifp = pdesc->ifp;
897c478bd9Sstevel@tonic-gate 	dfp = pdesc->dfp;
907c478bd9Sstevel@tonic-gate 	wfp = pdesc->wfp;
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 	if (mode[0] == 'w') {
937c478bd9Sstevel@tonic-gate 		pdesc->flags |= PFOR_WRITE;
947c478bd9Sstevel@tonic-gate 		pdesc->header.pih_magic = PIH_MAGIC;
957c478bd9Sstevel@tonic-gate 		pdesc->header.pih_blocklen = NUMWORDS;
967c478bd9Sstevel@tonic-gate 		pdesc->header.pih_numwords = 0;
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate 		(void) fwrite((char *)&(pdesc->header), sizeof (pdesc->header),
997c478bd9Sstevel@tonic-gate 		    1, ifp);
1007c478bd9Sstevel@tonic-gate 	} else {
1017c478bd9Sstevel@tonic-gate 		pdesc->flags &= ~PFOR_WRITE;
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 		if (!fread((char *)&(pdesc->header), sizeof (pdesc->header),
1047c478bd9Sstevel@tonic-gate 		    1, ifp)) {
1057c478bd9Sstevel@tonic-gate 			pdesc->header.pih_magic = 0;
1067c478bd9Sstevel@tonic-gate 			(void) fclose(ifp);
1077c478bd9Sstevel@tonic-gate 			(void) fclose(dfp);
1087c478bd9Sstevel@tonic-gate 			return ((PWDICT *) 0);
1097c478bd9Sstevel@tonic-gate 		}
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate 		if (pdesc->header.pih_magic != PIH_MAGIC) {
1127c478bd9Sstevel@tonic-gate 			pdesc->header.pih_magic = 0;
1137c478bd9Sstevel@tonic-gate 			(void) fclose(ifp);
1147c478bd9Sstevel@tonic-gate 			(void) fclose(dfp);
1157c478bd9Sstevel@tonic-gate 			return ((PWDICT *) 0);
1167c478bd9Sstevel@tonic-gate 		}
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 		if (pdesc->header.pih_blocklen != NUMWORDS) {
1197c478bd9Sstevel@tonic-gate 			pdesc->header.pih_magic = 0;
1207c478bd9Sstevel@tonic-gate 			(void) fclose(ifp);
1217c478bd9Sstevel@tonic-gate 			(void) fclose(dfp);
1227c478bd9Sstevel@tonic-gate 			return ((PWDICT *) 0);
1237c478bd9Sstevel@tonic-gate 		}
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 		if (pdesc->flags & PFOR_USEHWMS) {
1267c478bd9Sstevel@tonic-gate 			if (fread(pdesc->hwms, 1, sizeof (pdesc->hwms), wfp) !=
1277c478bd9Sstevel@tonic-gate 			    sizeof (pdesc->hwms)) {
1287c478bd9Sstevel@tonic-gate 				pdesc->flags &= ~PFOR_USEHWMS;
1297c478bd9Sstevel@tonic-gate 			}
1307c478bd9Sstevel@tonic-gate 		}
1317c478bd9Sstevel@tonic-gate 	}
1327c478bd9Sstevel@tonic-gate 	return (pdesc);
1337c478bd9Sstevel@tonic-gate }
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate int
PWClose(PWDICT * pwp)1367c478bd9Sstevel@tonic-gate PWClose(PWDICT *pwp)
1377c478bd9Sstevel@tonic-gate {
1387c478bd9Sstevel@tonic-gate 	if (pwp->header.pih_magic != PIH_MAGIC) {
1397c478bd9Sstevel@tonic-gate 		return (-1);
1407c478bd9Sstevel@tonic-gate 	}
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 	if (pwp->flags & PFOR_WRITE) {
1437c478bd9Sstevel@tonic-gate 		pwp->flags |= PFOR_FLUSH;
1447c478bd9Sstevel@tonic-gate 		(void) PutPW(pwp, (char *)0);	/* flush last index if necess */
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 		if (fseek(pwp->ifp, 0L, 0)) {
1477c478bd9Sstevel@tonic-gate 			return (-1);
1487c478bd9Sstevel@tonic-gate 		}
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate 		if (!fwrite((char *)&pwp->header, sizeof (pwp->header),
1517c478bd9Sstevel@tonic-gate 		    1, pwp->ifp)) {
1527c478bd9Sstevel@tonic-gate 			return (-1);
1537c478bd9Sstevel@tonic-gate 		}
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate 		if (pwp->flags & PFOR_USEHWMS) {
1567c478bd9Sstevel@tonic-gate 			int i;
1577c478bd9Sstevel@tonic-gate 			for (i = 1; i <= 0xff; i++) {
1587c478bd9Sstevel@tonic-gate 				if (!pwp->hwms[i]) {
1597c478bd9Sstevel@tonic-gate 					pwp->hwms[i] = pwp->hwms[i-1];
1607c478bd9Sstevel@tonic-gate 				}
1617c478bd9Sstevel@tonic-gate 			}
1627c478bd9Sstevel@tonic-gate 			(void) fwrite(pwp->hwms, 1, sizeof (pwp->hwms),
1637c478bd9Sstevel@tonic-gate 			    pwp->wfp);
1647c478bd9Sstevel@tonic-gate 		}
1657c478bd9Sstevel@tonic-gate 	}
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 	(void) fclose(pwp->ifp);
1687c478bd9Sstevel@tonic-gate 	(void) fclose(pwp->dfp);
1697c478bd9Sstevel@tonic-gate 	(void) fclose(pwp->wfp);
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate 	pwp->header.pih_magic = 0;
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate 	free(pwp);
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate 	return (0);
1767c478bd9Sstevel@tonic-gate }
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate int
PutPW(PWDICT * pwp,char * string)1797c478bd9Sstevel@tonic-gate PutPW(PWDICT *pwp, char *string)
1807c478bd9Sstevel@tonic-gate {
1817c478bd9Sstevel@tonic-gate 	if (!(pwp->flags & PFOR_WRITE)) {
1827c478bd9Sstevel@tonic-gate 		return (-1);
1837c478bd9Sstevel@tonic-gate 	}
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 	if (string) {
1867c478bd9Sstevel@tonic-gate 		(void) strncpy(pwp->data[pwp->count], string, MAXWORDLEN);
1877c478bd9Sstevel@tonic-gate 		pwp->data[pwp->count][MAXWORDLEN - 1] = '\0';
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate 		pwp->hwms[string[0] & 0xff] = pwp->header.pih_numwords;
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 		++(pwp->count);
1927c478bd9Sstevel@tonic-gate 		++(pwp->header.pih_numwords);
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 	} else if (!(pwp->flags & PFOR_FLUSH)) {
1957c478bd9Sstevel@tonic-gate 		return (-1);
1967c478bd9Sstevel@tonic-gate 	}
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate 	if ((pwp->flags & PFOR_FLUSH) || !(pwp->count % NUMWORDS)) {
1997c478bd9Sstevel@tonic-gate 		int i;
200c7402f07SJoep Vesseur 		uint32_t datum;
2017c478bd9Sstevel@tonic-gate 		register char *ostr;
2027c478bd9Sstevel@tonic-gate 
203c7402f07SJoep Vesseur 		datum = (uint32_t)ftell(pwp->dfp);
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate 		(void) fwrite((char *)&datum, sizeof (datum), 1, pwp->ifp);
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate 		(void) fputs(pwp->data[0], pwp->dfp);
2087c478bd9Sstevel@tonic-gate 		(void) putc(0, pwp->dfp);
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate 		ostr = pwp->data[0];
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate 		for (i = 1; i < NUMWORDS; i++) {
2137c478bd9Sstevel@tonic-gate 			register int j;
2147c478bd9Sstevel@tonic-gate 			register char *nstr;
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate 			nstr = pwp->data[i];
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 			if (nstr[0]) {
219c7402f07SJoep Vesseur 				for (j = 0; ostr[j] && nstr[j] &&
220c7402f07SJoep Vesseur 				    (ostr[j] == nstr[j]); j++)
221c7402f07SJoep Vesseur 					;
222c7402f07SJoep Vesseur 				(void) putc(j & 0xff, pwp->dfp);
2237c478bd9Sstevel@tonic-gate 				(void) fputs(nstr + j, pwp->dfp);
2247c478bd9Sstevel@tonic-gate 			}
2257c478bd9Sstevel@tonic-gate 			(void) putc(0, pwp->dfp);
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 			ostr = nstr;
2287c478bd9Sstevel@tonic-gate 		}
2297c478bd9Sstevel@tonic-gate 
230*981fe1b1SJohn Levon 		(void) memset(pwp->data, '\0', sizeof (pwp->data));
231*981fe1b1SJohn Levon 		pwp->count = 0;
2327c478bd9Sstevel@tonic-gate 	}
2337c478bd9Sstevel@tonic-gate 	return (0);
2347c478bd9Sstevel@tonic-gate }
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate char *
GetPW(PWDICT * pwp,uint32_t number)237c7402f07SJoep Vesseur GetPW(PWDICT *pwp, uint32_t number)
2387c478bd9Sstevel@tonic-gate {
239c7402f07SJoep Vesseur 	uint32_t datum;
2407c478bd9Sstevel@tonic-gate 	register int i;
2417c478bd9Sstevel@tonic-gate 	register char *ostr;
2427c478bd9Sstevel@tonic-gate 	register char *nstr;
2437c478bd9Sstevel@tonic-gate 	register char *bptr;
2447c478bd9Sstevel@tonic-gate 	char buffer[NUMWORDS * MAXWORDLEN];
2457c478bd9Sstevel@tonic-gate 	static char data[NUMWORDS][MAXWORDLEN];
246c7402f07SJoep Vesseur 	static uint32_t prevblock = 0xffffffff;
247c7402f07SJoep Vesseur 	uint32_t thisblock;
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 	thisblock = number / NUMWORDS;
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 	if (prevblock == thisblock) {
2527c478bd9Sstevel@tonic-gate 		return (data[number % NUMWORDS]);
2537c478bd9Sstevel@tonic-gate 	}
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate 	if (fseek(pwp->ifp, sizeof (struct pi_header) +
256c7402f07SJoep Vesseur 	    (thisblock * sizeof (uint32_t)), 0)) {
2577c478bd9Sstevel@tonic-gate 		return (NULL);
2587c478bd9Sstevel@tonic-gate 	}
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate 	if (!fread((char *)&datum, sizeof (datum), 1, pwp->ifp)) {
2617c478bd9Sstevel@tonic-gate 		return (NULL);
2627c478bd9Sstevel@tonic-gate 	}
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 	if (fseek(pwp->dfp, datum, 0)) {
2657c478bd9Sstevel@tonic-gate 		return (NULL);
2667c478bd9Sstevel@tonic-gate 	}
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate 	if (!fread(buffer, 1, sizeof (buffer), pwp->dfp)) {
2697c478bd9Sstevel@tonic-gate 		return (NULL);
2707c478bd9Sstevel@tonic-gate 	}
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate 	prevblock = thisblock;
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 	bptr = buffer;
2757c478bd9Sstevel@tonic-gate 
276c7402f07SJoep Vesseur 	for (ostr = data[0]; *(ostr++) = *(bptr++); /* nothing */)
277c7402f07SJoep Vesseur 		;
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 	ostr = data[0];
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate 	for (i = 1; i < NUMWORDS; i++) {
2827c478bd9Sstevel@tonic-gate 		nstr = data[i];
2837c478bd9Sstevel@tonic-gate 		(void) strcpy(nstr, ostr);
2847c478bd9Sstevel@tonic-gate 		ostr = nstr + *(bptr++);
285c7402f07SJoep Vesseur 		while (*(ostr++) = *(bptr++))
286c7402f07SJoep Vesseur 			;
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate 		ostr = nstr;
2897c478bd9Sstevel@tonic-gate 	}
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate 	return (data[number % NUMWORDS]);
2927c478bd9Sstevel@tonic-gate }
2937c478bd9Sstevel@tonic-gate 
294c7402f07SJoep Vesseur uint32_t
FindPW(PWDICT * pwp,char * string)2957c478bd9Sstevel@tonic-gate FindPW(PWDICT *pwp, char *string)
2967c478bd9Sstevel@tonic-gate {
2977c478bd9Sstevel@tonic-gate 	int lwm;
2987c478bd9Sstevel@tonic-gate 	int hwm;
2997c478bd9Sstevel@tonic-gate 	int idx;
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate 	if (string == NULL)
3027c478bd9Sstevel@tonic-gate 		return (PW_WORDS(pwp));
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate 	if (pwp->flags & PFOR_USEHWMS) {
3057c478bd9Sstevel@tonic-gate 		idx = string[0] & 0xff;
3067c478bd9Sstevel@tonic-gate 		lwm = idx ? pwp->hwms[idx - 1] : 0;
3077c478bd9Sstevel@tonic-gate 		hwm = pwp->hwms[idx];
3087c478bd9Sstevel@tonic-gate 	} else {
3097c478bd9Sstevel@tonic-gate 		lwm = 0;
3107c478bd9Sstevel@tonic-gate 		hwm = PW_WORDS(pwp) - 1;
3117c478bd9Sstevel@tonic-gate 	}
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate 	for (;;) {
3147c478bd9Sstevel@tonic-gate 		int cmp;
3157c478bd9Sstevel@tonic-gate 		int pivot;
3167c478bd9Sstevel@tonic-gate 		char *this;
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate 		pivot = lwm + ((hwm+1)-lwm)/2;
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 		if (feof(pwp->ifp) && feof(pwp->dfp) && feof(pwp->wfp))
3217c478bd9Sstevel@tonic-gate 			break;
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate 		if ((this = GetPW(pwp, pivot)) == NULL)
3247c478bd9Sstevel@tonic-gate 			break;
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 		cmp = strcmp(string, this);		/* INLINE ? */
3277c478bd9Sstevel@tonic-gate 
3287c478bd9Sstevel@tonic-gate 		if (cmp == 0)
3297c478bd9Sstevel@tonic-gate 			return (pivot);
3307c478bd9Sstevel@tonic-gate 		else if (cmp < 0)
3317c478bd9Sstevel@tonic-gate 			hwm = pivot-1;
3327c478bd9Sstevel@tonic-gate 		else
3337c478bd9Sstevel@tonic-gate 			lwm = pivot+1;
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate 		if (lwm > hwm)	/* searched all; not found */
3367c478bd9Sstevel@tonic-gate 			break;
3377c478bd9Sstevel@tonic-gate 	}
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate 	/* not found */
3407c478bd9Sstevel@tonic-gate 	return (PW_WORDS(pwp));
3417c478bd9Sstevel@tonic-gate }
342