2 * Copyright 1994, Julianne Frances Haugh
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Julianne F. Haugh nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #include <sys/types.h>
39 #include "prototypes.h"
40 /* local function prototypes */
41 static RETSIGTYPE catch_signals (int);
42 static void usage (void);
45 * catch_signals - signal catcher
47 static RETSIGTYPE catch_signals (unused int sig)
53 * usage - print syntax message and exit
55 static void usage (void)
57 fprintf (stderr, _("Usage: expiry {-f|-c}\n"));
62 * expiry - check and enforce password expiration policy
64 * expiry checks (-c) the current password expiration and forces (-f)
65 * changes when required. It is callable as a normal user command.
67 int main (int argc, char **argv)
77 * Start by disabling all of the keyboard signals.
79 signal (SIGHUP, catch_signals);
80 signal (SIGINT, catch_signals);
81 signal (SIGQUIT, catch_signals);
83 signal (SIGTSTP, catch_signals);
87 * expiry takes one of two arguments. The default action is to give
90 setlocale (LC_ALL, "");
91 bindtextdomain (PACKAGE, LOCALEDIR);
94 if (argc != 2 || (strcmp (argv[1], "-f") && strcmp (argv[1], "-c")))
98 * Get user entries for /etc/passwd and /etc/shadow
100 if (!(pwd = get_my_pwent ())) {
101 fprintf (stderr, _("%s: unknown user\n"), Prog);
104 spwd = getspnam (pwd->pw_name); /* !USE_PAM, No need for xgetspnam */
107 * If checking accounts, use agecheck() function.
109 if (strcmp (argv[1], "-c") == 0) {
112 * Print out number of days until expiration.
114 agecheck (pwd, spwd);
117 * Exit with status indicating state of account.
119 exit (isexpired (pwd, spwd));
123 * If forcing password change, use expire() function.
125 if (strcmp (argv[1], "-f") == 0) {
128 * Just call expire(). It will force the change or give a
129 * message indicating what to do. And it doesn't return at
130 * all unless the account is unexpired.