--- connect.org	Sat Aug  3 16:01:22 2002
+++ connect.c	Sun Aug  4 21:17:28 2002
@@ -699,6 +699,16 @@
                         struct stat *statb)
 
 /* returns 1 if OK and 0 if not OK */
+/*
+    3-Aug-2002 -- Modified to conform more closely to NCP semantics; sequence number
+                  is now incremented once per match, and the search starts over at
+                  the start of the directory each time this function is called.
+                  This may not seem optimal, but is needed to mimic Novell behavior
+                  in cases where files are being added to/removed from the directory
+                  between calls to this function (e.g. running "pkunzip xxx.zip" on
+                  a DOS client). -- MQR
+
+*/
 {
   DIR            *f     = give_dh_f(dh);
   int            okflag = 0;
@@ -706,32 +716,21 @@
   if (f != (DIR*)NULL) {
     struct  dirent *dirbuff;
     uint8   entry[256];
+    int     skip;          /* How many matches should we pass over? -- MQR 3-Aug-2002  */
     xstrcpy(entry, search);
     if ( (uint16)*sequence == MAX_U16)  *sequence = 0;
 
-    if (*sequence < dh->sequence || ((long)dh->dirpos) < 0L) {
-      dh->dirpos   = (off_t)0;
-      dh->sequence = 0;
-    }
-    SEEKDIR(f, dh->dirpos);
-
-    if (dh->sequence != *sequence) {
-      while (dh->sequence < *sequence) {
-        if (NULL == readdir(f)) {
-          dh->dirpos = TELLDIR(f);
-          release_dh_f(dh, 1);
-          return(0);
-        }
-        dh->sequence++;
-      }
-      dh->dirpos = TELLDIR(f);
-    }
     XDPRINTF((5,0,"get_dh_entry seq=0x%x, attrib=0x%x path:%s:, entry:%s:",
                 *sequence, attrib, dh->unixname, entry));
 
+    /* Always start at the begining of the directory -- MQR 3-Aug-2002  */
+    dh->dirpos   = (off_t)0;
+    dh->sequence = 0;
+    SEEKDIR(f, dh->dirpos);
+
+    skip = *sequence; /* The sequence number tells us how many entries to skip -- MQR 3-Aug-2002  */
     while ((dirbuff = readdir(f)) != (struct dirent*)NULL){
       okflag = 0;
-      dh->sequence++;
       if (dirbuff->d_ino) {
         uint8 *name=(uint8*)(dirbuff->d_name);
         uint8 dname[256];
@@ -756,6 +755,8 @@
                && tru_eff_rights_exists(dh->volume, dh->unixname, statb, TRUSTEE_T))
               okflag=0;
             
+            /* Don't return anything until the skip count reaches zero -- MQR 3-Aug-2002  */
+            if (okflag && skip-- > 0 ) okflag=0;
             if (okflag){
               if (unixname)
                 strmaxcpy(unixname, dh->unixname, size_unixname-1);
@@ -767,7 +768,7 @@
       }  /* if */
     } /* while */
     dh->kpath[0] = '\0';
-    *sequence  = dh->sequence;
+    (*sequence)++;
     dh->dirpos = TELLDIR(f);
     release_dh_f(dh, (dirbuff==NULL));
   } /* if */
