1 #ifndef __NSSWITCH_PAM_WINBIND_H__
2 #define __NSSWITCH_PAM_WINBIND_H__
3 /* pam_winbind header file
4 (Solaris needs some macros from Linux for common PAM code)
6 (C) Shirish Kalele 2000
10 Unix SMB/CIFS implementation.
12 This library is free software; you can redistribute it and/or
13 modify it under the terms of the GNU Lesser General Public
14 License as published by the Free Software Foundation; either
15 version 3 of the License, or (at your option) any later version.
17 This library is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 Library General Public License for more details.
22 You should have received a copy of the GNU Lesser General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "../lib/replace/replace.h"
27 #include "system/syslog.h"
28 #include "system/time.h"
30 #include "libwbclient/wbclient.h"
32 #define MODULE_NAME "pam_winbind"
34 #define PAM_SM_ACCOUNT
35 #define PAM_SM_PASSWORD
36 #define PAM_SM_SESSION
38 #ifndef PAM_WINBIND_CONFIG_FILE
39 #define PAM_WINBIND_CONFIG_FILE "/etc/security/pam_winbind.conf"
42 #include <iniparser.h>
50 /* newer versions of PAM have this in _pam_compat.h */
51 #ifndef PAM_AUTHTOK_RECOVERY_ERR
52 #define PAM_AUTHTOK_RECOVERY_ERR PAM_AUTHTOK_RECOVER_ERR
57 /* Solaris always uses dynamic pam modules */
58 #define PAM_EXTERN extern
59 #if defined(HAVE_SECURITY_PAM_APPL_H)
60 #include <security/pam_appl.h>
61 #elif defined(HAVE_PAM_PAM_APPL_H)
62 #include <pam/pam_appl.h>
65 #ifndef PAM_AUTHTOK_RECOVER_ERR
66 #define PAM_AUTHTOK_RECOVER_ERR PAM_AUTHTOK_RECOVERY_ERR
69 #endif /* defined(SUNOS5) || defined(SUNOS4) || defined(HPUX) || defined(FREEBSD) || defined(AIX) */
71 #if defined(HAVE_SECURITY_PAM_MODULES_H)
72 #include <security/pam_modules.h>
73 #elif defined(HAVE_PAM_PAM_MODULES_H)
74 #include <pam/pam_modules.h>
77 #if defined(HAVE_SECURITY__PAM_MACROS_H)
78 #include <security/_pam_macros.h>
79 #elif defined(HAVE_PAM__PAM_MACROS_H)
80 #include <pam/_pam_macros.h>
82 /* Define required macros from (Linux PAM 0.68) security/_pam_macros.h */
83 #define _pam_drop_reply(/* struct pam_response * */ reply, /* int */ replies) \
87 for (reply_i=0; reply_i<replies; ++reply_i) { \
88 if (reply[reply_i].resp) { \
89 _pam_overwrite(reply[reply_i].resp); \
90 free(reply[reply_i].resp); \
97 #define _pam_overwrite(x) \
99 register char *__xx__; \
106 * Don't just free it, forget it too.
109 #define _pam_drop(X) SAFE_FREE(X)
111 #define x_strdup(s) ( (s) ? strdup(s):NULL )
112 #endif /* HAVE_SECURITY__PAM_MACROS_H */
114 #ifdef HAVE_SECURITY_PAM_EXT_H
115 #include <security/pam_ext.h>
118 #define WINBIND_DEBUG_ARG 0x00000001
119 #define WINBIND_USE_AUTHTOK_ARG 0x00000002
120 #define WINBIND_UNKNOWN_OK_ARG 0x00000004
121 #define WINBIND_TRY_FIRST_PASS_ARG 0x00000008
122 #define WINBIND_USE_FIRST_PASS_ARG 0x00000010
123 #define WINBIND__OLD_PASSWORD 0x00000020
124 #define WINBIND_REQUIRED_MEMBERSHIP 0x00000040
125 #define WINBIND_KRB5_AUTH 0x00000080
126 #define WINBIND_KRB5_CCACHE_TYPE 0x00000100
127 #define WINBIND_CACHED_LOGIN 0x00000200
128 #define WINBIND_CONFIG_FILE 0x00000400
129 #define WINBIND_SILENT 0x00000800
130 #define WINBIND_DEBUG_STATE 0x00001000
131 #define WINBIND_WARN_PWD_EXPIRE 0x00002000
132 #define WINBIND_MKHOMEDIR 0x00004000
134 #if defined(HAVE_GETTEXT) && !defined(__LCLINT__)
135 #define _(string) dgettext(MODULE_NAME, string)
137 #define _(string) string
140 #define N_(string) string
143 * here is the string to inform the user that the new passwords they
144 * typed were not the same.
147 #define MISTYPED_PASS _("Sorry, passwords do not match")
149 #define on(x, y) (x & y)
150 #define off(x, y) (!(x & y))
152 #define PAM_WINBIND_NEW_AUTHTOK_REQD "PAM_WINBIND_NEW_AUTHTOK_REQD"
153 #define PAM_WINBIND_NEW_AUTHTOK_REQD_DURING_AUTH "PAM_WINBIND_NEW_AUTHTOK_REQD_DURING_AUTH"
154 #define PAM_WINBIND_HOMEDIR "PAM_WINBIND_HOMEDIR"
155 #define PAM_WINBIND_LOGONSCRIPT "PAM_WINBIND_LOGONSCRIPT"
156 #define PAM_WINBIND_LOGONSERVER "PAM_WINBIND_LOGONSERVER"
157 #define PAM_WINBIND_PROFILEPATH "PAM_WINBIND_PROFILEPATH"
158 #define PAM_WINBIND_PWD_LAST_SET "PAM_WINBIND_PWD_LAST_SET"
160 #define SECONDS_PER_DAY 86400
162 #define DEFAULT_DAYS_TO_WARN_BEFORE_PWD_EXPIRES 14
164 #include "winbind_client.h"
166 #define PAM_WB_REMARK_DIRECT(c,x)\
168 const char *error_string = NULL; \
169 error_string = _get_ntstatus_error_string(x);\
170 if (error_string != NULL) {\
171 _make_remark(c, PAM_ERROR_MSG, error_string);\
173 _make_remark(c, PAM_ERROR_MSG, x);\
177 #define LOGON_KRB5_FAIL_CLOCK_SKEW 0x02000000
179 #define PAM_WB_CACHED_LOGON(x) (x & WBC_AUTH_USER_INFO_CACHED_ACCOUNT)
180 #define PAM_WB_KRB5_CLOCK_SKEW(x) (x & LOGON_KRB5_FAIL_CLOCK_SKEW)
181 #define PAM_WB_GRACE_LOGON(x) ((WBC_AUTH_USER_INFO_CACHED_ACCOUNT|WBC_AUTH_USER_INFO_GRACE_LOGON) == ( x & (WBC_AUTH_USER_INFO_CACHED_ACCOUNT|WBC_AUTH_USER_INFO_GRACE_LOGON)))
193 #define TALLOC_FREE(ctx) do { talloc_free(ctx); ctx=NULL; } while(0)
195 #define TALLOC_ZERO_P(ctx, type) (type *)_talloc_zero(ctx, sizeof(type), #type)
196 #define TALLOC_P(ctx, type) (type *)talloc_named_const(ctx, sizeof(type), #type)