Skip to content

Commit

Permalink
libnss_tcb: Initialize or rewind dirstream from inside setspent(3).
Browse files Browse the repository at this point in the history
On first call to setspent(3) initialize the directory stream properly;
on subsequent calls use rewinddir(3) to reset the position of the directory
stream to the beginning of the directory, and also update the existing
directory stream to refer to the current state of the underlying directory
it operates on.  As all internal functions are operating on thread-local
storage now, this operation will be safe, since it will emit no effects
outside of the thread calling the setspent(3) function itself.

Signed-off-by: Björn Esser <[email protected]>
  • Loading branch information
besser82 committed Dec 20, 2024
1 parent 0f4837b commit fa71903
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
13 changes: 13 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
2021-12-18 Björn Esser <besser82 at fedoraproject.org>

libnss_tcb: Initialize or rewind dirstream from inside setspent(3).
On first call to setspent(3) initialize the directory stream properly;
on subsequent calls use rewinddir(3) to reset the position of the
directory stream to the beginning of the directory, and also update
the existing directory stream to refer to the current state of the
underlying directory it operates on. As all internal functions are
operating on thread-local storage now, this operation will be safe,
since it will emit no effects outside of the thread calling the
setspent(3) function itself.
* libs/nss.c (_nss_tcb_setspent): Initialize or rewind dirstream.
(_nss_tcb_getspent_r): Move initialization of the dirstream to
_nss_tcb_setspent.

libtcb: Add versioning to exported symbols.
This change is implemented for adding some interfaces to libtcb to
give it a more consumer friendly API and thus makes porting existing
Expand Down
14 changes: 9 additions & 5 deletions libs/nss.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ static __thread DIR *tcbdir = NULL;

int _nss_tcb_setspent(void)
{
if (!tcbdir) {
tcbdir = opendir(TCB_DIR);
if (!tcbdir)
return NSS_STATUS_UNAVAIL;
}

rewinddir(tcbdir);
return 1;
}

Expand Down Expand Up @@ -100,11 +107,8 @@ int _nss_tcb_getspent_r(struct spwd *__result_buf,
off_t currpos;
int retval, saved_errno;

if (!tcbdir) {
tcbdir = opendir(TCB_DIR);
if (!tcbdir)
return NSS_STATUS_UNAVAIL;
}
if (!tcbdir)
return NSS_STATUS_UNAVAIL;

do {
currpos = telldir(tcbdir);
Expand Down

0 comments on commit fa71903

Please sign in to comment.