]> granicus.if.org Git - shadow/blob - src/expiry.c
* libmisc/obscure.c: Tag the `old' parameter of palindrome(),
[shadow] / src / expiry.c
1 /*
2  * Copyright 1994, Julianne Frances Haugh
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
16  *
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
27  * SUCH DAMAGE.
28  */
29
30 #include <config.h>
31
32 #ident "$Id$"
33
34 #include <pwd.h>
35 #include <signal.h>
36 #include <stdio.h>
37 #include <sys/types.h>
38 #include "defines.h"
39 #include "prototypes.h"
40 /* local function prototypes */
41 static RETSIGTYPE catch_signals (int);
42 static void usage (void);
43
44 /*
45  * catch_signals - signal catcher
46  */
47 static RETSIGTYPE catch_signals (unused int sig)
48 {
49         exit (10);
50 }
51
52 /*
53  * usage - print syntax message and exit
54  */
55 static void usage (void)
56 {
57         fprintf (stderr, _("Usage: expiry {-f|-c}\n"));
58         exit (10);
59 }
60
61 /* 
62  * expiry - check and enforce password expiration policy
63  *
64  *      expiry checks (-c) the current password expiration and forces (-f)
65  *      changes when required. It is callable as a normal user command.
66  */
67 int main (int argc, char **argv)
68 {
69         struct passwd *pwd;
70
71         struct spwd *spwd;
72         char *Prog = argv[0];
73
74         sanitize_env ();
75
76         /* 
77          * Start by disabling all of the keyboard signals.
78          */
79         signal (SIGHUP, catch_signals);
80         signal (SIGINT, catch_signals);
81         signal (SIGQUIT, catch_signals);
82 #ifdef  SIGTSTP
83         signal (SIGTSTP, catch_signals);
84 #endif
85
86         /*
87          * expiry takes one of two arguments. The default action is to give
88          * the usage message.
89          */
90         setlocale (LC_ALL, "");
91         bindtextdomain (PACKAGE, LOCALEDIR);
92         textdomain (PACKAGE);
93
94         if (argc != 2 || (strcmp (argv[1], "-f") && strcmp (argv[1], "-c")))
95                 usage ();
96
97         /*
98          * Get user entries for /etc/passwd and /etc/shadow
99          */
100         if (!(pwd = get_my_pwent ())) {
101                 fprintf (stderr, _("%s: unknown user\n"), Prog);
102                 exit (10);
103         }
104         spwd = getspnam (pwd->pw_name); /* !USE_PAM, No need for xgetspnam */
105
106         /*
107          * If checking accounts, use agecheck() function.
108          */
109         if (strcmp (argv[1], "-c") == 0) {
110
111                 /*
112                  * Print out number of days until expiration.
113                  */
114                 agecheck (pwd, spwd);
115
116                 /*
117                  * Exit with status indicating state of account.
118                  */
119                 exit (isexpired (pwd, spwd));
120         }
121
122         /*
123          * If forcing password change, use expire() function.
124          */
125         if (strcmp (argv[1], "-f") == 0) {
126
127                 /*
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.
131                  */
132                 expire (pwd, spwd);
133                 exit (0);
134         }
135
136         /*
137          * Can't get here ...
138          */
139         usage ();
140         exit (1);
141 }