4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
34 #include <security/pam_appl.h>
35 #include <security/pam_modules.h>
36 #include "../../libpam/pam_impl.h"
41 * Various useful files and string constants
43 #define DIAL_FILE "/etc/dialups"
44 #define DPASS_FILE "/etc/d_passwd"
45 #define SHELL "/usr/bin/sh"
46 #define SCPYN(a, b) (void) strncpy(a, b, sizeof (a))
49 * pam_sm_authenticate - This is the top level function in the
50 * module called by pam_auth_port in the framework
51 * Returns: PAM_AUTH_ERR on failure, 0 on success
55 pam_sm_authenticate(pam_handle_t
*pamh
, int flags
, int argc
, const char **argv
)
61 char *p1
= NULL
, *p2
= NULL
;
64 char pwd_buffer
[1024];
65 char *password
= NULL
;
71 for (i
= 0; i
< argc
; i
++) {
72 if (strcasecmp(argv
[i
], "debug") == 0)
75 syslog(LOG_DEBUG
, "illegal option %s", argv
[i
]);
78 if ((retcode
= pam_get_user(pamh
, &user
, NULL
))
80 (retcode
= pam_get_item(pamh
, PAM_TTY
, (void **)&ttyn
))
86 "Dialpass authenticate user = %s, ttyn = %s",
87 user
? user
: "NULL", ttyn
? ttyn
: "NULL");
90 if (ttyn
== NULL
|| *ttyn
== '\0') {
93 (void) pam_get_item(pamh
, PAM_SERVICE
, (void **)&service
);
94 syslog(LOG_ERR
, "pam_dial_auth: terminal-device not specified"
95 "by %s, returning %s.", service
,
96 pam_strerror(pamh
, PAM_SERVICE_ERR
));
97 return (PAM_SERVICE_ERR
);
99 getpwnam_r(user
, &pwd
, pwd_buffer
, sizeof (pwd_buffer
), &pwdp
);
101 return (PAM_USER_UNKNOWN
);
103 if ((fp
= fopen(DIAL_FILE
, "rF")) == NULL
)
106 while ((p1
= fgets(line
, sizeof (line
), fp
)) != NULL
) {
107 while (*p1
!= '\n' && *p1
!= ' ' && *p1
!= '\t')
110 if (strcmp(line
, ttyn
) == 0)
116 if ((fp
= fopen(DPASS_FILE
, "rF")) == NULL
) {
117 syslog(LOG_ERR
, "pam_dial_auth: %s without %s, returning %s.",
118 DIAL_FILE
, DPASS_FILE
,
119 pam_strerror(pamh
, PAM_SYSTEM_ERR
));
120 (void) memset(line
, 0, sizeof (line
));
121 return (PAM_SYSTEM_ERR
);
126 (void) memset(line
, 0, sizeof (line
));
132 while ((p1
= fgets(line
, sizeof (line
)-1, fp
)) != NULL
) {
133 while (*p1
&& *p1
!= ':')
137 while (*p1
&& *p1
!= ':')
140 if (pwd
.pw_shell
!= NULL
&& strcmp(pwd
.pw_shell
, line
) == 0)
143 if (strcmp(SHELL
, line
) == 0)
148 (void) memset(line
, 0, sizeof (line
));
155 res
= __pam_get_authtok(pamh
, PAM_PROMPT
, PAM_AUTHTOK
,
156 dgettext(TEXT_DOMAIN
, "Dialup Password: "), &password
);
158 if (res
!= PAM_SUCCESS
) {
162 if (strcmp(crypt(password
, p2
), p2
) != 0) {
163 (void) memset(password
, 0, strlen(password
));
165 return (PAM_AUTH_ERR
);
167 (void) memset(password
, 0, strlen(password
));
171 return (PAM_SUCCESS
);
175 * dummy pam_sm_setcred - does nothing
179 pam_sm_setcred(pam_handle_t
*pamh
, int flags
, int argc
, const char **argv
)