]> granicus.if.org Git - shadow/commitdiff
* lib/commonio.c: Stop sorting entries when we reach the first
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Thu, 18 Mar 2010 23:21:21 +0000 (23:21 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Thu, 18 Mar 2010 23:21:21 +0000 (23:21 +0000)
NIS line.

ChangeLog
lib/commonio.c

index d861a184586a71ee7768ad6d2aed8f2a450afa0c..fda02a6f5703406352f730040a3a5fd6a063d3bd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2010-03-19  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * lib/commonio.c: Stop sorting entries when we reach the first
+       NIS line.
+
 2010-03-18  Nicolas François  <nicolas.francois@centraliens.net>
 
        * src/chsh.c: Even for root, warn if an invalid shell is
index ec5018dac7d333b86231cf28e3b7d605167dcb5d..f43829699b3d321a3c668c1a3f036bb519bea0ce 100644 (file)
@@ -706,10 +706,24 @@ commonio_sort (struct commonio_db *db, int (*cmp) (const void *, const void *))
 {
        struct commonio_entry **entries, *ptr;
        size_t n = 0, i;
+#if KEEP_NIS_AT_END
+       struct commonio_entry *nis = NULL
+#endif
 
-       for (ptr = db->head; NULL != ptr; ptr = ptr->next) {
+       for (ptr = db->head;
+               (NULL != ptr)
+#if KEEP_NIS_AT_END
+            && ('+' != ptr->line[0])
+#endif
+            ;
+            ptr = ptr->next) {
                n++;
        }
+#if KEEP_NIS_AT_END
+       if (NULL != ptr) {
+               nis = ptr;
+       }
+#endif
 
        if (n <= 1) {
                return 0;
@@ -721,7 +735,13 @@ commonio_sort (struct commonio_db *db, int (*cmp) (const void *, const void *))
        }
 
        n = 0;
-       for (ptr = db->head; NULL != ptr; ptr = ptr->next) {
+       for (ptr = db->head;
+#if KEEP_NIS_AT_END
+            nis != ptr;
+#else
+            NULL != ptr;
+#endif
+            ptr = ptr->next) {
                entries[n++] = ptr;
        }
        qsort (entries, n, sizeof (struct commonio_entry *), cmp);
@@ -729,11 +749,16 @@ commonio_sort (struct commonio_db *db, int (*cmp) (const void *, const void *))
        /* Take care of the head and tail separately */
        db->head = entries[0];
        n--;
-       db->tail = entries[n];
+#if KEEP_NIS_AT_END
+       if (NULL == nis)
+#endif
+       {
+               db->tail = entries[n];
+       }
        db->head->prev = NULL;
        db->head->next = entries[1];
-       db->tail->prev = entries[n - 1];
-       db->tail->next = NULL;
+       entries[n]->prev = entries[n - 1];
+       entries[n]->next = NULL;
 
        /* Now other elements have prev and next entries */
        for (i = 1; i < n; i++) {