|
Packit |
6bd9ab |
/*
|
|
Packit |
6bd9ab |
lookup_shadow.c - simple lookup code for shadow entries
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
Copyright (C) 2013 Arthur de Jong
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
This library is free software; you can redistribute it and/or
|
|
Packit |
6bd9ab |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6bd9ab |
License as published by the Free Software Foundation; either
|
|
Packit |
6bd9ab |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
This library is distributed in the hope that it will be useful,
|
|
Packit |
6bd9ab |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6bd9ab |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6bd9ab |
Lesser General Public License for more details.
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6bd9ab |
License along with this library; if not, write to the Free Software
|
|
Packit |
6bd9ab |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit |
6bd9ab |
02110-1301 USA
|
|
Packit |
6bd9ab |
*/
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
#include "config.h"
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
#include <string.h>
|
|
Packit |
6bd9ab |
#include <stdio.h>
|
|
Packit |
6bd9ab |
#include <errno.h>
|
|
Packit |
6bd9ab |
#include <stdlib.h>
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
#ifndef HAVE_SHADOW_H
|
|
Packit |
6bd9ab |
/* dummy implementation that does nothing for FreeBSD */
|
|
Packit |
6bd9ab |
int main(int argc,char *argv[])
|
|
Packit |
6bd9ab |
{
|
|
Packit |
6bd9ab |
fprintf(stderr, "%s: shadow lookups unsupported\n", argv[0]);
|
|
Packit |
6bd9ab |
return 1;
|
|
Packit |
6bd9ab |
}
|
|
Packit |
6bd9ab |
#else /* HAVE_SHADOW_H */
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
#include <shadow.h>
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
static void print_shadow(struct spwd *result)
|
|
Packit |
6bd9ab |
{
|
|
Packit |
6bd9ab |
printf("%s:%s:", result->sp_namp, result->sp_pwdp);
|
|
Packit |
6bd9ab |
if (result->sp_lstchg >= 0)
|
|
Packit |
6bd9ab |
printf("%d", (int)result->sp_lstchg);
|
|
Packit |
6bd9ab |
printf(":");
|
|
Packit |
6bd9ab |
if (result->sp_min >= 0)
|
|
Packit |
6bd9ab |
printf("%d", (int)result->sp_min);
|
|
Packit |
6bd9ab |
printf(":");
|
|
Packit |
6bd9ab |
if (result->sp_max >= 0)
|
|
Packit |
6bd9ab |
printf("%d", (int)result->sp_max);
|
|
Packit |
6bd9ab |
printf(":");
|
|
Packit |
6bd9ab |
if (result->sp_warn >= 0)
|
|
Packit |
6bd9ab |
printf("%d", (int)result->sp_warn);
|
|
Packit |
6bd9ab |
printf(":");
|
|
Packit |
6bd9ab |
if (result->sp_inact >= 0)
|
|
Packit |
6bd9ab |
printf("%d", (int)result->sp_inact);
|
|
Packit |
6bd9ab |
printf(":");
|
|
Packit |
6bd9ab |
if (result->sp_expire >= 0)
|
|
Packit |
6bd9ab |
printf("%d", (int)result->sp_expire);
|
|
Packit |
6bd9ab |
printf(":");
|
|
Packit |
6bd9ab |
if (result->sp_flag >= 0)
|
|
Packit |
6bd9ab |
printf("%x", (int)result->sp_flag);
|
|
Packit |
6bd9ab |
printf("\n");
|
|
Packit |
6bd9ab |
}
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* the main program... */
|
|
Packit |
6bd9ab |
int main(int argc,char *argv[])
|
|
Packit |
6bd9ab |
{
|
|
Packit |
6bd9ab |
struct spwd *result;
|
|
Packit |
6bd9ab |
/* check arguments */
|
|
Packit |
6bd9ab |
if ((argc != 1) && (argc != 2))
|
|
Packit |
6bd9ab |
{
|
|
Packit |
6bd9ab |
fprintf(stderr, "Usage: %s [USERNAME]\n", argv[0]);
|
|
Packit |
6bd9ab |
exit(EXIT_FAILURE);
|
|
Packit |
6bd9ab |
}
|
|
Packit |
6bd9ab |
/* start lookup */
|
|
Packit |
6bd9ab |
if (argc == 2)
|
|
Packit |
6bd9ab |
{
|
|
Packit |
6bd9ab |
/* get entry by name */
|
|
Packit |
6bd9ab |
errno = 0;
|
|
Packit |
6bd9ab |
result = getspnam(argv[1]);
|
|
Packit |
6bd9ab |
if (result == NULL)
|
|
Packit |
6bd9ab |
exit(EXIT_FAILURE);
|
|
Packit |
6bd9ab |
print_shadow(result);
|
|
Packit |
6bd9ab |
}
|
|
Packit |
6bd9ab |
else /* argc == 1 */
|
|
Packit |
6bd9ab |
{
|
|
Packit |
6bd9ab |
/* get all entries */
|
|
Packit |
6bd9ab |
setspent();
|
|
Packit |
6bd9ab |
while ((result = getspent()) != NULL)
|
|
Packit |
6bd9ab |
print_shadow(result);
|
|
Packit |
6bd9ab |
endspent();
|
|
Packit |
6bd9ab |
}
|
|
Packit |
6bd9ab |
return 0;
|
|
Packit |
6bd9ab |
}
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
#endif /* HAVE_SHADOW_H */
|