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.8 1999/06/07 16:40:45 marekm Exp $")
35 #include <sys/types.h>
38 #include "prototypes.h"
43 #if defined(HAVE_USERSEC_H) || defined(SHADOWPWD)
48 int main P_((int, char **));
50 #if !defined(SHADOWPWD) && !defined(AGING) /*{*/
53 * Not much to do here ...
57 main(int argc, char **argv)
62 #else /*} AGING || SHADOWPWD {*/
64 /* local function prototypes */
65 static RETSIGTYPE catch P_((int));
66 static void usage P_((void));
69 * catch - signal catcher
79 * usage - print syntax message and exit
85 fprintf(stderr, _("Usage: expiry { -f | -c }\n"));
90 * expiry - check and enforce password expiration policy
92 * expiry checks (-c) the current password expiraction and
93 * forces (-f) changes when required. It is callable as a
94 * normal user command.
98 main(int argc, char **argv)
104 char *Prog = argv[0];
109 * Start by disabling all of the keyboard signals.
112 signal (SIGHUP, catch);
113 signal (SIGINT, catch);
114 signal (SIGQUIT, catch);
116 signal (SIGTSTP, catch);
120 * expiry takes one of two arguments. The default action
121 * is to give the usage message.
124 setlocale(LC_ALL, "");
125 bindtextdomain(PACKAGE, LOCALEDIR);
128 if (argc != 2 || (strcmp (argv[1], "-f") && strcmp (argv[1], "-c")))
131 #if 0 /* could be setgid shadow with /etc/shadow mode 0640 */
133 * Make sure I am root. Can't open /etc/shadow without root
137 if (geteuid () != 0) {
138 fprintf(stderr, _("%s: WARNING! Must be set-UID root!\n"),
145 * Get user entries for /etc/passwd and /etc/shadow
148 if (!(pwd = get_my_pwent())) {
149 fprintf(stderr, _("%s: unknown user\n"), Prog);
153 spwd = getspnam(pwd->pw_name);
157 * If checking accounts, use agecheck() function.
160 if (strcmp (argv[1], "-c") == 0) {
163 * Print out number of days until expiration.
167 agecheck (pwd, spwd);
173 * Exit with status indicating state of account --
177 exit (isexpired (pwd, spwd));
179 exit (isexpired (pwd));
184 * If forcing password change, use expire() function.
187 if (strcmp (argv[1], "-f") == 0) {
190 * Just call expire(). It will force the change
191 * or give a message indicating what to do. And
192 * it doesn't return at all unless the account