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 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 * Copyright (c) 2016 by Delphix. All rights reserved.
31 #include <security/pam_appl.h>
32 #include <security/pam_modules.h>
35 static int parse_allow_name(char *, char *);
38 * pam_sm_acct_mgmt main account managment routine.
39 * XXX: The routine just prints out a warning message.
40 * It may need to force the user to change their
54 /*LINTED - set but not used. Would be used in a real module. */
56 /*LINTED - set but not used. Would be used in a real module. */
63 if (pam_get_item(pamh
, PAM_USER
, (void **)&user
) != PAM_SUCCESS
)
64 return (PAM_SERVICE_ERR
);
66 if (pam_get_item(pamh
, PAM_SERVICE
, (void **)&pg
) != PAM_SUCCESS
)
67 return (PAM_SERVICE_ERR
);
70 * kludge alert. su needs to be handled specially for allow policy.
71 * we want to use the policy of the current user not the "destination"
72 * user. This will enable us to prevent su to root but not to rlogin,
73 * telnet, rsh, ftp to root.
75 * description of problem: user name is the "destination" name. not
76 * the current name. The allow policy needs to be applied to the
77 * current name in the case of su. user is "root" in this case and
78 * we will be getting the root policy instead of the user policy.
80 if (strcmp(pg
, "su") == 0) {
86 return (PAM_SYSTEM_ERR
);
90 if (user
== 0 || *user
== '\0' || (strcmp(user
, "root") == 0))
93 for (i
= 0; i
< argc
; i
++) {
94 if (strcasecmp(argv
[i
], "debug") == 0)
96 else if (strcasecmp(argv
[i
], "nowarn") == 0) {
98 flags
= flags
| PAM_SILENT
;
99 } else if (strncmp(argv
[i
], "allow=", 6) == 0)
100 error
|= parse_allow_name(user
, (char *)(argv
[i
]+6));
102 syslog(LOG_DEBUG
, "illegal option %s", argv
[i
]);
104 return (error
?PAM_SUCCESS
:PAM_AUTH_ERR
);
107 static char *getname();
110 parse_allow_name(char *who
, char *cp
)
118 cp
= getname(cp
, name
);
119 /* catch things such as =, and ,, */
122 if (strcmp(who
, name
) == 0)
129 getname(char *cp
, char *name
)
131 /* force name to be initially null string */
139 if (*cp
== ',' || *cp
== '\0')
143 /* make name into string */
145 return ((*cp
== '\0')? (char *)0 : ++cp
);