Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / pam / pam_modules / unix / unix_chauthtok.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: unix_chauthtok.c /main/5 1996/05/09 04:33:18 drk $ */
24 /*
25  * Copyright (c) 1992-1995, by Sun Microsystems, Inc.
26  * All rights reserved.
27  */
28
29 #ident  "@(#)unix_chauthtok.c 1.83      95/12/12 SMI"
30
31 #include "unix_headers.h"
32
33 /*
34  * pam_sm_chauthtok():
35  *      To change authentication token.
36  *
37  *      This function handles all requests from the "passwd" command
38  *      to change a user's password in all repositories specified
39  *      in nsswitch.conf.
40  */
41
42 int
43 pam_sm_chauthtok(
44         pam_handle_t            *pamh,
45         int                     flags,
46         int                     argc,
47         const char              **argv)
48 {
49         int i;
50         int debug = 0;                  /* debug option from pam.conf */
51         int authtok_aged = 0;           /* flag to check if password expired */
52         unix_authtok_data *status;      /* status in pam handle stating if */
53                                         /* password aged */
54
55         /*
56          * Only check for debug here - parse remaining options
57          * in __update_authtok();
58          */
59         for (i = 0; i < argc; i++) {
60                 if (strcmp(argv[i], "debug") == 0)
61                         debug = 1;
62         }
63
64         if (flags & PAM_PRELIM_CHECK) {
65                 /* do not do any prelim check at this time */
66                 if (debug)
67                         syslog(LOG_DEBUG,
68                         "unix pam_sm_chauthtok(): prelim check");
69                 return (PAM_SUCCESS);
70         }
71
72         /* make sure PAM framework is telling us to update passwords */
73         if (!(flags & PAM_UPDATE_AUTHTOK)) {
74                 syslog(LOG_ERR, "unix pam_sm_chauthtok: bad flags: %d", flags);
75                 return (PAM_SYSTEM_ERR);
76         }
77
78         if (flags & PAM_CHANGE_EXPIRED_AUTHTOK) {
79                 if (pam_get_data(pamh, UNIX_AUTHTOK_DATA, (void **)&status)
80                                                         == PAM_SUCCESS) {
81                         switch (status->age_status) {
82                         case PAM_NEW_AUTHTOK_REQD:
83                                 if (debug)
84                                     syslog(LOG_DEBUG,
85                                     "pam_sm_chauthtok: UNIX password aged");
86                                 authtok_aged = 1;
87                                 break;
88                         default:
89                                 /* UNIX authtok did not expire */
90                                 if (debug)
91                                     syslog(LOG_DEBUG,
92                                     "pam_sm_chauthtok: UNIX password young");
93                                 authtok_aged = 0;
94                                 break;
95                         }
96                 }
97                 if (!authtok_aged)
98                         return (PAM_IGNORE);
99         }
100
101         /*
102          *      This function calls __update_authtok() to change passwords.
103          *      By passing PAM_REP_DEFAULT, the repository will be determined
104          *      by looking in nsswitch.conf.
105          *
106          *      To obtain the domain name (passed as NULL), __update_authtok()
107          *      will call: nis_local_directory();
108          */
109         return (__update_authtok(pamh, flags, PAM_REP_DEFAULT, NULL,
110                         argc, argv));
111 }