Skip to content

Commit 736550d

Browse files
committed
unixpwd: getspent_r() is not reentrant (share FILE on shadow), so use more portable getspent()
Signed-off-by: Sebastien Marie <[email protected]>
1 parent 85a6d22 commit 736550d

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

unixpwd/c/unixpwd.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ int
133133
unixpwd_setspw(const char *user, char *password)
134134
{
135135

136-
struct spwd spw,
137-
*sp;
138-
char buf[BUFLEN];
136+
struct spwd *sp;
139137
int tmp;
140138
FILE *tmp_file = NULL;
141139
char tmp_name[PATH_MAX];
@@ -165,10 +163,7 @@ unixpwd_setspw(const char *user, char *password)
165163
}
166164

167165
setspent();
168-
while (1) {
169-
rc = getspent_r(&spw, buf, BUFLEN, &sp);
170-
if (rc != 0 || !sp)
171-
break;
166+
while ((sp = getspent()) != NULL) {
172167
if (!strcmp(user, sp->sp_namp)) {
173168
sp->sp_pwdp = password;
174169
updated++;
@@ -178,11 +173,6 @@ unixpwd_setspw(const char *user, char *password)
178173
endspent();
179174

180175
fclose(tmp_file);
181-
if (rc != ENOENT) {
182-
ulckpwdf();
183-
unlink(tmp_name);
184-
return rc;
185-
}
186176
if (!updated) {
187177
ulckpwdf();
188178
unlink(tmp_name);

0 commit comments

Comments
 (0)