From: nekral-guest Date: Thu, 18 Mar 2010 23:21:21 +0000 (+0000) Subject: * lib/commonio.c: Stop sorting entries when we reach the first X-Git-Tag: 4.1.5~296 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e19c7200ebbb6d4b5b731295d1112a03bf8be607;p=shadow * lib/commonio.c: Stop sorting entries when we reach the first NIS line. --- diff --git a/ChangeLog b/ChangeLog index d861a184..fda02a6f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-03-19 Nicolas François + + * lib/commonio.c: Stop sorting entries when we reach the first + NIS line. + 2010-03-18 Nicolas François * src/chsh.c: Even for root, warn if an invalid shell is diff --git a/lib/commonio.c b/lib/commonio.c index ec5018da..f4382969 100644 --- a/lib/commonio.c +++ b/lib/commonio.c @@ -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++) {