2 * Copyright (c) 1994 , Julianne Frances Haugh
3 * Copyright (c) 1996 - 2000, Marek Michałkiewicz
4 * Copyright (c) 2001 - 2006, Tomasz Kłoczko
5 * Copyright (c) 2007 - 2008, Nicolas François
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the copyright holders or contributors may not be used to
17 * endorse or promote products derived from this software without
18 * specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #include <sys/types.h>
42 #include "prototypes.h"
43 /* local function prototypes */
44 static RETSIGTYPE catch_signals (int);
45 static void usage (void);
48 * catch_signals - signal catcher
50 static RETSIGTYPE catch_signals (unused int sig)
56 * usage - print syntax message and exit
58 static void usage (void)
60 fputs (_("Usage: expiry {-f|-c}\n"), stderr);
65 * expiry - check and enforce password expiration policy
67 * expiry checks (-c) the current password expiration and forces (-f)
68 * changes when required. It is callable as a normal user command.
70 int main (int argc, char **argv)
80 * Start by disabling all of the keyboard signals.
82 signal (SIGHUP, catch_signals);
83 signal (SIGINT, catch_signals);
84 signal (SIGQUIT, catch_signals);
86 signal (SIGTSTP, catch_signals);
90 * expiry takes one of two arguments. The default action is to give
93 setlocale (LC_ALL, "");
94 bindtextdomain (PACKAGE, LOCALEDIR);
97 if (argc != 2 || (strcmp (argv[1], "-f") && strcmp (argv[1], "-c")))
101 * Get user entries for /etc/passwd and /etc/shadow
103 if (!(pwd = get_my_pwent ())) {
104 fprintf (stderr, _("%s: unknown user\n"), Prog);
107 spwd = getspnam (pwd->pw_name); /* !USE_PAM, No need for xgetspnam */
110 * If checking accounts, use agecheck() function.
112 if (strcmp (argv[1], "-c") == 0) {
115 * Print out number of days until expiration.
117 agecheck (pwd, spwd);
120 * Exit with status indicating state of account.
122 exit (isexpired (pwd, spwd));
126 * If forcing password change, use expire() function.
128 if (strcmp (argv[1], "-f") == 0) {
131 * Just call expire(). It will force the change or give a
132 * message indicating what to do. And it doesn't return at
133 * all unless the account is unexpired.