Skip to content

Commit 1264867

Browse files
besser82solardiz
authored andcommitted
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. Signed-off-by: Björn Esser <[email protected]>
1 parent 0f4837b commit 1264867

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

ChangeLog

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1-
2021-12-18 Björn Esser <besser82 at fedoraproject.org>
1+
2024-12-18 Björn Esser <besser82 at fedoraproject.org>
2+
3+
libnss_tcb: Initialize or rewind dirstream from inside setspent(3).
4+
On first call to setspent(3) initialize the directory stream properly;
5+
on subsequent calls use rewinddir(3) to reset the position of the
6+
directory stream to the beginning of the directory, and also update
7+
the existing directory stream to refer to the current state of the
8+
underlying directory it operates on. As all internal functions are
9+
operating on thread-local storage now, this operation will be safe,
10+
since it will emit no effects outside of the thread calling the
11+
setspent(3) function itself.
12+
* libs/nss.c (_nss_tcb_setspent): Initialize or rewind dirstream.
13+
(_nss_tcb_getspent_r): Move initialization of the dirstream to
14+
_nss_tcb_setspent.
215

316
libtcb: Add versioning to exported symbols.
417
This change is implemented for adding some interfaces to libtcb to

libs/nss.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ static __thread DIR *tcbdir = NULL;
1515

1616
int _nss_tcb_setspent(void)
1717
{
18+
if (!tcbdir) {
19+
tcbdir = opendir(TCB_DIR);
20+
if (!tcbdir)
21+
return NSS_STATUS_UNAVAIL;
22+
23+
return 1;
24+
}
25+
26+
rewinddir(tcbdir);
1827
return 1;
1928
}
2029

@@ -101,9 +110,8 @@ int _nss_tcb_getspent_r(struct spwd *__result_buf,
101110
int retval, saved_errno;
102111

103112
if (!tcbdir) {
104-
tcbdir = opendir(TCB_DIR);
105-
if (!tcbdir)
106-
return NSS_STATUS_UNAVAIL;
113+
errno = ENOENT;
114+
return NSS_STATUS_UNAVAIL;
107115
}
108116

109117
do {

0 commit comments

Comments
 (0)