mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-18 15:32:22 +00:00
LibC: Allow empty spwd members when writing shadow entries via putspent
Previously there was no way to output an empty value into the shadow file entries when the spwd members were disabled. This would cause new user entries to the shadow file to be cluttered with disabled values. This commit checks if the spwd member value is diabled (-1) and will output as appropriate.
This commit is contained in:
parent
54578ec5d4
commit
af8b7248c8
Notes:
sideshowbarker
2024-07-18 17:09:25 +09:00
Author: https://github.com/brapru
Commit: af8b7248c8
Pull-request: https://github.com/SerenityOS/serenity/pull/7556
Issue: https://github.com/SerenityOS/serenity/issues/4884
Reviewed-by: https://github.com/bcoles
Reviewed-by: https://github.com/linusg
1 changed files with 66 additions and 2 deletions
|
@ -236,8 +236,72 @@ int putspent(struct spwd* p, FILE* stream)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nwritten = fprintf(stream, "%s:%s:%ld:%ld:%ld:%ld:%ld:%ld:%ld\n", p->sp_namp,
|
int nwritten;
|
||||||
p->sp_pwdp, p->sp_lstchg, p->sp_min, p->sp_max, p->sp_warn, p->sp_inact, p->sp_expire, p->sp_flag);
|
|
||||||
|
nwritten = fprintf(stream, "%s:%s:", p->sp_namp, p->sp_pwdp);
|
||||||
|
if (!nwritten || nwritten < 0) {
|
||||||
|
errno = ferror(stream);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p->sp_lstchg != (long int)-1)
|
||||||
|
nwritten = fprintf(stream, "%ld:", p->sp_lstchg);
|
||||||
|
else
|
||||||
|
nwritten = fprintf(stream, "%c", ':');
|
||||||
|
if (!nwritten || nwritten < 0) {
|
||||||
|
errno = ferror(stream);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p->sp_min != (long int)-1)
|
||||||
|
nwritten = fprintf(stream, "%ld:", p->sp_min);
|
||||||
|
else
|
||||||
|
nwritten = fprintf(stream, "%c", ':');
|
||||||
|
if (!nwritten || nwritten < 0) {
|
||||||
|
errno = ferror(stream);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p->sp_max != (long int)-1)
|
||||||
|
nwritten = fprintf(stream, "%ld:", p->sp_max);
|
||||||
|
else
|
||||||
|
nwritten = fprintf(stream, "%c", ':');
|
||||||
|
if (!nwritten || nwritten < 0) {
|
||||||
|
errno = ferror(stream);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p->sp_warn != (long int)-1)
|
||||||
|
nwritten = fprintf(stream, "%ld:", p->sp_warn);
|
||||||
|
else
|
||||||
|
nwritten = fprintf(stream, "%c", ':');
|
||||||
|
if (!nwritten || nwritten < 0) {
|
||||||
|
errno = ferror(stream);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p->sp_inact != (long int)-1)
|
||||||
|
nwritten = fprintf(stream, "%ld:", p->sp_inact);
|
||||||
|
else
|
||||||
|
nwritten = fprintf(stream, "%c", ':');
|
||||||
|
if (!nwritten || nwritten < 0) {
|
||||||
|
errno = ferror(stream);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p->sp_expire != (long int)-1)
|
||||||
|
nwritten = fprintf(stream, "%ld:", p->sp_expire);
|
||||||
|
else
|
||||||
|
nwritten = fprintf(stream, "%c", ':');
|
||||||
|
if (!nwritten || nwritten < 0) {
|
||||||
|
errno = ferror(stream);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p->sp_flag != (unsigned long int)-1)
|
||||||
|
nwritten = fprintf(stream, "%ld\n", p->sp_flag);
|
||||||
|
else
|
||||||
|
nwritten = fprintf(stream, "%c", '\n');
|
||||||
if (!nwritten || nwritten < 0) {
|
if (!nwritten || nwritten < 0) {
|
||||||
errno = ferror(stream);
|
errno = ferror(stream);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue