01e68d5f0c352d56ff39f1505cc0e2442d4d5c79
[ddiss/samba.git] / nsswitch / pam_winbind.h
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)
5
6    (C) Shirish Kalele 2000
7 */
8
9 /*
10    Unix SMB/CIFS implementation.
11
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.
16
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.
21
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/>.
24 */
25
26 #include "../lib/replace/replace.h"
27 #include "system/syslog.h"
28 #include "system/time.h"
29 #include <talloc.h>
30 #include "libwbclient/wbclient.h"
31
32 #define MODULE_NAME "pam_winbind"
33 #define PAM_SM_AUTH
34 #define PAM_SM_ACCOUNT
35 #define PAM_SM_PASSWORD
36 #define PAM_SM_SESSION
37
38 #ifndef PAM_WINBIND_CONFIG_FILE
39 #define PAM_WINBIND_CONFIG_FILE "/etc/security/pam_winbind.conf"
40 #endif
41
42 #include <iniparser.h>
43
44 #ifdef HAVE_LIBINTL_H
45 #include <libintl.h>
46 #endif
47
48 #if defined(LINUX)
49
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
53 #endif
54
55 #else /* !LINUX */
56
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>
63 #endif
64
65 #ifndef PAM_AUTHTOK_RECOVER_ERR
66 #define PAM_AUTHTOK_RECOVER_ERR PAM_AUTHTOK_RECOVERY_ERR
67 #endif
68
69 #endif /* defined(SUNOS5) || defined(SUNOS4) || defined(HPUX) || defined(FREEBSD) || defined(AIX) */
70
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>
75 #endif
76
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>
81 #else
82 /* Define required macros from (Linux PAM 0.68) security/_pam_macros.h */
83 #define _pam_drop_reply(/* struct pam_response * */ reply, /* int */ replies) \
84 do {                                              \
85     int reply_i;                                  \
86                                                   \
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);            \
91         }                                         \
92     }                                             \
93     if (reply)                                    \
94         free(reply);                              \
95 } while (0)
96
97 #define _pam_overwrite(x)        \
98 do {                             \
99      register char *__xx__;      \
100      if ((__xx__=(x)))           \
101           while (*__xx__)        \
102                *__xx__++ = '\0'; \
103 } while (0)
104
105 /*
106  * Don't just free it, forget it too.
107  */
108
109 #define _pam_drop(X) SAFE_FREE(X)
110
111 #define  x_strdup(s)  ( (s) ? strdup(s):NULL )
112 #endif /* HAVE_SECURITY__PAM_MACROS_H */
113
114 #ifdef HAVE_SECURITY_PAM_EXT_H
115 #include <security/pam_ext.h>
116 #endif
117
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
133
134 #if defined(HAVE_GETTEXT) && !defined(__LCLINT__)
135 #define _(string) dgettext(MODULE_NAME, string)
136 #else
137 #define _(string) string
138 #endif
139
140 #define N_(string) string
141
142 /*
143  * here is the string to inform the user that the new passwords they
144  * typed were not the same.
145  */
146
147 #define MISTYPED_PASS _("Sorry, passwords do not match")
148
149 #define on(x, y) (x & y)
150 #define off(x, y) (!(x & y))
151
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"
159
160 #define SECONDS_PER_DAY 86400
161
162 #define DEFAULT_DAYS_TO_WARN_BEFORE_PWD_EXPIRES 14
163
164 #include "winbind_client.h"
165
166 #define PAM_WB_REMARK_DIRECT(c,x)\
167 {\
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);\
172         } else {\
173                 _make_remark(c, PAM_ERROR_MSG, x);\
174         };\
175 };
176
177 #define LOGON_KRB5_FAIL_CLOCK_SKEW      0x02000000
178
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)))
182
183 struct pwb_context {
184         pam_handle_t *pamh;
185         int flags;
186         int argc;
187         const char **argv;
188         dictionary *dict;
189         uint32_t ctrl;
190 };
191
192 #ifndef TALLOC_FREE
193 #define TALLOC_FREE(ctx) do { talloc_free(ctx); ctx=NULL; } while(0)
194 #endif
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)
197 #endif