File: check_expired.c

package info (click to toggle)
account-utils 1.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 836 kB
  • sloc: ansic: 8,789; xml: 1,584; sh: 77; makefile: 10
file content (45 lines) | stat: -rw-r--r-- 849 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//SPDX-License-Identifier: GPL-2.0-or-later

#include <pwd.h>
#include <shadow.h>
#include <stdbool.h>

#include "pwaccess.h"

#include "basics.h"

int
main(int argc, char **argv)
{
  _cleanup_free_ char *error = NULL;
  bool pwchangeable = false;
  long daysleft = -1;
  int r;

  if (argc != 2)
    {
      fprintf(stderr, "Usage: check_expired <account>\n");
      return 1;
    }

  r = pwaccess_check_expired(argv[1], &daysleft, &pwchangeable, &error);
  if (r < 0)
    {
      if (error)
	fprintf(stderr, "%s\n", error);
      else
        fprintf(stderr, "check_expired failed: %s\n", strerror(-r));
      return 1;
    }

  printf("Expired: %i\n", r);

  printf("Days left: %li\n", daysleft);

  if (pwchangeable)
    fprintf(stdout, "Password can be changed.\n");
  else
    fprintf(stdout, "Password cannot be changed.\n");

  return 0;
}