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
33 RCSID (PKG_VER "$Id: expiry.c,v 1.12 2002/01/05 15:41:43 kloczek Exp $")
34 #include <sys/types.h>
37 #include "prototypes.h"
40 /* local function prototypes */
41 static RETSIGTYPE catch (int);
42 static void usage (void);
45 * catch - signal catcher
48 static RETSIGTYPE catch (int sig)
54 * usage - print syntax message and exit
57 static void usage (void)
59 fprintf (stderr, _("Usage: expiry {-f|-c}\n"));
64 * expiry - check and enforce password expiration policy
66 * expiry checks (-c) the current password expiraction and forces (-f)
67 * changes when required. It is callable as a normal user command.
70 int main (int argc, char **argv)
82 * Start by disabling all of the keyboard signals.
85 signal (SIGHUP, catch);
86 signal (SIGINT, catch);
87 signal (SIGQUIT, catch);
89 signal (SIGTSTP, catch);
93 * expiry takes one of two arguments. The default action is to give
97 setlocale (LC_ALL, "");
98 bindtextdomain (PACKAGE, LOCALEDIR);
102 || (strcmp (argv[1], "-f") && strcmp (argv[1], "-c")))
105 #if 0 /* could be setgid shadow with /etc/shadow mode 0640 */
107 * Make sure I am root. Can't open /etc/shadow without root
111 if (geteuid () != 0) {
113 _("%s: WARNING! Must be set-UID root!\n"),
120 * Get user entries for /etc/passwd and /etc/shadow
123 if (!(pwd = get_my_pwent ())) {
124 fprintf (stderr, _("%s: unknown user\n"), Prog);
128 spwd = getspnam (pwd->pw_name);
132 * If checking accounts, use agecheck() function.
135 if (strcmp (argv[1], "-c") == 0) {
138 * Print out number of days until expiration.
142 agecheck (pwd, spwd);
148 * Exit with status indicating state of account.
152 exit (isexpired (pwd, spwd));
154 exit (isexpired (pwd));
159 * If forcing password change, use expire() function.
162 if (strcmp (argv[1], "-f") == 0) {
165 * Just call expire(). It will force the change or give a
166 * message indicating what to do. And it doesn't return at
167 * all unless the account is unexpired.