endpwent: Close all opened instances of /etc/passwd, including those used by getpwuid() and getpwnam()
This commit is contained in:
parent
2ca20c1a1e
commit
702cc0442c
@ -7,6 +7,8 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
static FILE* pwd_file = nullptr;
|
static FILE* pwd_file = nullptr;
|
||||||
|
static FILE* pwnam_file = nullptr;
|
||||||
|
static FILE* pwuid_file = nullptr;
|
||||||
|
|
||||||
static int initialize_pwd(FILE** stream)
|
static int initialize_pwd(FILE** stream)
|
||||||
{
|
{
|
||||||
@ -126,7 +128,6 @@ extern "C"
|
|||||||
|
|
||||||
struct passwd* getpwnam(const char* name)
|
struct passwd* getpwnam(const char* name)
|
||||||
{
|
{
|
||||||
static FILE* pwnam_file = nullptr;
|
|
||||||
if (!pwnam_file)
|
if (!pwnam_file)
|
||||||
{
|
{
|
||||||
if (!initialize_pwd(&pwnam_file)) return NULL;
|
if (!initialize_pwd(&pwnam_file)) return NULL;
|
||||||
@ -149,7 +150,6 @@ extern "C"
|
|||||||
|
|
||||||
struct passwd* getpwuid(uid_t uid)
|
struct passwd* getpwuid(uid_t uid)
|
||||||
{
|
{
|
||||||
static FILE* pwuid_file = nullptr;
|
|
||||||
if (!pwuid_file)
|
if (!pwuid_file)
|
||||||
{
|
{
|
||||||
if (!initialize_pwd(&pwuid_file)) return NULL;
|
if (!initialize_pwd(&pwuid_file)) return NULL;
|
||||||
@ -182,5 +182,15 @@ extern "C"
|
|||||||
fclose(pwd_file);
|
fclose(pwd_file);
|
||||||
pwd_file = nullptr;
|
pwd_file = nullptr;
|
||||||
}
|
}
|
||||||
|
if (pwuid_file)
|
||||||
|
{
|
||||||
|
fclose(pwuid_file);
|
||||||
|
pwuid_file = nullptr;
|
||||||
|
}
|
||||||
|
if (pwnam_file)
|
||||||
|
{
|
||||||
|
fclose(pwnam_file);
|
||||||
|
pwnam_file = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user