Skip to content

Commit

Permalink
getent: add support for the 'shadow' database
Browse files Browse the repository at this point in the history
  • Loading branch information
floppym committed Jan 10, 2021
1 parent bf12065 commit 79d453a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions main/musl/getent.c
Expand Up @@ -36,6 +36,7 @@
#include <netdb.h>
#include <pwd.h>
#include <grp.h>
#include <shadow.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdbool.h>
Expand Down Expand Up @@ -428,6 +429,29 @@ static int services(int argc, char *argv[])
return rv;
}

static int shadow(int argc, char *argv[])
{
struct spwd *sp;
int i, rv;

rv = RV_OK;
if (argc == 2) {
while ((sp = getspent()) != NULL)
putspent(sp, stdout);
} else {
for (i = 2; i < argc; i++) {
sp = getspnam(argv[i]);
if (sp == NULL) {
rv = RV_NOTFOUND;
break;
}
putspent(sp, stdout);
}
}
endspent();
return rv;
}

static int shells(int argc, char *argv[])
{
const char *sh;
Expand Down Expand Up @@ -471,6 +495,7 @@ static struct getentdb {
{ "passwd", passwd, },
{ "protocols", protocols, },
{ "services", services, },
{ "shadow", shadow, },
{ "shells", shells, },

{ NULL, NULL, },
Expand Down

0 comments on commit 79d453a

Please sign in to comment.